gpt4 book ai didi

javascript - 通过 loadURL 函数加载 markerLayer 时更改 mapbox 中的标记颜色

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:25:14 25 4
gpt4 key购买 nike

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

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 数据更改标记的颜色? posted example取决于未使用 loadUrl 加载的 geoJson 数据。我怀疑这与标记颜色不变的原因有关。

最佳答案

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


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

关于javascript - 通过 loadURL 函数加载 markerLayer 时更改 mapbox 中的标记颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19222428/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com