Leaflet markercluster zoom

16 views
Skip to first unread message

Tamara

unread,
Jul 19, 2022, 10:09:39 AMJul 19
to Leaflet
Hello, 
The map with multiple markers renders with all markers clustered. When I click on the cluster I get the desired look. How can I get the desired look on load without having to manually click on the cluster.
What I get: 
before.png
What I want:
after.png

Edwin Corrigan

unread,
Jul 19, 2022, 10:27:15 AMJul 19
to leafl...@googlegroups.com
Hi Tamara, 

So, when you click, the map zooms from where it is in your first image to where it is in your second image? This is happening because the zoomToBoundsOnClick option is turned on by default in the Marker clustering library (https://github.com/Leaflet/Leaflet.markercluster)

If so, you can replicate this without clicking by calculating the bounds from your data and then use the fitBounds function to set the map zoom and center to the desired location. Here's a link to the fitBounds function in the Leaflet docs:

Edwin


--

---
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/65620237-472e-43c1-95a4-1df740d1cf23n%40googlegroups.com.


Reply all
Reply to author
Forward
0 new messages