markerClusterer on click zoom

AlexBrand picture AlexBrand · Apr 19, 2011 · Viewed 39.7k times · Source

I just added a MarkerClusterer to my google map. It works perfectly fine.

I am just wondering if there is any way of adjusting the zoom-in behaviour when the cluster is clicked. I would like to change the zoom level if possible.

Is there any way of achieving this?

Thanks

Answer

Jack picture Jack · Sep 22, 2011

There has been an update to the MarkerClusterer source code, allowing much easier access to the click event:

google.maps.event.addListener(markerCluster, 'clusterclick', function(cluster) {
    // your code here
});

where 'markerCluster' ist the MarkerCluster object. Inside the function you may also access

cluster.getCenter();
cluster.getMarkers();
cluster.getSize();

I use this to switch to a different map type, as I use a custom tile set for easier overview on lower zoom levels:

map.setCenter(cluster.getCenter()); // zoom to the cluster center
map.setMapTypeId(google.maps.MapTypeId.ROADMAP); // switch map type
map.setOptions(myMapOptions); // apply some other map options (optional)

Regards Jack