React-leaflet: auto-pan is re-triggered for an open popup when markers are added or removed on the map

Created on 2 Jun 2017  路  5Comments  路  Source: PaulLeCam/react-leaflet

Expected behavior

When a marker popup is opened, the auto-pan should be triggered. Afterwards, auto-pan should NOT be triggered and the user should be able to pan away from the popup (provided keepInView=false), even if updates are made to the map while the popup is open.

Actual behavior

While a marker popup is opened, auto-pan will be triggered each time a different marker is added or removed on the map.

Steps to reproduce

https://www.webpackbin.com/bins/-Kle4Bvy078Jnxxr1QhZ

  1. click the marker in the center of the map to open the popup
  2. pan the map such that the popup is off the screen
  3. wait for the second marker to be added/removed

Most helpful comment

@mjclawar That makes sense, it looks like this is an issue with leaflet itself: https://github.com/Leaflet/Leaflet/issues/2937. My mistake.

I'm opening an issue with leaflet since I believe this is undesired behavior (the popup should auto-pan when opened, but adding or removing sibling markers shouldn't re-trigger a popup to pan into view when the user isn't interacting with it at all).

All 5 comments

Hi,
Please only use GitHub issues to report possible bugs in the library.
You can use the react-leaflet tag in StackOverflow for general questions about it.

@PaulLeCam I'm not sure how this isn't a bug in the library - leaflet itself doesn't exhibit this behavior, I've included reproduction steps, and it seems like a pretty clear mechanic that one of the methods that <Popup /> or <Marker /> is calling in componentDidUpdate is causing Leaflet to re-do the map layout stuff when it shouldn't.

I can investigate this myself if you don't have time, but I'm not sure why you closed the issue without explaining why this isn't a bug in react-leaflet.

@PaulLeCam I have confirmed that vanilla Leaflet dos not exhibit this behavior, meaning this is a possible bug in the library. I'd appreciate it if you could re-open this issue.

@qrohlf Looks like the actual argument that prevents it from panning for your example is autoPan. This defaults to true.

keepInView just forces the popup to stay in the map view.

If you add autoPan={false} to the first Popup component in your example, you'll get the intended behavior.
If you set keepInView={true} with no autoPan argument in the first Popup component in your example, you won't be able to move the map.

@mjclawar That makes sense, it looks like this is an issue with leaflet itself: https://github.com/Leaflet/Leaflet/issues/2937. My mistake.

I'm opening an issue with leaflet since I believe this is undesired behavior (the popup should auto-pan when opened, but adding or removing sibling markers shouldn't re-trigger a popup to pan into view when the user isn't interacting with it at all).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

samankhademi picture samankhademi  路  3Comments

rolfdalhaug picture rolfdalhaug  路  3Comments

diligiant picture diligiant  路  3Comments

robinmetral picture robinmetral  路  4Comments

benzen picture benzen  路  4Comments