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.

openPopup() breaks setView() with animation

See original GitHub issue

Scenario 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:

  1. [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.
  2. [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.

  1. panTo -> setView -> _tryAnimatedPan -> panBy is always called. This is good and it is the required behaviour.
  2. 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:closed
  • Created 8 years ago
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

6reactions
clemenslermencommented, Aug 14, 2015

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.

0reactions
hyperknotcommented, Oct 15, 2015

Just to confirm: OK in beta 2.

Read more comments on GitHub >

github_iconTop 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 >

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