1
G'day!
我想爲我的OpenLayers地圖上的每個標記添加一個獨特的(css-)類,但我不知道該如何!我嘗試了幾乎所有的東西,並在forums of OpenStreetMap上發佈了這個問題(因爲那裏的人對OpenLayers非常熟悉)。
這是我寫的添加標記功能:OpenLayers:添加(css-)類到標記?
function ownMarker(lon,lat,icon,markerid) { var size = new OpenLayers.Size(38,58); var offset = new OpenLayers.Pixel(-(size.w/2), -size.h); var element = new OpenLayers.Element.addClass('div', 'test'); var icon = new OpenLayers.Icon('images/marker/'+ icon +'.png', size, offset); var marker = new OpenLayers.Marker((new OpenLayers.LonLat(lon, lat).transform(proj4326, projmerc)),icon) marker.id = markerid; marker.events.register("mousedown", marker, function() { if(this.id != 'home') { currentID = this.id; $('.activeResult').removeClass('activeResult'); $('#results a[href$=' + this.id + ']').addClass("activeResult"); showContent($(".nav a:first-child").attr("href")); $(".nav a:first-child").addClass("activeContent") if(contentOpen == false){ $("#container").show(); $(".frame").animate({left: 0}); contentOpen = true; } tempLatitude = $('#results a[href$=' + this.id + ']').attr("lat"); tempLongitude = $('#results a[href$=' + this.id + ']').attr("lon"); targetLatitude = $('#results a[href$=' + this.id + ']').attr("lat"); targetLongitude = $('#results a[href$=' + this.id + ']').attr("lon"); ownPanTo(tempLongitude, tempLatitude); console.log(this.id); } }); markers.addMarker(marker); }
正如你可以在第5行看到的,我已經嘗試過的類添加到標記 - 沒有成功!
請幫幫我! :)
乾杯!