通过 loadURL 函数加载标记图层时更改地图框中的标记颜色

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

本文关键字:地图 颜色 函数 loadURL 加载 图层 通过      更新时间:2023-09-26

我正在使用Mapbox loadURL函数加载一个标记层。这工作正常,我能够访问标记属性,但似乎不起作用的是更改标记的颜色。

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';
});

为什么这不起作用,我将如何使用从 URL 加载的 geoJson 数据更改标记的颜色?发布的示例取决于未使用 loadURL 加载的 geoJson 数据。我怀疑这与标记颜色不变的原因有关。

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

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