From 18a9d9ace41dab878f4a83eec5ca1a610915bf4d Mon Sep 17 00:00:00 2001 From: Olivier Ribiere Date: Sat, 18 Jan 2025 18:35:29 +0100 Subject: [PATCH] feat(map): remove map layers from legend --- vue/src/services/map/LegendService.ts | 16 +++++++++ vue/src/stores/myMapStore.ts | 34 ++++++++++++++------ vue/src/views/map/components/MyMapLegend.vue | 12 +++++-- 3 files changed, 51 insertions(+), 11 deletions(-) diff --git a/vue/src/services/map/LegendService.ts b/vue/src/services/map/LegendService.ts index c9252de..d8a0391 100644 --- a/vue/src/services/map/LegendService.ts +++ b/vue/src/services/map/LegendService.ts @@ -15,6 +15,7 @@ export class LegendService { legendList.value.forEach((legendItem, i) => { legendItem.order = i }) + console.log(legendList.value) } else { if (layerType === LayerType.APP_LAYER) { legendList.value.push({ @@ -59,4 +60,19 @@ export class LegendService { const layers = map.getStyle().layers // Récupère la liste des couches console.log('Liste des couches:', layers) } + + static updateAtlasSubLayersOrder( + atlasMapLayer: AtlasLayerLegendItem, + atlasThematicMaps: Ref + ) { + const atlasThematicMap = atlasThematicMaps.value.find((x) => x.id === atlasMapLayer.id) + if (atlasThematicMap) { + atlasMapLayer.subLayers.map((sortedSubLayer) => { + for (const sublayer of atlasThematicMap.subLayers) { + if (sublayer.id === sortedSubLayer.name) sublayer.mapOrder = sortedSubLayer.order + } + }) + atlasThematicMap.subLayers.sort((a, b) => a.mapOrder! - b.mapOrder!) + } + } } diff --git a/vue/src/stores/myMapStore.ts b/vue/src/stores/myMapStore.ts index 01802d6..b9800d7 100644 --- a/vue/src/stores/myMapStore.ts +++ b/vue/src/stores/myMapStore.ts @@ -88,16 +88,31 @@ export const useMyMapStore = defineStore(StoresList.MY_MAP, () => { } function updateAtlasSubLayersOrder(atlasMapLayer: AtlasLayerLegendItem) { - const atlasThematicMap = atlasThematicMaps.value.find((x) => x.id === atlasMapLayer.id) - if (atlasThematicMap) { - atlasMapLayer.subLayers.map((sortedSubLayer) => { - for (const sublayer of atlasThematicMap.subLayers) { - if (sublayer.id === sortedSubLayer.name) sublayer.mapOrder = sortedSubLayer.order + LegendService.updateAtlasSubLayersOrder(atlasMapLayer, atlasThematicMaps) + updateAtlasLayersVisibility(atlasMapLayer.id, false) + updateLegendOrder() + } + + function removeLayerFromLegend(item: AtlasLayerLegendItem | AppLayerLegendItem) { + if (item.layerType === LayerType.ATLAS_LAYER) { + atlasThematicMaps.value.map((x) => { + if (x.id === item.id) { + x.mainLayer.isShown = false + updateAtlasLayersVisibility(item.id) } }) - atlasThematicMap.subLayers.sort((a, b) => a.mapOrder! - b.mapOrder!) - updateAtlasLayersVisibility(atlasMapLayer.id, false) - updateLegendOrder() + } else { + switch (item.id) { + case ItemType.ACTOR: + actorLayer.value!.isShown = false + break + case ItemType.PROJECT: + projectLayer.value!.isShown = false + break + case ItemType.RESOURCE: + resourceLayer.value!.isShown = false + break + } } } @@ -116,6 +131,7 @@ export const useMyMapStore = defineStore(StoresList.MY_MAP, () => { updateAtlasLayersVisibility, legendList, updateLegendOrder, - updateAtlasSubLayersOrder + updateAtlasSubLayersOrder, + removeLayerFromLegend } }) diff --git a/vue/src/views/map/components/MyMapLegend.vue b/vue/src/views/map/components/MyMapLegend.vue index 3a0c2c2..6f88039 100644 --- a/vue/src/views/map/components/MyMapLegend.vue +++ b/vue/src/views/map/components/MyMapLegend.vue @@ -22,7 +22,11 @@ {{ item.name }}
- +