From 6b968a047bea4a09703609f67d0b9ab6b3c8d4ca Mon Sep 17 00:00:00 2001 From: Oscar Fonts Date: Mon, 18 Mar 2024 15:52:16 +0100 Subject: [PATCH] Deep cloning of cluster properties. Closes #215 --- index.js | 8 ++++---- package.json | 3 +++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index c56439669..8ec6d4c98 100644 --- a/index.js +++ b/index.js @@ -369,11 +369,11 @@ export default class Supercluster { _map(data, i, clone) { if (data[i + OFFSET_NUM] > 1) { const props = this.clusterProps[data[i + OFFSET_PROP]]; - return clone ? Object.assign({}, props) : props; + return clone ? structuredClone(props) : props; } const original = this.points[data[i + OFFSET_ID]].properties; const result = this.options.map(original); - return clone && result === original ? Object.assign({}, result) : result; + return clone && result === original ? structuredClone(result) : result; } } @@ -395,8 +395,8 @@ function getClusterProperties(data, i, clusterProps) { count >= 10000 ? `${Math.round(count / 1000) }k` : count >= 1000 ? `${Math.round(count / 100) / 10 }k` : count; const propIndex = data[i + OFFSET_PROP]; - const properties = propIndex === -1 ? {} : Object.assign({}, clusterProps[propIndex]); - return Object.assign(properties, { + const properties = propIndex === -1 ? {} : structuredClone(clusterProps[propIndex]); + return Object.assign(properties ?? {}, { cluster: true, cluster_id: data[i + OFFSET_ID], point_count: count, diff --git a/package.json b/package.json index f0c6554c3..4d4a1a925 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,9 @@ "name": "supercluster", "version": "8.0.1", "description": "A very fast geospatial point clustering library.", + "engines": { + "node": ">=17.0.0" + }, "main": "dist/supercluster.js", "type": "module", "exports": "./index.js",