Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete cluster without deleting markers? #900

Open
PauloAlves311 opened this issue Jul 23, 2024 · 0 comments
Open

Delete cluster without deleting markers? #900

PauloAlves311 opened this issue Jul 23, 2024 · 0 comments
Labels
triage me I really want to be triaged. type: question Request for information or clarification. Not an issue.

Comments

@PauloAlves311
Copy link

PauloAlves311 commented Jul 23, 2024

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]);
@PauloAlves311 PauloAlves311 added triage me I really want to be triaged. type: question Request for information or clarification. Not an issue. labels Jul 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage me I really want to be triaged. type: question Request for information or clarification. Not an issue.
Projects
None yet
Development

No branches or pull requests

1 participant