From 61050a7a8a001d0d0de1cc4076b9a6f222729642 Mon Sep 17 00:00:00 2001 From: Bryon Lewis Date: Fri, 21 Feb 2025 10:54:37 -0500 Subject: [PATCH 1/8] add legend toggle, update color static selection --- client/src/components/LayerTypeConfig.vue | 157 +++++++++++++----- client/src/components/MapLegend.vue | 4 +- .../components/{ => MapLegends}/ColorKey.vue | 109 +++++++++++- .../components/{ => MapLegends}/FilterKey.vue | 10 +- client/src/types.ts | 1 + client/src/utils.ts | 16 ++ 6 files changed, 249 insertions(+), 48 deletions(-) rename client/src/components/{ => MapLegends}/ColorKey.vue (78%) rename client/src/components/{ => MapLegends}/FilterKey.vue (91%) diff --git a/client/src/components/LayerTypeConfig.vue b/client/src/components/LayerTypeConfig.vue index a447124..414f902 100644 --- a/client/src/components/LayerTypeConfig.vue +++ b/client/src/components/LayerTypeConfig.vue @@ -54,11 +54,12 @@ export default defineComponent({ return enabled; }); - type LayerActionItems = 'enabled' | 'selectable' | 'hoverable' | 'opacity' | 'zoomMinMax' | 'selectColor' | 'defaultSize' | 'color' | 'text' | 'heatmapControls'; + type LayerActionItems = 'enabled' | 'selectable' | 'hoverable' | 'opacity' | 'zoomMinMax' | 'selectColor' | 'defaultSize' | 'legend' | 'color' | 'text' | 'heatmapControls'; const layerActionItemsMap: Record = { enabled: ['line', 'fill', 'circle', 'fill-extrusion', 'text', 'heatmap'], selectable: ['line', 'fill', 'circle', 'fill-extrusion'], hoverable: ['line', 'fill', 'circle', 'fill-extrusion'], + legend: ['line', 'fill', 'circle', 'fill-extrusion', 'heatmap'], opacity: ['line', 'fill', 'circle', 'fill-extrusion', 'text', 'heatmap'], zoomMinMax: ['line', 'fill', 'circle', 'fill-extrusion', 'text', 'heatmap'], selectColor: ['line', 'fill', 'circle', 'fill-extrusion'], @@ -70,7 +71,7 @@ export default defineComponent({ const actionItemVisible = computed(() => { const enabledItems = new Set(); - const itemList: LayerActionItems[] = ['enabled', 'selectable', 'hoverable', 'opacity', 'zoomMinMax', 'selectColor', 'defaultSize', 'color', 'text', 'heatmapControls']; + const itemList: LayerActionItems[] = ['enabled', 'selectable', 'hoverable', 'legend', 'opacity', 'zoomMinMax', 'selectColor', 'defaultSize', 'color', 'text', 'heatmapControls']; itemList.forEach((key) => { if (layerActionItemsMap[key].includes(props.layerType)) { enabledItems.add(key); @@ -98,6 +99,9 @@ export default defineComponent({ if (field === 'hoverable') { displayConfig.hoverable = val; } + if (field === 'legend') { + displayConfig.legend = val; + } if (field === 'opacity') { if (val) { displayConfig.opacity = 0.75; @@ -239,6 +243,36 @@ export default defineComponent({ } } }; + + // Static color setting: + const getLayerConfigColor = () => { + const found = MapStore.selectedVectorMapLayers.value.find((item: VectorMapLayer) => item.id === props.layerId); + if (found?.default_style?.layers) { + const layerTypeVal = found?.default_style?.layers[props.layerType]; + if (layerTypeVal !== false && layerTypeVal !== true) { + if (layerTypeVal.color === undefined) { + layerTypeVal.color = '#00FF00'; + } + return layerTypeVal.color; + } + } + return '#00FF00'; + }; + const baseColorConfig = computed(() => getLayerConfigColor()); + + const updateStaticColor = (color: string) => { + const { layer } = getVectorLayerDisplayConfig(props.layerId, props.layerType); + if (layer?.default_style?.layers && layer.default_style.layers[props.layerType]) { + if ( + layer.default_style.layers[props.layerType] !== false + && layer.default_style.layers[props.layerType] !== true + ) { + (layer.default_style.layers[props.layerType] as VectorLayerDisplayConfig).color = color; + updateLayer(layer); + } + } + }; + return { currentLayerType, colorPickerVisible, @@ -259,6 +293,8 @@ export default defineComponent({ updateOpacity, updateZoom, actionItemVisible, + baseColorConfig, + updateStaticColor, }; }, }); @@ -294,6 +330,43 @@ export default defineComponent({ Enabled + + + + + + + + + {{ + valueDisplayCheckbox('opacity') ? 'mdi-checkbox-marked' : 'mdi-checkbox-blank-outline' }} + + Opacity + {{ currentLayerType.opacity.toFixed(2) }} + + + + + - + {{ valueDisplayCheckbox('selectColor') ? 'mdi-checkbox-marked' : 'mdi-checkbox-blank-outline' }} @@ -401,79 +474,68 @@ export default defineComponent({ - + - - + + {{ - valueDisplayCheckbox('opacity') ? 'mdi-checkbox-marked' : 'mdi-checkbox-blank-outline' }} + valueDisplayCheckbox('zoom') ? 'mdi-checkbox-marked' : 'mdi-checkbox-blank-outline' }} - Opacity - {{ currentLayerType.opacity.toFixed(2) }} + Zoom Min/Max - - + - + - + {{ - valueDisplayCheckbox('zoom') ? 'mdi-checkbox-marked' : 'mdi-checkbox-blank-outline' }} + valueDisplayCheckbox('legend') ? 'mdi-checkbox-marked' : 'mdi-checkbox-blank-outline' }} - Zoom Min/Max - - - + Legend - {{ getColorType() }} + + {{ getColorType() }} + + + + + + + diff --git a/client/src/components/MapLegend.vue b/client/src/components/MapLegend.vue index ed49c9b..165ff15 100644 --- a/client/src/components/MapLegend.vue +++ b/client/src/components/MapLegend.vue @@ -3,8 +3,8 @@ import { Ref, computed, defineComponent, ref, } from 'vue'; import MapStore from '../MapStore'; -import ColorKey from './ColorKey.vue'; -import FilterKey from './FilterKey.vue'; +import ColorKey from './MapLegends/ColorKey.vue'; +import FilterKey from './MapLegends/FilterKey.vue'; export default defineComponent({ components: { diff --git a/client/src/components/ColorKey.vue b/client/src/components/MapLegends/ColorKey.vue similarity index 78% rename from client/src/components/ColorKey.vue rename to client/src/components/MapLegends/ColorKey.vue index e10fffa..c4c2594 100644 --- a/client/src/components/ColorKey.vue +++ b/client/src/components/MapLegends/ColorKey.vue @@ -15,8 +15,8 @@ import { VectorLayerDisplay, VectorLayerDisplayConfig, VectorMapLayer, -} from '../types'; // Import your defined types -import { createColorNumberPairs, formatNumPrecision, getLayerAvailableProperties } from '../utils'; +} from '../../types'; // Import your defined types +import { createColorNumberPairs, formatNumPrecision, getLayerAvailableProperties } from '../../utils'; export default defineComponent({ name: 'ColorKey', @@ -71,7 +71,7 @@ export default defineComponent({ }; const layerDisplayConfig = layerDisplay as VectorLayerDisplayConfig; - if (layerDisplayConfig?.color && layerDisplayConfig.enabled) { + if (layerDisplayConfig?.color && layerDisplayConfig.enabled && layerDisplayConfig.legend) { if (type !== 'heatmap') { if (typeof layerDisplayConfig.color === 'string') { keyType.colors.push({ @@ -248,7 +248,7 @@ export default defineComponent({