question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unexpected behavior when repeatedly calling map.setZoom with the same zoom level

See original GitHub issue

Steps to reproduce Steps to reproduce the behavior:

  • go to this JS Fiddle with an example of the issue
  • hit the button three times
  • the first time, the map zooms to the specified zoom level
  • the second time, it zooms to the feature’s bounds
  • the third time, it zooms back out to the specified zoom level
  • the pattern continues each time the button is pressed.

Expected behavior I expect that calling map.setZoom repeatedly with the same argument will result in no change if the zoom is already at that value

Current behavior The map is zooming back and forth between the desired zoom level and the bounds of the feature

Environment

  • Leaflet version: 1.6.0
  • Browser (with version): Firefox 72.0.2
  • OS/Platform (with version): MacOS 10.14.6

Additional context I also noted this behavior if you replace lines 12 & 13 with this:

map.fitBounds(circle.getBounds());
map.fitBounds(circle.getBounds(), {maxZoom: 14});

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7

github_iconTop GitHub Comments

3reactions
johnd0ecommented, Mar 13, 2020

Workaround: use option {animate:false}.

        map.fitBounds(circle.getBounds(), {animate:false});
        map.setZoom(14, {animate:false});

Note that you need to disable animation for both command, otherwise you will get funny effect.

1reaction
johnd0ecommented, Mar 12, 2020

I still tend to think that this is leaflet flaw

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unexpected behavior when repeatedly calling map.setZoom ...
Here is a js fiddle which demonstrates the behavior I'm talking about. Hitting the "Zoom it" button 3-5 times shows first a zoom...
Read more >
map.bounds_changed event fires repeatedly when the map is ...
You can work around this behavior with a setTimeout() call to only act on the event once after it stops firing. This fires...
Read more >
Maps JavaScript API | Google Developers
When using v=beta , can be accessed by calling const {Map} = await google.map. ... The allowed values are restricted depending on the...
Read more >
question
Unexpected behavior when repeatedly calling map.setZoom with the same zoom level (Leaflet.js). Mar 11, 2020. 1. Writing set of functions that will use...
Read more >
Four causes for 'Zoom fatigue' and their solutions
Another source of stress is that, depending on your monitor size and whether you're using an external monitor, faces on videoconferencing calls ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found