MarkerClusterer component groups nearby markers into clusters to improve map performance and readability when displaying many markers.
Import
Usage
Props
A render function that receives the clusterer instance and returns the markers to be clustered.
Options to configure the marker clusterer.
Clustering Options
Whether the center of each cluster should be the average position of all markers in the cluster.
The grid size of a cluster in pixels. Default is 60.
The maximum zoom level at which clustering is enabled. When the map zoom exceeds this level, all markers are displayed individually.
The minimum number of markers needed to form a cluster. Default is 2.
Whether to zoom the map when a cluster is clicked. Default is true.
Appearance Options
An array of styles to apply to cluster icons. Each style defines the appearance for clusters of different sizes.
The base path to the cluster icon images.
The extension for cluster icon image files. Default is ‘png’.
An array of sizes for cluster icons.
Whether to use retina-ready cluster icons.
The CSS class to apply to cluster icons.
The tooltip text to display on cluster icons.
Performance Options
The batch size for processing markers in Internet Explorer. Helps improve performance in IE.
Whether to ignore hidden markers when clustering.
A function that determines which cluster style to use based on the markers in the cluster.
Event Handlers
Callback fired when a cluster is clicked.
Callback fired when the clustering algorithm starts.
Callback fired when the clustering algorithm finishes.
Callback fired when the mouse enters a cluster.
Callback fired when the mouse leaves a cluster.
Callback fired when the marker clusterer instance is loaded.
Callback fired when the marker clusterer is unmounted.
Types
ClusterIconStyle
Defines the visual style of a cluster icon.TCalculator
A function that calculates which cluster style to use.Example with Custom Styles
Notes
- The
MarkerClusterercomponent uses the@react-google-maps/marker-clustererpackage internally. - Markers must be passed the
clustererprop to be included in clustering. - Custom cluster icons should be optimized for web use to ensure good performance.
- The clustering algorithm runs automatically when markers are added, removed, or when the map viewport changes.