Question

I have a MarkerClusterer which i want to disable if the zoom level is below a threshold.

Example: The zoom level is 10, the clusters are visible. The threshold is 5, so if the user zooms out to see the world, all Markers should not be rendered. I don't want to clear the markers though, because they need to be shown if the user zooms in again.

Was it helpful?

Solution

If you don't want to clear the markers, you can instead use setMap() to set the map, to which the MarkerCluster is assigned, to a different map than the one the user is viewing.

setMap() takes null as a valid parameter.

Another option is to do some awful hack, like creating a second map that is not visible to the user and assigning the MarkerCluster to that map. It won't win any coding competitions, but it will work.

Then, when you get back to an appropriate zoom level, you can use setMap() again to put the MarkerCluster back on the map.

You can use the zoom_changed event to detect when the zoom on the map has changed and call setMap() appropriately.

Hopefully, this is all you need to get this done, but if not, post some of your code and maybe we can try to be more specific about exactly how to modify it to achieve this.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top