Donations encourage developers such as myself to provide support for and develop new versions of our code.
ClusterMarker: Reference
Reference
Constructor
var myCluster = new ClusterMarker(map, options );
map (GMap2) is a required argument. This must be a reference to the map which you want to add your Clustermarker to.
options is an optional argument, passed to the ClusterMarker constructor as an object literal. Properties that can be set using the options object literal are:
borderPaddng (integer) See borderPadding property documentation.
clusteringEnabled (boolean) See clusteringEnabled property documentation.
clusterMarkerClick (function) See clusterMarkerClick property documentation.
clusterMarkerIcon (GIcon) Pass a GIcon to the constructor to change the default appearance of the cluster marker(the green arrow marker).
clusterMarkerTitle (string) Customise the tooltip that appears when the mouse is over a cluster marker. See clusterMarkerTitle property documentation.
fitMapMaxZoom (integer) See fitMapMaxZoom property documentation.
fitMapToMarkers (boolean) Now removed from the script and replaced with a new method fitMapToMarkers() that performs the same task. See fitMapToMarkers method documentation.
intersectPadding (integer) See intersectPadding property documentation.
markers (array of markers) This is the collection of markers that ClusterMarker will manage.
Methods
addMarkers(array of markers) adds the array of markers to ClusterMarker to manage. If some markers have already been added to your ClusterMarker then the new markers will be added to the existing markers.
myCluster.addMarkers(markers);
fitMapToMarkers() zooms and moves the map so that all markers (if not clustered or hidden) would fit the map view.
myCluster.fitMapToMarkers();
removeMarkers() simply removes all managed markers from ClusterMarker. After calling removeMarkers() you can then use the addMarkers() method to manage another (new) collection of markers.
myCluster.removeMarkers();
refresh(boolean) causes ClusterMarker to re-calculate all markers' visibilities and update the map. You can optionally pass a boolean value such as refresh(true); to force ClusterMarker to perform a complete update rather than it's default optimalised update. The default update is used when you call either refresh() or refresh(false) and is optimalised for speed - if you find clusters not being updated then use the refresh(true); option.
myCluster.refresh();
triggerClick(integer) triggers a click event on the marker identified in the array of markers by the index passed to triggerClick. The map will move and/or zoom in if necessary to uncluster that marker. Currently this method can be slow if the map has to zoom many levels to uncluster the chosen marker - i hope to improve it's performance with a future update.
myCluster.triggerClick(8);
Properties
borderPadding (integer) specifies, in pixels, the extra padding outside the map's current viewport monitored by ClusterMarker. Markers that fall within this padding are added to the map, even if they are not fully visible. Copied from Google Maps API Reference for the API GMarkerManager as this property is identical to the GMarkerManager option of the same name. This property is 256 pixels by default.
myCluster.borderPadding=512;
clusteringEnabled (boolean) accepts a boolean true or false value and enables or disables clustering. After changing this property you will likely want to call the refresh() method to see the change in effect. This property is enabled (true) by default.
myCluster.clusteringEnabled=true;
clusterMarkerClick A custom function that will be executed when a cluster marker is clicked instead of the default built in function. The custom function will be passed a single argument - an object literal with two properties:
clusterMarker A reference to the cluster marker that has been clicked.
clusteredMarkers An array of references to all the markers contained in the cluster.
clusterMarkerTitle specifies a string to display as the tooltip that appears when the mouse hovers over a cluster marker. You can use the token %count to represent the number of markers in a cluster. The default cluster marker title is equivalent to passing a string "Click to zoom in and see %count markers".
myCluster.clusterMarkerTitle='This is a cluster of %count locations';
fitMapMaxZoom (integer) specifies the maximum zoom level to use if fitMapToMarkers is executed. By default, ClusterMarker will zoom in to a level at which all markers and cluster markers are visible on the map. If this default fitMapToMarkers action zooms your map in too much then specify a fitMapMaxZoom that you find more suitable. The default value of fitMapMaxZoom is the maximum zoom level for the current map type.
myCluster.fitMapMaxZoom=12;
intersectPadding (integer) specifies a number of pixels (negative or positive) that surround each marker's icon to determine if it intersects with any nearby markers. This property is zero pixels by default.