From 85b0d733119930b48d03eb52fafca5a342d53862 Mon Sep 17 00:00:00 2001 From: hvangeffen Date: Wed, 11 Dec 2024 13:55:13 +0100 Subject: [PATCH] Scope current colour scales to spatialdisplay instance --- .../SpatialDisplayComponent.vue | 125 +++++------------- src/components/wms/InformationPanel.vue | 84 +++++++----- src/services/useColourScales/index.ts | 56 ++++++++ src/services/useWms/index.ts | 10 +- src/stores/colourScales.ts | 115 ++++++++++------ 5 files changed, 225 insertions(+), 165 deletions(-) create mode 100644 src/services/useColourScales/index.ts diff --git a/src/components/spatialdisplay/SpatialDisplayComponent.vue b/src/components/spatialdisplay/SpatialDisplayComponent.vue index 56540a13..25628e50 100644 --- a/src/components/spatialdisplay/SpatialDisplayComponent.vue +++ b/src/components/spatialdisplay/SpatialDisplayComponent.vue @@ -13,18 +13,18 @@ :streamlineOptions="layerCapabilities?.animatedVectors" @doubleclick="onCoordinateClick" /> -
+
() const isLoading = ref(false) let debouncedSetLayerOptions!: () => void -const legendLayerName = ref(props.layerName) const legendLayerStyles = ref() const settings = useUserSettingsStore() @@ -231,6 +223,9 @@ const showLayer = ref(true) const layerKind = ref(LayerKind.Static) const colourScalesStore = useColourScalesStore() +const currentColourScale = ref() +const currentColourScaleIds = ref([]) + const workflowsStore = useWorkflowsStore() const showLocationsLayer = ref(true) @@ -248,73 +243,22 @@ watchEffect(() => { watch( legendLayerStyles, - () => { - const styles = legendLayerStyles.value + (styles) => { if (styles === undefined) { - colourScalesStore.currentIds = [] - colourScalesStore.currentIndex = 0 + currentColourScaleIds.value = [] return } - legendLayerName.value = props.layerName - colourScalesStore.currentIds = styles.map(styleToId) - colourScalesStore.currentIndex = 0 - - styles.forEach(async (style) => { - const styleId = styleToId(style) - - if (!(styleId in colourScalesStore.scales)) { - const initialLegendGraphic = await fetchWmsLegend( - baseUrl, - legendLayerName.value, - settings.useDisplayUnits, - undefined, - style, - ) - - const legend = initialLegendGraphic.legend - const newColourScale = reactive({ - title: getLegendTitle( - props.layerCapabilities?.title ?? '', - initialLegendGraphic, - ), - style: style, - colourMap: legend, - range: legendToRange(legend), - initialRange: legendToRange(legend), - useGradients: !legend.some((entry) => entry.colorSmoothing === false), - }) - colourScalesStore.scales[styleId] = newColourScale - - const range = computed(() => { - const newRange = rangeToString(newColourScale.range) - const initialRange = rangeToString(newColourScale.initialRange) - - return newRange !== initialRange ? newRange : undefined - }) - - const newLegendGraphic = useWmsLegend( - baseUrl, - legendLayerName, - () => settings.useDisplayUnits, - range, - style, - () => - props.layerCapabilities - ? (props.layerCapabilities.styles ?? [style]) - : undefined, - ) - - watch(newLegendGraphic, () => { - if (newLegendGraphic.value?.legend === undefined) return - colourScalesStore.scales[styleId].title = getLegendTitle( - props.layerCapabilities?.title ?? '', - newLegendGraphic.value, - ) - colourScalesStore.scales[styleId].colourMap = - newLegendGraphic.value.legend - }) - } + currentColourScaleIds.value = styles.map(styleToId) + + styles.forEach((style) => { + colourScalesStore.addScale( + style, + props.layerName, + () => props.layerCapabilities?.title, + () => settings.useDisplayUnits, + () => props.layerCapabilities?.styles ?? [], + ) }) }, { immediate: true }, @@ -364,7 +308,6 @@ watch( const _forecastTime = layer?.keywordList?.[0].forecastTime forecastTime.value = _forecastTime ? new Date(_forecastTime) : undefined - legendLayerName.value = props.layerName legendLayerStyles.value = props.layerCapabilities?.styles if (legendLayerStyles.value === undefined && props.layerName) { legendLayerStyles.value = [ @@ -395,7 +338,7 @@ watch(currentElevation, () => { }) watch( - [() => colourScalesStore.currentScale?.range, () => settings.useDisplayUnits], + [() => currentColourScale.value?.range, () => settings.useDisplayUnits], () => { setLayerOptions() }, @@ -443,10 +386,10 @@ function setLayerOptions(): void { ? convertBoundingBoxToLngLatBounds(props.layerCapabilities.boundingBox) : undefined, elevation: currentElevation.value, - colorScaleRange: colourScalesStore.currentScale?.range - ? rangeToString(colourScalesStore.currentScale?.range) + colorScaleRange: currentColourScale.value?.range + ? rangeToString(currentColourScale.value?.range) : undefined, - style: colourScalesStore.currentScale?.style.name, + style: currentColourScale.value?.style.name, useDisplayUnits: settings.useDisplayUnits, } } else { diff --git a/src/components/wms/InformationPanel.vue b/src/components/wms/InformationPanel.vue index 32d2c26c..07edfe16 100644 --- a/src/components/wms/InformationPanel.vue +++ b/src/components/wms/InformationPanel.vue @@ -36,14 +36,11 @@ prepend-icon="mdi-clock-time-four-outline" > - + @@ -62,14 +59,12 @@
-