From b94ca595a1eda27a6a62d548ead56cd4852d7294 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Viricel?= Date: Tue, 4 Jun 2024 10:14:03 +0200 Subject: [PATCH] feat: show superposed POIs #226 --- components/MainMap/MapFeatures.vue | 8 +- components/Map/MapBase.vue | 18 +-- lib/clusters.ts | 50 ++++++++ lib/markerLayerFactory.ts | 197 +++++++++++++++-------------- 4 files changed, 157 insertions(+), 116 deletions(-) diff --git a/components/MainMap/MapFeatures.vue b/components/MainMap/MapFeatures.vue index 352cf504..2b97fbac 100644 --- a/components/MainMap/MapFeatures.vue +++ b/components/MainMap/MapFeatures.vue @@ -117,7 +117,6 @@ export default defineNuxtComponent({ const { config } = storeToRefs(useSiteStore()) const mapStore = useMapStore() const { center, selectedFeature } = storeToRefs(mapStore) - const mapStyleLoaded = ref(false) return { center, @@ -125,20 +124,17 @@ export default defineNuxtComponent({ device, mapBase: ref>(), mapStore, - mapStyleLoaded, selectedFeature, } }, data(): { map: Map - markers: { [id: string]: Marker } selectedFeatureMarker?: Marker selectedBackground: MapStyleEnum } { return { map: null!, - markers: {}, selectedBackground: DEFAULT_MAP_STYLE, } }, @@ -259,11 +255,9 @@ export default defineNuxtComponent({ }) this.showSelectedFeature() - this.mapStyleLoaded = true }, // Map interactions - onClick(e: MapMouseEvent) { let selectedFeatures = STYLE_LAYERS.map((layerId) => { return this.map.queryRenderedFeatures(e.point, { @@ -315,7 +309,7 @@ export default defineNuxtComponent({ // Map view onMapRender() { - if (this.mapStyleLoaded && this.selectedFeature) { + if (this.map && this.map.getSource(POI_SOURCE) && this.map.isSourceLoaded(POI_SOURCE) && this.selectedFeature) { const marker = createMarker((this.selectedFeature.geometry as GeoJSON.Point).coordinates as [number, number]) this.setSelectedFeatureMarker(marker) } diff --git a/components/Map/MapBase.vue b/components/Map/MapBase.vue index 3410a410..645d9ddf 100644 --- a/components/Map/MapBase.vue +++ b/components/Map/MapBase.vue @@ -104,14 +104,12 @@ export default defineNuxtComponent({ map: maplibregl.Map poiFilter: PoiFilter | null poiLayerTemplate: maplibregl.LayerSpecification | undefined - markers: { [id: string]: maplibregl.Marker } fullAttribution: string } { return { map: null!, poiFilter: null, poiLayerTemplate: undefined, - markers: {}, fullAttribution: '', } }, @@ -198,6 +196,7 @@ export default defineNuxtComponent({ .filter(feature => !!feature) .map((feature, index) => { feature.id = index + return feature }) }, @@ -241,7 +240,7 @@ export default defineNuxtComponent({ cluster: cluster === undefined ? true : cluster, clusterRadius: 32, clusterProperties: clusterProps, - clusterMaxZoom: 15, + clusterMaxZoom: 20, tolerance: 0.6, data: { type: 'FeatureCollection', @@ -342,7 +341,7 @@ export default defineNuxtComponent({ this.$emit('mapStyleLoad', style) }, - onMapRender( + async onMapRender( eventName: | 'mapData' | 'mapDragEnd' @@ -353,14 +352,9 @@ export default defineNuxtComponent({ | 'mapZoomEnd', event: any, ) { - if ( - this.map - && this.map.getSource(POI_SOURCE) - && this.map.isSourceLoaded(POI_SOURCE) - ) { - this.markers = updateMarkers( + if (this.map && this.map.getSource(POI_SOURCE) && this.map.isSourceLoaded(POI_SOURCE)) { + await updateMarkers( this.map as maplibregl.Map, - this.markers, POI_SOURCE, this.fitBounds, (feature: ApiPoi, marker?: Marker) => this.$emit('featureClick', feature, marker), @@ -415,7 +409,7 @@ export default defineNuxtComponent({ -