Leaflet Panning when Clicking on Markers

146 views
Skip to first unread message

Christoph Merten

unread,
Sep 4, 2023, 4:57:58 PM9/4/23
to Leaflet
Hi there,

when clicking on an indiividual marker icon which is half outside the map, the map will pan the icon into the visible area of the map:

Screenshot 2023-09-04 2300.png

how to disable this panning? Even a "move' event ist fired.

Regards
Chris

Edwin Corrigan

unread,
Sep 4, 2023, 6:55:50 PM9/4/23
to leafl...@googlegroups.com
Hi Christoph,

You can disable auto panning for the popups with the autoPan property for popups. It's set to true by default, but I've attached a html of how to set it to false, just open in your browser.

A sidenote to your question, but it might be useful. If you want to display the entire popup on click, but also turn off autopan, look into popup's offset function.

--

---
You received this message because you are subscribed to the Google Groups "Leaflet" group.
To unsubscribe from this group and stop receiving emails from it, send an email to leaflet-js+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/leaflet-js/3399b72a-9c75-4e80-81e3-8f783f6d29dcn%40googlegroups.com.
example_popup_autopan.html

Christoph Merten

unread,
Sep 4, 2023, 10:54:49 PM9/4/23
to leafl...@googlegroups.com
Thanks Edwin. But the behavior is Not the Problem with the popups. Its about the Marker Icons. Just try HTTPS://dev.gruppenunterkuenfte.de

And move the map that one Marker ist halt outside on the left and then click one the visible part. The the map pans the Icon ist full visible.

Regards
Chris

Message has been deleted
Message has been deleted

Edwin Corrigan

unread,
Sep 6, 2023, 6:42:48 AM9/6/23
to leafl...@googlegroups.com
Hi Christoph,
How about adding the autoPanOnFocus option to the Marker? Below is an example:

const marker = L.marker([51.5, -0.09], { autoPanOnFocus: false }).addTo(map).bindPopup(popup);

Edwin

Best Regards, 

Edwin


Edwin Corrigan 

 

Tel: (353) 87 7552 666

Christoph Merten

unread,
Sep 10, 2023, 5:26:59 AM9/10/23
to Leaflet
Hi Edwin,

thanks a lot. It works. I'm blind :-) I found it in the docs after you wrote.

Best regards
Chris

Reply all
Reply to author
Forward
0 new messages