Using getLeaves randomly throws 'No cluster with the specified id'.
See original GitHub issueI’m using supercluster in a website where- whenever a user moves the map (mapbox-gl), the frontend sends a request to the backend with map bounds and current zoom level.
I create a index using const index = Supercluster({options}).load(points). What I want to achieve is whenever the frontend requests for features on the backend, the backend should find clusters inside the given bounds (I’m already able to achieve this) and then get 1 feature from the cluster and send it back to the fronted.
So here’s the problem whenever I use index.getLeaves(cluster_id, 1) Supercluster randomly throws the Error No Cluster with the specified Id It works for some clusters but it doesn’t for others. This behavior is not expected. It will be great if you can help.
Here is a test case-
let index = new Supercluster({
radius: 20,
extent: 256,
maxZoom: 23,
minPoints: 2,
});
index.load(features); //load features
//This function runs whenever the frontend requests for features
getCluster(bounds, zoom){
let clusters = clusterIndex.getClusters(bounds, zoom); //Array of clusters
let features = [];
clusters.forEach((cluster) => {
if (!cluster) return;
let feature = clusterIndex.getLeaves(cluster.id, 1); //randomly throws No cluster with the specified Id,
//I also tried 'cluster.properties.cluster_id' it still didn't work
features.push(feature[0]);
});
return features;
}
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:5 (3 by maintainers)

Top Related StackOverflow Question
@sarveshkolte
getClustersreturns both clusters and individual unclustered points (that have no neighbors), have you tried checkingcluster.properties.cluster === truebefore fetching leaves for it?No worries, glad it worked!