From 5fa8a0ab05b96f32971cc0393776f848a3f42a6c Mon Sep 17 00:00:00 2001 From: Martin Schuhfuss Date: Tue, 8 Jul 2025 15:51:14 +0200 Subject: [PATCH] fix: skip clustering for when list of markers is empty Running the supercluster algorithm fails when there are no markers. Fixes: #991 --- src/algorithms/supercluster.ts | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/algorithms/supercluster.ts b/src/algorithms/supercluster.ts index 75c69a70..6eb24f9c 100644 --- a/src/algorithms/supercluster.ts +++ b/src/algorithms/supercluster.ts @@ -68,13 +68,10 @@ export class SuperClusterAlgorithm extends AbstractAlgorithm { const position = MarkerUtils.getPosition(marker); const coordinates = [position.lng(), position.lat()]; return { - type: "Feature" as const, - geometry: { - type: "Point" as const, - coordinates, - }, + type: "Feature", + geometry: { type: "Point", coordinates }, properties: { marker }, - }; + } as const; }); this.superCluster.load(points); } @@ -87,6 +84,13 @@ export class SuperClusterAlgorithm extends AbstractAlgorithm { this.state = state; + // when input is empty, return right away + if (input.markers.length === 0) { + this.clusters = []; + + return { clusters: this.clusters, changed }; + } + if (changed) { this.clusters = this.cluster(input); }