openPopup() breaks setView() with animation
See original GitHub issueScenario is the following very common setup: clicking in sidebar to center map on marker and open marker’s popup. What happens instead: map pans to wrong place and/or moves only till marker is in the map, but not in the center. It also happened that the popup got displayed in a totally different place than the marker on the screen.
Abstract code for trigger:
item_title_link.click(function() {
map.panTo(layer.getLatLng(), {animate: true});
layer.openPopup();
});
What happens:
- [bug]: When clicking for the first time, the map doesn’t center on the marker, but pans until it is in the corner/edge of map. In this case,
panBy
is called twice. - [good]: When clicking for the second time, the map centers on the marker. In this case,
panBy
is only called once.
The reason as far I was able to debug is the following. The following paths are all fighting to move the screen and end up in broken results many times.
panTo
->setView
->_tryAnimatedPan
->panBy
is always called. This is good and it is the required behaviour.Layer.openPopup
->Map.openPopup
->setLatLng
->update
->_adjustPan
->panBy
. This should not happen, as it destroys the real panBy movement. This path is not happening once the marker is visible on the screen (at the edges/corners), thus the second time the activation happens this path doesn’t run.
The only “fix” I found is to call setView with {reset: true}
to completely disable animation.
Leaflet v1.0.0-beta.1
OS X 10.9.5, latest Chrome
Issue Analytics
- State:
- Created 8 years ago
- Comments:9 (1 by maintainers)
Top Results From Across the Web
Documentation - a JavaScript library for interactive maps
Closes the popup previously opened with openPopup (or the given one). ... and aborts resetting the map view if map.locate was called with...
Read more >Animated setView() in Leaflet - Stack Overflow
Unfortunately, there is no way to change the duration of any setView that changes the current zoom level in Leaflet 0.7.7*.
Read more >leaflet - moveToLocation and open Marker-Popup automatically
openPopup(); but it can't read the setContent(). Cannot read property 'setContent' of undefined. I tried e.layer.bindPopup('test').openPopup() ...
Read more >Animated panning | React Leaflet
Animated panning. Usage. Click the map to move to the location. Live Editor ... setView(e.latlng, map.getZoom(), {. animate: animateRef.current || false,. } ...
Read more >animation-delay - CSS: Cascading Style Sheets | MDN
The animation-delay CSS property specifies the amount of time to wait from applying the animation to an element before beginning to perform ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Have you tried to set the Popup {autoPan: false}? I think I had a similar problem. Markers which were pretty much at the edge of the screen didn’t center when a popup was bound to them. Setting this option solved the problem.
Just to confirm: OK in beta 2.