Search code examples
javascriptleaflet

Leaflet : Firing an event when bounds change


I am using leaflet to develop a new application. You can have an idea of the app here.

I would like to fire an event whenever the bounds of the map change. I looked at the doc but couldn't find anything related to that.

I have found the getBounds() method, and the list of possible event methods, but nothing combining both.

The only other possibility I see to do that is to check for mouse drag and scroll events and check the bounds every time. But I was hoping there would be something better to do.

Would you have a better idea? Thanks!


Solution

  • Map bounds are updated each time the map is moved (either by pan or zoom). So you can use moveend event for your purpose

    map.on('moveend', function(e) {
       var bounds = map.getBounds();
    });