From 68570c3d6fe046ef7e3854bf37ab5b3c4b0935d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Viricel?= Date: Tue, 19 Nov 2024 16:54:15 +0100 Subject: [PATCH] chore: simplify Position to LngLatLike conversion #23 --- src/teritorio-cluster.ts | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/teritorio-cluster.ts b/src/teritorio-cluster.ts index 9ff3b2a..f237310 100644 --- a/src/teritorio-cluster.ts +++ b/src/teritorio-cluster.ts @@ -1,5 +1,5 @@ import type { FitBoundsOptions, GeoJSONSource, LngLatLike, MapGeoJSONFeature, MapSourceDataEvent } from 'maplibre-gl' -import { LngLat, Marker, Point, type Map as MapGL } from 'maplibre-gl' +import { Marker, Point, type Map as MapGL } from 'maplibre-gl' import { clusterRenderDefault, markerRenderDefault, @@ -127,20 +127,20 @@ export class TeritorioCluster extends EventTarget { this.fitBoundsOptions = options } - setSelectedFeature = (feature: MapGeoJSONFeature) => { + setSelectedFeature = (feature: GeoJSON.Feature) => { const id = getFeatureId(feature) const match = this.#findFeature(id) if (!match) { if (feature.geometry.type !== 'Point') { - console.error(`Feature ${id} is not Geometry.Point, thus not supported yet.`) + console.error(`Feature ${id} is not of type 'Point', and is not supported.`) return } // Sets a Pin Marker on a specific coordinates which isn't related to any feature from data source this.resetSelectedFeature() this.selectedFeatureId = id - this.#renderPinMarker(new LngLat(feature.geometry.coordinates[0], feature.geometry.coordinates[1])) + this.#renderPinMarker(feature.geometry.coordinates as LngLatLike) return } @@ -149,16 +149,16 @@ export class TeritorioCluster extends EventTarget { this.selectedFeatureId = id if ('type' in match && match.type === 'Feature' && match.geometry.type === 'Point') { - const coords = match.geometry.coordinates - - this.#renderPinMarker(new LngLat(coords[0], coords[1])) + this.#renderPinMarker(match.geometry.coordinates as LngLatLike) return - } else if ('feature' in match && match.feature.geometry.type === 'Point') { + } + + if ('feature' in match && match.feature.geometry.type === 'Point') { const cluster = this.markersOnScreen.get(match.clusterId) if (!cluster) { - console.error(`Cluster ${match.clusterId} not found.`) + console.error(`Cluster with ID ${match.clusterId} not found.`) return } @@ -354,7 +354,7 @@ export class TeritorioCluster extends EventTarget { } this.featuresMap.forEach(feature => { - const coords = feature.geometry.type === 'Point' ? new LngLat(feature.geometry.coordinates[0], feature.geometry.coordinates[1]) : undefined + const coords = feature.geometry.type === 'Point' ? feature.geometry.coordinates as LngLatLike : undefined const id = getFeatureId(feature) if (!coords) {