javascript - Changing marker-color in mapbox when markerLayer loaded through loadURL function - Stack Overflow

I'm loading a markerLayer using the Mapbox loadURL function. This works fine and I'm able to

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.

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.

Share Improve this question asked Oct 7, 2013 at 10:28 sudocitysudocity 4878 silver badges14 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 8

Changing the properties of the feature can't automatically change the icon - you'll need to call setIcon, like:

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745474465a4629280.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信