JiriHoffmann / react-native-clusterer

React Native clustering library using C++ Supercluster implementation
MIT License
159 stars 20 forks source link

Clusterer: React Native component getLeaves #29

Closed BinLei001 closed 8 months ago

BinLei001 commented 1 year ago

I use Clusterer as React componet. When the point is clicked, if it is a cluster, I need to get all leaves. But Clusterer is a FunctionComponent I tried to use ref, failed. So how do I get superclusterer, and then call its method to getLeaves?

 <Clusterer
      // ref={ref => {this.clusterer = ref}}  can't use ref here
      data={ clusterCollection}
      region={region}
      options={{radius: 18,minZoom:clusterMinZoom}}
      mapDimensions={MAP_DIMENSIONS}
      renderItem={(item) => {
        return (
        <Point
            key={
            item.properties?.cluster_id ?? `point-${item.properties?.id}`
            }
            item={item}
            onPress={(item) => {

            }}
        />
        )
    }}
  />
FazilMuhammed commented 9 months ago

@BinLei001 did you got the solution.same issue also I have when a cluster click need get details how its possible ?

JiriHoffmann commented 8 months ago

The Clusterer component is just a simple wrapper and doesn't implement a ref. You can either use the getExpansionRegion() property (before v2.0.0 it was getClusterExpansionRegion()) that is provided for all clusters features in both Clusterer and useClusterer, or implement it yourself with the Supercluster class.