Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Leaflet map event equivalent to Google Map "idle" event

I can't seem to find the map event in Leaflet that equals to Google Map "idle" event.

The definition of Google Map event "idle" is "This event is fired when the map becomes idle after panning or zooming."

https://developers.google.com/maps/documentation/javascript/reference#Map

I tried Leaflet "viewreset", "load", "blur", "focused", "moveend" but they are really different from Google Map's "idle".

  • "viewreset": only executed when finished zoom in/out, not on initial and after panning.
  • "load": only when initialized.
  • "moveend": only when panning and zoomed, not initialized.

The best I can do is to use this

var foo = function(e){
   console.log('Hello');
}
map.on('load', foo);
map.on('moveend', foo);

Just want to find out if I'm reading the manual wrong. Or even if there is no event equivalent to Google Map's 'idle', is there a better way to implement it?

like image 389
Petra Barus Avatar asked May 13 '14 04:05

Petra Barus


1 Answers

There is no "idle" event in Leaflet library, though the description seems resemblant of "moveend" (there is nothing about map initialization).

As you yourself found out, you can use both "load" and "moveend" events. For catching those two, you don't need to call map.on twice: events can be joined in one string:

map.on('load moveend', function(e) { ... });
like image 135
Ilja Zverev Avatar answered Sep 23 '22 12:09

Ilja Zverev