Situation: I am adding a new geoJson layer to my map and I want to animate all the markers in once they have been added with a slight delay between each one. The API appears to do everything BUT offer a callback for when the last marker is added!
Sample code
L.geoJson(data, {
onEachFeature: function (feature, layer) {
console.log(feature, layer);
}
}).addTo(map);
what I would like is
L.geoJson(data, {
onEachFeature: function (feature, layer) {
console.log(feature, layer);
},
complete:function(layers){
console.log(layers);
}
}).addTo(map);
I know each layer has an onAdd event but is there similar for a layerGroup?
Thanks
I have got in contact with the major contributors of leafletjs and there is no need to have a callback for a standard geojson layer, you can just do this;
var layer = L.geoJson(data, {}).addTo(map);
animateMyIconsIn(layer.getLayers()); // your custom function
However you do need a callback if you are using the AJAX plugin;
//first create the layer
var layer = L.geoJson.AJAX(url, {});
//then add a listener
layer.on('dataLoadComplete',function(e){
//finally add the layer
layer.addTo(map);
animateMyIconsIn(layer.getLayers()); // your custom function
});
updated syntax is currently "data: loaded" as found from this post;
https://gis.stackexchange.com/questions/271919/how-to-cluster-external-geojson-using-leaflet-ajax-js
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.