Callback when all layers are added to the leafletjs map

Situation: I am adding a new geoJson layer to my map and I want to animate all the markers as soon as they are added with a slight delay between them. The API seems to do everything, BUT offers a callback when the last token is added!

Code example

L.geoJson(data, { onEachFeature: function (feature, layer) { console.log(feature, layer); } }).addTo(map); 

I would like

  L.geoJson(data, { onEachFeature: function (feature, layer) { console.log(feature, layer); }, complete:function(layers){ console.log(layers); } }).addTo(map); 

I know that each layer has an onAdd event, but similar for layerGroup?

thanks

+8
javascript leaflet
source share
1 answer

I contacted the main contributors in the leaflets, and there is no need to have a callback for the standard geojson layer, you can just do it;

 var layer = L.geoJson(data, {}).addTo(map); animateMyIconsIn(layer.getLayers()); // your custom function 

However, you need a callback if you use 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 }); 
+3
source share

All Articles