From e8c09e3ad4244fe2a56959a301f827f2a4f466fe Mon Sep 17 00:00:00 2001 From: Devin Cowan Date: Thu, 20 Nov 2025 11:00:23 -0500 Subject: [PATCH] feat: enhance context menu with feature deselection and selection logic --- frontend/src/components/ContextMenu.vue | 12 ++++++++++-- frontend/src/components/TheLeafletMap.vue | 24 ++++++++++++++++++++++- frontend/src/helpers/map.js | 24 +++++++++++++++++++---- 3 files changed, 53 insertions(+), 7 deletions(-) diff --git a/frontend/src/components/ContextMenu.vue b/frontend/src/components/ContextMenu.vue index 25a3ddec..a995a0af 100644 --- a/frontend/src/components/ContextMenu.vue +++ b/frontend/src/components/ContextMenu.vue @@ -12,7 +12,7 @@ @@ -23,10 +23,13 @@ Select Additional Feature + + Deselect Feature + Zoom to Feature - + Select Feature @@ -43,6 +46,10 @@ defineProps({ context: { type: Object, required: true + }, + isFeatureSelected: { + type: Boolean, + default: false } }) @@ -50,6 +57,7 @@ defineEmits([ 'close', 'zoom-to-feature', 'select-feature', + 'deselect-feature', 'select-additional-feature', 'show-feature-info', 'dismiss' diff --git a/frontend/src/components/TheLeafletMap.vue b/frontend/src/components/TheLeafletMap.vue index 0f4f1b65..0c50d94a 100644 --- a/frontend/src/components/TheLeafletMap.vue +++ b/frontend/src/components/TheLeafletMap.vue @@ -7,9 +7,11 @@ { + if (!contextMenu.value.feature) return false + + const featureStore = useFeaturesStore() + const { selectedFeatures } = storeToRefs(featureStore) + + return selectedFeatures.value.some( + (feature) => feature.properties.COMID === contextMenu.value.feature.properties.COMID + ) +}) + +// Add new context menu handler for deselection +function contextDeselectFeature() { + if (contextMenu.value.feature) { + featureStore.deselectFeature(contextMenu.value.feature) + } + contextMenu.value.show = false + contextMenuFeatureLatLng.value = null +} + // Keyboard event handlers const handleKeyDown = (event) => { if ((event.ctrlKey || event.metaKey) && multiReachMode) { diff --git a/frontend/src/helpers/map.js b/frontend/src/helpers/map.js index 60f69b9a..8683f4d2 100644 --- a/frontend/src/helpers/map.js +++ b/frontend/src/helpers/map.js @@ -522,7 +522,7 @@ const showHoverPopup = (feature, latlng, closeable = false) => { function createFlowlinesFeatureLayer(region) { const featureStore = useFeaturesStore() - const { multiReachMode } = storeToRefs(featureStore) + const { multiReachMode, selectedFeatures } = storeToRefs(featureStore) let url = `https://arcgis.cuahsi.org/arcgis/rest/services/CIROH-ComRes/${region.name}/FeatureServer/${region.flowlinesLayerNumber}` const featureLayer = esriLeaflet.featureLayer({ url: url, @@ -579,11 +579,27 @@ function createFlowlinesFeatureLayer(region) { featureLayer.on('click', function (e) { const feature = e.layer.feature console.log('Feature clicked:', feature) + const isCtrlOrCmdClick = e.originalEvent.ctrlKey || e.originalEvent.metaKey - if (isCtrlOrCmdClick && multiReachMode.value) { - console.log('Multi-select enabled via Ctrl/Cmd key.') - featureStore.mergeFeature(feature) + + // Check if feature is already selected + const isAlreadySelected = selectedFeatures.value.some( + (selected) => selected.properties.COMID === feature.properties.COMID + ) + + if (multiReachMode.value && isCtrlOrCmdClick) { + console.log('Multi-select mode with Ctrl/Cmd key.') + if (isAlreadySelected) { + // Deselect the feature if already selected + console.log('Deselecting feature in multi-reach mode') + featureStore.deselectFeature(feature) + } else { + // Select additional feature + console.log('Selecting additional feature in multi-reach mode') + featureStore.mergeFeature(feature) + } } else { + // Normal selection behavior (replace current selection) featureStore.selectFeature(feature) } })