From 936843c7eb2384cb3704995e02c3bfc881db3528 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Viricel?= Date: Wed, 4 Dec 2024 00:36:25 +0100 Subject: [PATCH] fix: more fine-grained map data event --- src/teritorio-cluster.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/teritorio-cluster.ts b/src/teritorio-cluster.ts index a8bcce1..468a809 100644 --- a/src/teritorio-cluster.ts +++ b/src/teritorio-cluster.ts @@ -101,12 +101,11 @@ export class TeritorioCluster extends EventTarget { this.unfoldedClusterRender = options?.unfoldedClusterRenderFn this.unfoldedClusterMaxLeaves = options?.unfoldedClusterMaxLeaves || 7 - // after the GeoJSON data is loaded, update markers on the screen and do so on every map move/moveend - map.on('data', (e: MapSourceDataEvent) => { - if (e.sourceId !== this.sourceId || !e.isSourceLoaded || e.sourceDataType === 'metadata') - return - - this.#render() + // After the GeoJSON data is loaded, update markers on the screen and do so on every map moveend + map.on('sourcedata', (ev: MapSourceDataEvent) => { + if (ev.isSourceLoaded && ev.sourceId === this.sourceId && ev.sourceDataType !== 'metadata') { + this.#render() + } }) map.on('moveend', this.#render)