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);
},
plete:function(layers){
console.log(layers);
}
}).addTo(map);
I know each layer has an onAdd event but is there similar for a layerGroup?
Thanks
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);
},
plete:function(layers){
console.log(layers);
}
}).addTo(map);
I know each layer has an onAdd event but is there similar for a layerGroup?
Thanks
Share Improve this question asked Sep 19, 2013 at 14:54 sidonaldsonsidonaldson 25.3k10 gold badges60 silver badges64 bronze badges2 Answers
Reset to default 3I 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./questions/271919/how-to-cluster-external-geojson-using-leaflet-ajax-js