Manuel Manuel - 3 years ago 143
Javascript Question

Leaflet map-event 'load' does not fire

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

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.

Answer Source

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 ='mapid');
mymap.on('load', onMapLoad);
mymap.setView([51.505, -0.09], 13);

Source : Github Issue

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download