supercluster: get all markers in a cluster

995 views Asked by At

I'm using superclsuter for clustering markers in react native map, what I want is to get all children from a cluster no matter what level of nesting a cluster may have.

to explain the situation a little better, a cluster can have markers and other clusters as children, I need to flatten the child clusters to get markers inside them.

cluster
  marker
  cluster(3 markers)

// this should return the 4 markers, the top-level marker, and markers within the child cluster
1

There are 1 answers

0
Jahir Tarafder On

I know it is late for an answer, but this solution is for google map using google-map-react package.

  1. First on initializing the map options, add maxZoom and minZoom. maxZoom must be equal to supercluster max-zoom

  2. On cluster rendering use this code:

    if(isCluster){

    if(zoom>=15){
        return (
            //Create MultiMarker similar to the marker below but different infowindow style to display list of places and display text
            <MultiMarker
                key={`cluster-${cluster.id}`}
                lat={latitude}
                lng={longitude}
                text={`${pointCount} Listing`}
                places={supercluster.getChildren(cluster.id)}
            >
            </MultiMarker>
        )
    }else{
        return ClusterMarker;
    }
    

    }

    return Normal or Custom marker;

For cluster reference: https://www.leighhalliday.com/google-maps-clustering