I am trying to call a function after a leaflet map has successfully loaded, working with leaflet 1.0.1. Regarding to the docs there is a map event named load
which states: Fired when the map is initialized (when its center and zoom are set for the first time). So this snipped should fire, if the map has loaded, but that never happens:
function onMapLoad() {
alert("Map successfully loaded")
};
mymap.on('load', onMapLoad);
There is no error or response, simple nothing. So why is the map-load event not working properly ?
Here goes a simple JS FIDDLE.
I suggest you to use the "whenReady" method available in Leaflet 1.0.1
var callBack = function () {
console.log("Map successfully loaded");
// do some stuff
};
mymap.whenReady(callBack);
Put the mymap.on('load', onMapLoad);
event handler before you actually load the map (with map.setView...
).
So your actual code should look like,
var mymap = L.map('mapid');
mymap.on('load', onMapLoad);
mymap.setView([51.505, -0.09], 13);
Source : Github Issue
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With