From fe5d946cbe3898dc5c9391f060e7017c99e3b874 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Viricel?= Date: Wed, 11 Dec 2024 17:51:47 +0100 Subject: [PATCH] feat: set pin marker on initial feature not in source #51 --- src/teritorio-cluster.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/teritorio-cluster.ts b/src/teritorio-cluster.ts index 468a809..cf42930 100644 --- a/src/teritorio-cluster.ts +++ b/src/teritorio-cluster.ts @@ -438,6 +438,22 @@ export class TeritorioCluster extends EventTarget { marker.remove() } + if (this.initialFeature && !this.selectedFeatureId && !this.pinMarker) { + const id = this.#getFeatureId(this.initialFeature) + const coords = this.initialFeature.geometry.type === 'Point' + ? new maplibre.LngLat(this.initialFeature.geometry.coordinates[0], this.initialFeature.geometry.coordinates[1]) + : undefined + + if (!coords) { + console.error(`Coordinates not found for feature id : ${id}`) + return + } + + this.selectedFeatureId = id + this.#renderPinMarker(coords) + this.initialFeature = undefined + } + this.markersOnScreen = newMarkers this.ticking = false }