Skip to content

Commit

Permalink
add a test for generateId option
Browse files Browse the repository at this point in the history
  • Loading branch information
mourner committed Nov 5, 2019
1 parent 05439aa commit c85a890
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ Returns the zoom on which the cluster expands into several children (useful for
| extent | 512 | (Tiles) Tile extent. Radius is calculated relative to this value. |
| nodeSize | 64 | Size of the KD-tree leaf node. Affects performance. |
| log | false | Whether timing info should be logged. |
| generateId | false | Whether to generate unique numeric ids for input features. |
| generateId | false | Whether to generate ids for input features in vector tiles. |

### Property map/reduce options

Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const defaultOptions = {
nodeSize: 64, // size of the KD-tree leaf node, affects performance
log: false, // whether to log timing info

// whether to generate numeric ids for input features
// whether to generate numeric ids for input features (in vector tiles)
generateId: false,

// a reduce function for calculating custom cluster properties
Expand Down
7 changes: 7 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ test('returns leaves of a cluster', (t) => {
t.end();
});

test('generates unique ids with generateId option', (t) => {
const index = new Supercluster({generateId: true}).load(places.features);
const ids = index.getTile(0, 0, 0).features.filter(f => !f.tags.cluster).map(f => f.id);
t.same(ids, [12, 20, 21, 22, 24, 28, 30, 62, 81, 118, 119, 125, 81, 118]);
t.end();
});

test('getLeaves handles null-property features', (t) => {
const index = new Supercluster().load(places.features.concat([{
type: 'Feature',
Expand Down

0 comments on commit c85a890

Please sign in to comment.