我在为要素图层设置图标时遇到了一些问题.我不断得到layer.setIcon is not a function和类似的错误.如何更改此图层的图标样式?
var layer = L.mapbox.featureLayer()
.loadURL(attrs.geoJsonSource)
.addTo(map);
layer.on('ready', function() {
this.eachLayer(function(layer){
layer.setIcon(L.mapbox.marker.icon({
'marker-color': '#8834bb',
'marker-size': 'large',
'marker-symbol': 'restaurant'
}))
});
map.fitBounds(featureLayer.getBounds());
});
Run Code Online (Sandbox Code Playgroud)
我不知道为什么,但所提出的解决方案都不适合我。相反,我必须遍历该层的各个层。
layer.on('layeradd', function(e) {
var marker = e.layer, feature = marker.feature;
e.layer.getLayers().forEach(function(marker) {
marker.setIcon(L.mapbox.marker.icon({
'marker-color': '#8834bb',
'marker-size': 'large',
'marker-symbol': 'restaurant'
}));
})
});
Run Code Online (Sandbox Code Playgroud)