Skip to content

Commit

Permalink
Deep cloning of cluster properties. Closes mapbox#215
Browse files Browse the repository at this point in the history
  • Loading branch information
oscarfonts committed Mar 18, 2024
1 parent fff7326 commit 6b968a0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
8 changes: 4 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand All @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 6b968a0

Please sign in to comment.