Leaflet Version: 1.4.0. At the time of render, we are saving bounds by calling getBounds() on the layer. After the map is rendered, zoomend event is called and the bounds captured are different from previous getBounds(). This looks weird.

We want to persist the bounds and apply them after reopening. So we are capturing bounds on zoomend event. As these bounds are different, we see variation of the extents. Code sample:

polygonLayer.getBounds(); //This will give bounds of the layer
mymap.on('zoomend', function(event) {   
  var bounds = event.target.getBounds();

These two are different as shown below. If I need to save my extent and apply again what should be done.

enter image description here

2 Answers 2


I'm not sure I follow the logic you are trying to achieve by using zoomend event, but when you fit to bounds, the zoom doesn't necessarily change - it might be that only the bounds have changed.
Try checking the results from moveend event

mymap.on('moveend', function(event) {   
  var bounds = event.target.getBounds();

You might also want to prevent animation in the first panning:

map.fitBounds(polygonLayer.getBounds(), {
    animate: false,

These are two different sets of bounds:

  1. polygonLayer.getBounds(); call is giving you layer bounds for polygonLayer layer, regardless of the current view.
  2. event.target.getBounds(); call on zoomend event is giving you current map view bounds.
  • I know that we are getting different bounds. But when we send the map view bounds to fitbounds() methods, leaflet is still calling zoomend event which is giving different map view bounds. When we pass bounds to fitbounds() We should not call zoomend event. May 30, 2019 at 7:28
  • While rendering map for the first time, we call mymap.fitBounds(polygonLayer.getBounds()); This will call zoomend event. Where I am storing the targetBounds (view bounds). Next when we save the map, we save the zoomend bounds and on reopening the map we pass these bounds to mymap.fitBounds. But even in this case zoomend event is called. This is the issue which makes the current view smaller on rerendering. May 30, 2019 at 7:29
  • 1
    I'm not sure if I quite follow the logic of your app. Some source code would help.
    – TomazicM
    May 30, 2019 at 13:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.