Skip to content

Commit 27e2516

Browse files
authored
fix: skip clustering for when list of markers is empty (#1014)
Running the supercluster algorithm fails when there are no markers. Fixes: #991
1 parent 834c7a0 commit 27e2516

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/algorithms/supercluster.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,10 @@ export class SuperClusterAlgorithm extends AbstractAlgorithm {
6868
const position = MarkerUtils.getPosition(marker);
6969
const coordinates = [position.lng(), position.lat()];
7070
return {
71-
type: "Feature" as const,
72-
geometry: {
73-
type: "Point" as const,
74-
coordinates,
75-
},
71+
type: "Feature",
72+
geometry: { type: "Point", coordinates },
7673
properties: { marker },
77-
};
74+
} as const;
7875
});
7976
this.superCluster.load(points);
8077
}
@@ -87,6 +84,13 @@ export class SuperClusterAlgorithm extends AbstractAlgorithm {
8784

8885
this.state = state;
8986

87+
// when input is empty, return right away
88+
if (input.markers.length === 0) {
89+
this.clusters = [];
90+
91+
return { clusters: this.clusters, changed };
92+
}
93+
9094
if (changed) {
9195
this.clusters = this.cluster(input);
9296
}

0 commit comments

Comments
 (0)