Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import Supercluster from 'mutable-supercluster';

#### `load(points)`

Loads an array of [GeoJSON Feature](https://tools.ietf.org/html/rfc7946#section-3.2) objects. Each feature's `geometry` must be a [GeoJSON Point](https://tools.ietf.org/html/rfc7946#section-3.1.2). Once loaded, index is immutable.
Loads an array of [GeoJSON Feature](https://tools.ietf.org/html/rfc7946#section-3.2) objects. Each feature's `geometry` must be a [GeoJSON Point](https://tools.ietf.org/html/rfc7946#section-3.1.2). Loading the points is destructive, so the provided list will be cleared.

#### `getClusters(bbox, zoom)`

Expand Down
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export default class Supercluster {
if (log) console.time(timerId);

this.points = structuredClone(points);
points.length = 0;

// generate a cluster object for each point and index input points into a R-tree
const currentClusterData = [];
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mutable-supercluster",
"version": "1.0.3",
"version": "1.0.4",
"description": "A library for fast and mutable geospatial point clustering.",
"main": "dist/mutable-supercluster.js",
"type": "module",
Expand Down
26 changes: 13 additions & 13 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,27 @@ const placesTileMin5 = JSON.parse(readFileSync(new URL('./fixtures/places-z0-0-0
const sortedTileMin5Features = placesTileMin5.features.sort(compareFn);

test('generates clusters properly', () => {
const index = new Supercluster({getId}).load(places.features);
const index = new Supercluster({getId}).load(structuredClone(places.features));
const tile = index.getTile(0, 0, 0);
tile.features.sort(compareFn);
assert.deepEqual(tile.features, sortedTileFeatures);
});

test('supports minPoints option', () => {
const index = new Supercluster({minPoints: 5, getId}).load(places.features);
const index = new Supercluster({minPoints: 5, getId}).load(structuredClone(places.features));
const tile = index.getTile(0, 0, 0);
tile.features.sort(compareFn);
assert.deepEqual(tile.features, sortedTileMin5Features);
});

test('returns children of a cluster', () => {
const index = new Supercluster({getId}).load(places.features);
const index = new Supercluster({getId}).load(structuredClone(places.features));
const childCounts = index.getChildren(164).map(p => p.properties.point_count || 1);
assert.deepEqual(childCounts, [1, 7, 2, 6]);
});

test('returns leaves of a cluster', () => {
const index = new Supercluster({getId}).load(places.features);
const index = new Supercluster({getId}).load(structuredClone(places.features));
const leafNames = index.getLeaves(164, 10, 5).map(p => p.properties.name);
assert.deepEqual(leafNames, [
'I. de Cozumel',
Expand All @@ -56,13 +56,13 @@ test('returns leaves of a cluster', () => {
});

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

test('getLeaves handles null-property features', () => {
const index = new Supercluster({getId}).load(places.features.concat([{
const index = new Supercluster({getId}).load(structuredClone(places.features).concat([{
type: 'Feature',
properties: null,
geometry: {
Expand All @@ -75,7 +75,7 @@ test('getLeaves handles null-property features', () => {
});

test('returns cluster expansion zoom', () => {
const index = new Supercluster({getId}).load(places.features);
const index = new Supercluster({getId}).load(structuredClone(places.features));
assert.deepEqual(index.getClusterExpansionZoom(164), 1);
assert.deepEqual(index.getClusterExpansionZoom(196), 1);
assert.deepEqual(index.getClusterExpansionZoom(581), 2);
Expand All @@ -89,7 +89,7 @@ test('returns cluster expansion zoom for maxZoom', () => {
extent: 256,
maxZoom: 4,
getId
}).load(places.features);
}).load(structuredClone(places.features));

assert.deepEqual(index.getClusterExpansionZoom(2504), 5);
});
Expand All @@ -100,7 +100,7 @@ test('aggregates cluster properties with reduce', () => {
reduce: (a, b) => { a.sum += b.sum; },
radius: 100,
getId
}).load(places.features);
}).load(structuredClone(places.features));

assert.deepEqual(index.getTile(1, 0, 0).features.map(f => f.tags.sum).filter(Boolean),
[8, 19, 12, 23, 146, 34, 8, 29, 84, 63, 35, 80]);
Expand Down Expand Up @@ -150,7 +150,7 @@ test('returns clusters when query crosses international dateline', () => {
});

test('does not crash on weird bbox values', () => {
const index = new Supercluster({getId}).load(places.features);
const index = new Supercluster({getId}).load(structuredClone(places.features));
assert.equal(index.getClusters([129.426390, -103.720017, -445.930843, 114.518236], 1).length, 26);
assert.equal(index.getClusters([112.207836, -84.578666, -463.149397, 120.169159], 1).length, 27);
assert.equal(index.getClusters([129.886277, -82.332680, -445.470956, 120.390930], 1).length, 26);
Expand All @@ -161,7 +161,7 @@ test('does not crash on weird bbox values', () => {
});

test('does not crash on non-integer zoom values', () => {
const index = new Supercluster({getId}).load(places.features);
const index = new Supercluster({getId}).load(structuredClone(places.features));
assert.ok(index.getClusters([179, -10, -177, 10], 1.25));
});

Expand Down Expand Up @@ -195,7 +195,7 @@ test('does not throw on zero items', () => {
});

test('update properties succeeds', () => {
const index = new Supercluster({getId}).load(places.features);
const index = new Supercluster({getId}).load(structuredClone(places.features));
const leafNames = index.getLeaves(164, 3, 5).map(p => p.properties.name);
assert.deepEqual(leafNames, [
'I. de Cozumel',
Expand All @@ -213,7 +213,7 @@ test('update properties succeeds', () => {
});

test('update properties with different location fails', () => {
const index = new Supercluster({getId}).load(places.features);
const index = new Supercluster({getId}).load(structuredClone(places.features));
// Change location of point 160 and try to update.
index.updatePointProperties(160, {geometry: {coordinates: [0, 0]}});
// Result should not have changed.
Expand Down