mapbox / supercluster

A very fast geospatial point clustering library for browsers and Node.
ISC License
2.1k stars 298 forks source link

getLeaves returns 'No cluster with the specified id' #72

Closed KentDi808 closed 6 years ago

KentDi808 commented 6 years ago

I am using react-mapbox-gl@3.4.1 and supercluster@3.0.2 to get the list of features in a clicked cluster.

I saw that in V3.0.0 of supercluster the zoom factor is encoded into the cluster_id.

I am using a GeoJSONLayer to do the clustering (which may not be the right way to do it for supercluster) and the correct features are not returned OnClick.

Clicking some clusters throws a run-time error:

'No cluster with the specified id'.

Any idea why no features or the wrong features are being returned?

WebpackBin Showing a working example of the issue.

Any help would be appreciated.

KentDi808 commented 6 years ago

I have come up with a solution that gets me the data that I need.

Modifying the onClick to encode the cluster_id gets all of the items in the cluster.

const cluster_id = (id << 5) + (zoom + 1);

Thanks in advance.

mourner commented 6 years ago

The Webpack bin isn't loading for me for some reason... I'd guess that you're experiencing this issue because GL JS still uses Supercluster 2.3.0, which doesn't encode zoom into ids. We should upgrade there. Let's close here since it's not directly a supercluster issue.

KentDi808 commented 6 years ago

I'm okay with closing it. For some reason if you do a hard refresh the WebpackBin it will render correctly. Also, thanks for the great work you are doing.

PetengDedet commented 4 years ago

Just get same issue. After 3 hours of tracing the code, figured out that some of the cluster properties has an empty latitude or longitude. 😅 Filter the data before assign it to the points array. Solved.

Posted here to remind myself or others in the future for easy googling.

nhk-nguyen commented 3 years ago

Just get same issue. After 3 hours of tracing the code, figured out that some of the cluster properties has an empty latitude or longitude. 😅 Filter the data before assign it to the points array. Solved.

Posted here to remind myself or others in the future for easy googling.

You're right. Got the same issue and thanks to your comment!