Skip to content

add getLeaves method for retrieving leaf points (paginated) - #32

Merged
mourner merged 2 commits into
masterfrom
leaves-paginated
Jan 18, 2017
Merged

mourner merged 2 commits into
masterfrom
leaves-paginated

Conversation

@mourner

@mourner mourner commented Jan 18, 2017

Copy link
Copy Markdown
Member

Building on #31, this PR adds a method for a super-fast retrieval of leaf points in a cluster with pagination support. This is the second part of solving mapbox/mapbox-gl-js#3318, allowing us to create a UI where you can click on a cluster and get a paginated view of all points in it with ability to jump between pages.

Usage is as follows:

index.getLeaves(
    clusterId, // cluster_id property of the clicked cluster
    zoom,      // zoom of the clicked cluster
    limit,     // how many points to return; 10 by default
    offset);   // how many points to skip for pagination; 0 by default

Since this is basically depth-first spatial tree traversal, the call is very fast — e.g. getting 1000 points starting from the 200,000-th from a 400,000-point cluster takes just 2-3ms. Getting an array of all 400k points (limit = Infinity, offset = 0) takes 220ms, which is surprisingly fast too.

  • add some tests

cc @apkoponen @bewithjonam @stepankuzmin @popovae

@mourner
mourner merged commit c4b141d into master Jan 18, 2017
@mourner
mourner deleted the leaves-paginated branch January 18, 2017 16:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant