3

I'm loading a markerLayer using the Mapbox loadURL function. This works fine and I'm able to access marker properties, but what doesn't seem to work is changing the color of the markers.

var markerLayer = L.mapbox.markerLayer();
markerLayer.loadURL('geojson.php?lat='+lat+'&lng='+lng)
   .addTo(map);

markerLayer.on('click',function(e) {
    e.layer.unbindPopup();

    var feature = e.layer.feature;
    var info = '<h2>' + feature.properties.name + '</h2>' +
               '<p>' + feature.properties.description + '</p>';

    document.getElementById('info').innerHTML = info;

    feature.properties['old-color'] = feature.properties['marker-color'];
    feature.properties['marker-color'] = '#000';

});

Why does this not work and how would I go about changing the color of the marker using geoJson data loaded from a URL? The posted example depends on geoJson data that wasn't loaded using loadUrl. I suspect that has something to do with the reason why marker colors do not change.

4

1 回答 1

8

更改功能的属性不能自动更改图标 - 您需要调用setIcon,例如:

e.layer.setIcon(L.mapbox.marker.icon(feature.properties));

于 2013-10-10T22:08:18.983 回答