Skip to content

getChildren method for getting children of a cluster on the next zoom - #31

Merged
mourner merged 1 commit into
masterfrom
children
Dec 16, 2016
Merged

mourner merged 1 commit into
masterfrom
children

Conversation

@mourner

@mourner mourner commented Dec 14, 2016 •

Copy link
Copy Markdown
Member

Fixes #13. This is a fast approach replacing changes proposed in #27 and #30. Also addresses mapbox/mapbox-gl-js#3318.

It pretty much doesn't affect performance while allowing to accurately fetch "children" clusters, either for spiderfying, generating a hull, precise "zoom to cluster" or any other features.

The way it works is storing the index of the "origin" point the cluster was created from as its id, and also storing parentId for each point/cluster that was clustered. Then you can fetch the "origin" point, do a radius query around it on the next zoom and filter out points that are not related to the cluster. This operation is almost instant since it's O(log N).

Let me know what you think!

cc @apkoponen @bewithjonam @stepankuzmin

@stepankuzmin

Copy link
Copy Markdown

Great! I think this is awesome!

@bewithjonam

Copy link
Copy Markdown

Looks fantastic. Thank you.

Right now,
throws error when you give a wrong clusterId (while retrieveing origin.x/origin.y)
throws error when you give a zoom level that doesn't have a tree. (not sure, should we use _limitZoom or throw a better error)

Fyi, trying to use this with a mapbox-gl-js fork

@mourner

mourner commented Dec 15, 2016

Copy link
Copy Markdown
Member Author

Thanks for the feedback! I should probably add some descriptive errors. Not sure about _limitZoom — if you change the input zoom, the cluster id relations will probably break.

@apkoponen

Copy link
Copy Markdown

Awesome, great work! Looking forward seeing this in Mapbox GL JS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants