Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@googlemaps/markerclusterer: How to set maxZoom?

I'm trying to figure out how to set the maxZoom attribute.

I found the list of acceptable arguments:

new MarkerClusterer({ map, markers, algorithm, renderer, onClusterClick })

So, I don't want to implement my own algorithm. The default one I guess pretty cool.

I found the maxZoom property in the documentation. But cannot understand how to pass it to the MarkerClusterer object.

I saw this question, but looks like the MarkerClusterer implementation have changed and the answer is outdated. The MarkerClusterer object accepts only one argument with described fields above for now.

I'll be very grateful for any help.

like image 561
Alexey Zalyotov Avatar asked Sep 05 '25 03:09

Alexey Zalyotov


2 Answers

Thanks to @mrupsidown for help! The correct way to set custom maxZoom is to change the algorithm:

const algorithm = new SuperClusterAlgorithm({ maxZoom: 12 })
new MarkerClusterer({map, markers, algorithm, renderer, onClusterClick});
like image 101
Alexey Zalyotov Avatar answered Sep 07 '25 20:09

Alexey Zalyotov


I was stuck on this as well and found an easier solution. You just need to pass an object algorithmOptions.

new MarkerClusterer({map, markers, algorithmOptions: { maxZoom: 10 }});

I also didn't understand the docs properly but found it by looking into the source code: https://github.com/googlemaps/js-markerclusterer/blob/e3ea80c1172eedc0f9784d832f419153a49825ce/src/markerclusterer.ts#L84C8-L84C8

like image 36
Jay Avatar answered Sep 07 '25 20:09

Jay