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:
panBy is called twice.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
Swapping the panTo and openPopup lines fixes the marker's position on the map but breakes the popup's position, which is now usually not visible (depending on the distance panned).
Related to: https://github.com/Leaflet/Leaflet/issues/3745
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.
@clemenslermen brilliant, that's a nice workaround.
@clemenslermen thanks
it works for me.
@hyperknot do you still have the issue with latest master? If yes, can you set up a test case with http://playground-leaflet.rhcloud.com/ to reproduce it? Thanks :)
I'll have a look at reproducing it with master today.
Reproduced, still not fixed in master:
http://playground-leaflet.rhcloud.com/rur/3/edit?html,js,output
On the other hand, popup.openOn(map) got fixed in master (might be unrelated):
http://playground-leaflet.rhcloud.com/qor/1/edit?html,js,output
Just to confirm: OK in beta 2.
Most helpful comment
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.