Skip to content

Commit

Permalink
chore: simplify Position to LngLatLike conversion #23
Browse files Browse the repository at this point in the history
  • Loading branch information
wazolab committed Nov 19, 2024
1 parent eefafbf commit 836ae08
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/teritorio-cluster.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 836ae08

Please sign in to comment.