MarkerClusterer is an awesome marker clustering utility for the Google Maps API. Currently when you click on a cluster, the map is re-centered and zooms in one level. This is sometimes a problem if your markers are very close together and the map is zoomed very far out. It take a few clicks before the markers become unclustered.
This snippet modifies the clusterclick behavior, so that clicking on a cluster zooms in more intelligently. Instead of simply zooming in one level, the bounds of the map are redefined based on the lat/long of the markers that a cluster contains.
Make sure you are using the dev branch of MarkerClusterer, earlier versions do not allow you to override the default clusterclick behavior.
Be sure to set zoomOnClick: false.
Also, this script make's use of jQuery's $.each() function. If you aren't using jQuery, you should find a different way to iterate through the loop.
GEvent.addListener(markerCluster, "clusterclick", function (cluster) { var markers = cluster.getMarkers(); var bounds = new GLatLngBounds(); $.each(markers, function(i, marker){ bounds.extend(marker.marker.getLatLng()); }); map.setCenter(bounds.getCenter(), map.getBoundsZoomLevel(bounds)); });
You need to login to post a comment.
