I use @googlemaps/markerclusterer to cluster markers on Google map, which integrated in a Reactjs app.
In a hook I iterate through addresses, create markers and markersClusterer:
useEffect(() => {
const markers = addresses.map((address) => {
new window.google.maps.Marker({
position: {
lat: address.attributes.lat,
lng: address.attributes.lng,
},
map: map,
});
});
new MarkerClusterer({ map, markers });
}, [addresses, map, mapParams]);
In the mapParams
I store map bounds - this dependecy help to rerender markers if bounds changed. When I use zoom on the map I would see proper clustering depends on the zoom level. Instead of that I see clusters for different zoom levels.