From 2c9f1618f8a065cd9a20ae0e46e2e9a814b6c4dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Viricel?= Date: Mon, 2 Dec 2024 12:37:19 +0100 Subject: [PATCH] fix: cluster not found during async call #39 --- index.html | 5 ++++- src/teritorio-cluster.ts | 9 +++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/index.html b/index.html index 1a81735..745c688 100644 --- a/index.html +++ b/index.html @@ -142,8 +142,11 @@ } const removeData = () => { - const source = map.getSource('earthquakes') + if(teritorioCluster.ticking) + return + const source = map.getSource('earthquakes') + source.setData({ type: 'FeatureCollection', features: geojson.features diff --git a/src/teritorio-cluster.ts b/src/teritorio-cluster.ts index 710e3cc..674a1ad 100644 --- a/src/teritorio-cluster.ts +++ b/src/teritorio-cluster.ts @@ -343,8 +343,13 @@ export class TeritorioCluster extends EventTarget { // Get cluster's leaves if (feature.properties.cluster) { const source = this.map.getSource(this.sourceId) as GeoJSONSource - const leaves = await source.getClusterLeaves(Number.parseInt(id), feature.properties.point_count, 0) as MapGeoJSONFeature[] - this.clusterLeaves.set(id, leaves) + + try { + const leaves = await source.getClusterLeaves(Number.parseInt(id), feature.properties.point_count, 0) as MapGeoJSONFeature[] + this.clusterLeaves.set(id, leaves) + } catch(error) { + console.error(error) + } } }