我正在使用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';
});
Run Code Online (Sandbox Code Playgroud)
为什么这不起作用,我将如何使用从URL加载的geoJson数据更改标记的颜色?该贴例子依赖于没有使用使用loadURL加载GeoJSON的数据.我怀疑这与标记颜色不变的原因有关.
更改功能的属性不能自动更改图标 - 您需要调用setIcon,如:
e.layer.setIcon(L.mapbox.marker.icon(feature.properties));
| 归档时间: |
|
| 查看次数: |
2305 次 |
| 最近记录: |