From eff3b68a5115428b010501a159e7f5e1c20248d6 Mon Sep 17 00:00:00 2001 From: geospackle <52420266+geospackle@users.noreply.github.com> Date: Thu, 9 Apr 2020 13:25:04 -0400 Subject: [PATCH 01/11] Added support for multipoint features multiToSingles(multiPointFeature) returns a copy of the original multipoint feature for each point in it, replacing values of coordinates and geometry type with the values of the single point geometry --- index.js | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index b8bb7e24..1d87a574 100644 --- a/index.js +++ b/index.js @@ -36,13 +36,23 @@ export default class Supercluster { this.points = points; // generate a cluster object for each point and index input points into a KD-tree + // dissemble multipoint features let clusters = []; for (let i = 0; i < points.length; i++) { - if (!points[i].geometry) continue; - clusters.push(createPointCluster(points[i], i)); + if (!points[i].geometry) { + continue; + } else if (points[i].geometry.type === 'MultiPoint') { + const newPointFeatures = multiToSingles(points[i]); + for (let j=0; j < newPointFeatures.length; j++) { + clusters.push(createPointCluster(newPointFeatures[j], i)); + } + } else { + clusters.push(createPointCluster(points[i], i)); + } } this.trees[maxZoom + 1] = new KDBush(clusters, getX, getY, nodeSize, Float32Array); + if (log) console.timeEnd(timerId); // cluster points on max zoom, then cluster the results on previous zoom, etc.; @@ -380,3 +390,15 @@ function getX(p) { function getY(p) { return p.y; } + +function multiToSingles(multiPointFeature) { + let featureTemplate = $.extend(true, {}, multiPointFeature); + let newFeatures = []; + for (let i = 0; i < multiPointFeature.geometry.coordinates.length; i++) { + const newCoordinates = multiPointFeature.geometry.coordinates[i]; + featureTemplate.geometry.coordinates = newCoordinates; + featureTemplate.geometry.type = 'Point'; + newFeatures.push(featureTemplate); + } + return newFeatures; +} From 2398ef0d4623f708b7d0bc9c429d0cc9988201df Mon Sep 17 00:00:00 2001 From: geospackle <52420266+geospackle@users.noreply.github.com> Date: Thu, 9 Apr 2020 13:30:17 -0400 Subject: [PATCH 02/11] Update index.js --- index.js | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/index.js b/index.js index 1d87a574..a3b3398a 100644 --- a/index.js +++ b/index.js @@ -40,15 +40,15 @@ export default class Supercluster { let clusters = []; for (let i = 0; i < points.length; i++) { if (!points[i].geometry) { - continue; - } else if (points[i].geometry.type === 'MultiPoint') { - const newPointFeatures = multiToSingles(points[i]); - for (let j=0; j < newPointFeatures.length; j++) { - clusters.push(createPointCluster(newPointFeatures[j], i)); - } - } else { + continue; + } else if (points[i].geometry.type === 'MultiPoint') { + const newPointFeatures = multiToSingles(points[i]); + for (let j=0; j < newPointFeatures.length; j++) { + clusters.push(createPointCluster(newPointFeatures[j], i)); + } + } else { clusters.push(createPointCluster(points[i], i)); - } + } } this.trees[maxZoom + 1] = new KDBush(clusters, getX, getY, nodeSize, Float32Array); @@ -392,13 +392,13 @@ function getY(p) { } function multiToSingles(multiPointFeature) { - let featureTemplate = $.extend(true, {}, multiPointFeature); - let newFeatures = []; - for (let i = 0; i < multiPointFeature.geometry.coordinates.length; i++) { - const newCoordinates = multiPointFeature.geometry.coordinates[i]; - featureTemplate.geometry.coordinates = newCoordinates; - featureTemplate.geometry.type = 'Point'; - newFeatures.push(featureTemplate); - } - return newFeatures; + let featureTemplate = $.extend(true, {}, multiPointFeature); + let newFeatures = []; + for (let i = 0; i < multiPointFeature.geometry.coordinates.length; i++) { + const newCoordinates = multiPointFeature.geometry.coordinates[i]; + featureTemplate.geometry.coordinates = newCoordinates; + featureTemplate.geometry.type = 'Point'; + newFeatures.push(featureTemplate); + } + return newFeatures; } From 5a05018cbaa369107868805338ec8039454bf196 Mon Sep 17 00:00:00 2001 From: geospackle <52420266+geospackle@users.noreply.github.com> Date: Mon, 13 Apr 2020 10:21:59 -0400 Subject: [PATCH 03/11] fixed formatting and variable declaration --- index.js | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/index.js b/index.js index a3b3398a..b503442e 100644 --- a/index.js +++ b/index.js @@ -41,18 +41,18 @@ export default class Supercluster { for (let i = 0; i < points.length; i++) { if (!points[i].geometry) { continue; - } else if (points[i].geometry.type === 'MultiPoint') { - const newPointFeatures = multiToSingles(points[i]); - for (let j=0; j < newPointFeatures.length; j++) { + } else if (points[i].geometry.type === 'MultiPoint') { + const newPointFeatures = multiToSingles(points[i]); + for (let j = 0; j < newPointFeatures.length; j++) { clusters.push(createPointCluster(newPointFeatures[j], i)); - } - } else { + } + } else { clusters.push(createPointCluster(points[i], i)); - } + } } this.trees[maxZoom + 1] = new KDBush(clusters, getX, getY, nodeSize, Float32Array); - - + + if (log) console.timeEnd(timerId); // cluster points on max zoom, then cluster the results on previous zoom, etc.; @@ -392,13 +392,13 @@ function getY(p) { } function multiToSingles(multiPointFeature) { - let featureTemplate = $.extend(true, {}, multiPointFeature); - let newFeatures = []; + const featureTemplate = $.extend(true, {}, multiPointFeature); + const newFeatures = []; for (let i = 0; i < multiPointFeature.geometry.coordinates.length; i++) { const newCoordinates = multiPointFeature.geometry.coordinates[i]; - featureTemplate.geometry.coordinates = newCoordinates; - featureTemplate.geometry.type = 'Point'; - newFeatures.push(featureTemplate); + featureTemplate.geometry.coordinates = newCoordinates; + featureTemplate.geometry.type = 'Point'; + newFeatures.push(featureTemplate); } return newFeatures; } From 604b2a04f3b66ba412e58751f0607b7a2c4aaa90 Mon Sep 17 00:00:00 2001 From: geospackle <52420266+geospackle@users.noreply.github.com> Date: Mon, 13 Apr 2020 10:33:12 -0400 Subject: [PATCH 04/11] fixed formatiing --- index.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index b503442e..6d8adb9b 100644 --- a/index.js +++ b/index.js @@ -43,7 +43,7 @@ export default class Supercluster { continue; } else if (points[i].geometry.type === 'MultiPoint') { const newPointFeatures = multiToSingles(points[i]); - for (let j = 0; j < newPointFeatures.length; j++) { + for (let j = 0; j < newPointFeatures.length; j++) { clusters.push(createPointCluster(newPointFeatures[j], i)); } } else { @@ -51,8 +51,7 @@ export default class Supercluster { } } this.trees[maxZoom + 1] = new KDBush(clusters, getX, getY, nodeSize, Float32Array); - - + if (log) console.timeEnd(timerId); // cluster points on max zoom, then cluster the results on previous zoom, etc.; From 68d7c619a86afb3e105d57a518206c71946ff7a1 Mon Sep 17 00:00:00 2001 From: geospackle <52420266+geospackle@users.noreply.github.com> Date: Tue, 14 Apr 2020 09:23:20 -0400 Subject: [PATCH 05/11] Update index.js --- index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/index.js b/index.js index 6d8adb9b..35dfd97f 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,8 @@ import KDBush from 'kdbush'; +const $ = window.$; + const defaultOptions = { minZoom: 0, // min zoom to generate clusters on maxZoom: 16, // max zoom level to cluster the points on From 5825a9560eb88357631fda79d068bcbc3b80c402 Mon Sep 17 00:00:00 2001 From: geospackle <52420266+geospackle@users.noreply.github.com> Date: Tue, 14 Apr 2020 09:34:30 -0400 Subject: [PATCH 06/11] Update index.js --- index.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/index.js b/index.js index 35dfd97f..6d8adb9b 100644 --- a/index.js +++ b/index.js @@ -1,8 +1,6 @@ import KDBush from 'kdbush'; -const $ = window.$; - const defaultOptions = { minZoom: 0, // min zoom to generate clusters on maxZoom: 16, // max zoom level to cluster the points on From b4063a83b05640123a1fe63745b6c0f6273e49ea Mon Sep 17 00:00:00 2001 From: geospackle <52420266+geospackle@users.noreply.github.com> Date: Tue, 14 Apr 2020 09:51:48 -0400 Subject: [PATCH 07/11] Substituted use of jquery in multiToSingles() --- index.js | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index 6d8adb9b..c2fd647a 100644 --- a/index.js +++ b/index.js @@ -391,13 +391,21 @@ function getY(p) { } function multiToSingles(multiPointFeature) { - const featureTemplate = $.extend(true, {}, multiPointFeature); - const newFeatures = []; - for (let i = 0; i < multiPointFeature.geometry.coordinates.length; i++) { - const newCoordinates = multiPointFeature.geometry.coordinates[i]; - featureTemplate.geometry.coordinates = newCoordinates; - featureTemplate.geometry.type = 'Point'; - newFeatures.push(featureTemplate); + const featureTemplate = { + "type": "Feature", + "properties": { + }, + "geometry": { + } } - return newFeatures; + const newFeatures = []; + for (let i = 0; i < multiPointFeature.geometry.coordinates.length; i++) { + const newCoordinates = multiPointFeature.geometry.coordinates[i]; + const newProperties = multiPointFeature.properties[i]; + featureTemplate.geometry.properties = newProperties; + featureTemplate.geometry.coordinates = newCoordinates; + featureTemplate.geometry.type = 'Point'; + newFeatures.push(featureTemplate); + } + return newFeatures; } From 63de627edd2bf7c52615b68ea5ead754bfe2ff36 Mon Sep 17 00:00:00 2001 From: geospackle <52420266+geospackle@users.noreply.github.com> Date: Tue, 14 Apr 2020 09:56:25 -0400 Subject: [PATCH 08/11] Fixed formatting --- index.js | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/index.js b/index.js index c2fd647a..91db0647 100644 --- a/index.js +++ b/index.js @@ -392,20 +392,20 @@ function getY(p) { function multiToSingles(multiPointFeature) { const featureTemplate = { - "type": "Feature", - "properties": { - }, - "geometry": { - } - } - const newFeatures = []; - for (let i = 0; i < multiPointFeature.geometry.coordinates.length; i++) { - const newCoordinates = multiPointFeature.geometry.coordinates[i]; - const newProperties = multiPointFeature.properties[i]; - featureTemplate.geometry.properties = newProperties; - featureTemplate.geometry.coordinates = newCoordinates; - featureTemplate.geometry.type = 'Point'; - newFeatures.push(featureTemplate); - } - return newFeatures; + 'type': 'Feature', + 'properties': { + }, + 'geometry': { + } + }; + const newFeatures = []; + for (let i = 0; i < multiPointFeature.geometry.coordinates.length; i++) { + const newCoordinates = multiPointFeature.geometry.coordinates[i]; + const newProperties = multiPointFeature.properties[i]; + featureTemplate.geometry.properties = newProperties; + featureTemplate.geometry.coordinates = newCoordinates; + featureTemplate.geometry.type = 'Point'; + newFeatures.push(featureTemplate); + } + return newFeatures; } From c883ca9851321edfe81e16ba134aa22dcb91e1c2 Mon Sep 17 00:00:00 2001 From: geospackle <52420266+geospackle@users.noreply.github.com> Date: Tue, 14 Apr 2020 09:58:46 -0400 Subject: [PATCH 09/11] Fixed formatting --- index.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/index.js b/index.js index 91db0647..d9560122 100644 --- a/index.js +++ b/index.js @@ -398,14 +398,14 @@ function multiToSingles(multiPointFeature) { 'geometry': { } }; - const newFeatures = []; - for (let i = 0; i < multiPointFeature.geometry.coordinates.length; i++) { - const newCoordinates = multiPointFeature.geometry.coordinates[i]; - const newProperties = multiPointFeature.properties[i]; - featureTemplate.geometry.properties = newProperties; - featureTemplate.geometry.coordinates = newCoordinates; - featureTemplate.geometry.type = 'Point'; - newFeatures.push(featureTemplate); - } - return newFeatures; + const newFeatures = []; + for (let i = 0; i < multiPointFeature.geometry.coordinates.length; i++) { + const newCoordinates = multiPointFeature.geometry.coordinates[i]; + const newProperties = multiPointFeature.properties[i]; + featureTemplate.geometry.properties = newProperties; + featureTemplate.geometry.coordinates = newCoordinates; + featureTemplate.geometry.type = 'Point'; + newFeatures.push(featureTemplate); + } + return newFeatures; } From b30861db0ef00b1acda18960c391c81968f7fc1e Mon Sep 17 00:00:00 2001 From: geospackle <52420266+geospackle@users.noreply.github.com> Date: Thu, 25 Jun 2020 13:25:26 -0400 Subject: [PATCH 10/11] Update index.js Fixed function multiToSingles --- index.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index d9560122..48913fc1 100644 --- a/index.js +++ b/index.js @@ -400,12 +400,13 @@ function multiToSingles(multiPointFeature) { }; const newFeatures = []; for (let i = 0; i < multiPointFeature.geometry.coordinates.length; i++) { - const newCoordinates = multiPointFeature.geometry.coordinates[i]; - const newProperties = multiPointFeature.properties[i]; - featureTemplate.geometry.properties = newProperties; - featureTemplate.geometry.coordinates = newCoordinates; - featureTemplate.geometry.type = 'Point'; - newFeatures.push(featureTemplate); + let newFeature = JSON.parse(JSON.stringify(featureTemplate)); + let newCoordinates = multiPointFeature.geometry.coordinates[i]; + let newProperties = multiPointFeature.properties; + newFeature.geometry.properties = newProperties; + newFeature.geometry.coordinates = newCoordinates; + newFeature.geometry.type = 'Point'; + newFeatures.push(newFeature); } - return newFeatures; +return newFeatures } From 0c1c6cc9cc3fa14c91e5a0ed383d3e2395b255eb Mon Sep 17 00:00:00 2001 From: geospackle <52420266+geospackle@users.noreply.github.com> Date: Fri, 26 Jun 2020 12:42:54 -0400 Subject: [PATCH 11/11] fixed formatting --- index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 48913fc1..647e3ec1 100644 --- a/index.js +++ b/index.js @@ -400,13 +400,13 @@ function multiToSingles(multiPointFeature) { }; const newFeatures = []; for (let i = 0; i < multiPointFeature.geometry.coordinates.length; i++) { - let newFeature = JSON.parse(JSON.stringify(featureTemplate)); - let newCoordinates = multiPointFeature.geometry.coordinates[i]; - let newProperties = multiPointFeature.properties; + const newFeature = JSON.parse(JSON.stringify(featureTemplate)); + const newCoordinates = multiPointFeature.geometry.coordinates[i]; + const newProperties = multiPointFeature.properties; newFeature.geometry.properties = newProperties; newFeature.geometry.coordinates = newCoordinates; newFeature.geometry.type = 'Point'; newFeatures.push(newFeature); } -return newFeatures + return newFeatures; }