googlemaps / googlemaps/js-markerclusterer
Delete cluster without deleting markers?
- Dominant language
- TypeScript
- Stars
- 293
- Forks
- 104
- Avg merge
- 3m
- Merged PRs (30d)
- 18
Description
I have maxZoom in my map, which means that if the user is at this level, some clusters will still show, and the user can't see the markers inside them. So I want to delete/hide the cluster, but still keep its markers.
But the cluster.delete() will delete the cluster AND the markers. So is there any workaround to this?
```
clusterer.current = new MarkerClusterer({
map,
onClusterClick: (e, cluster, map) => {
cluster.delete();
// defaultOnClusterClickHandler(e, cluster, map);
},
```
Edit: I just realized that the cluster.delete() does work as intended. The issue is that the state is not being refreshed. So I guess I need to pass something to the useEffect() which will re-add the markers, but not exactly sure what:
```
//Create Clusters
useEffect(() => {
if (!map) return;
if (clusterer.current) {
clusterer.current.clearMarkers();
} else {
clusterer.current = new MarkerClusterer({
map,
onClusterClick: (e, cluster, map) => {
cluster.delete();
// defaultOnClusterClickHandler(e, cluster, map);
},
}
}, [map, markers]);
//Add markers to cluster
useEffect(() => {
clusterer.current?.addMarkers(Object.values(markers));
}, [markers]);
```
Contributor guide
Assessment
This issue has not been assessed yet.