Skip to content

Commit a39c840

Browse files
committed
Scope current colour scales to spatialdisplay instance
1 parent cc589ff commit a39c840

File tree

5 files changed

+225
-165
lines changed

5 files changed

+225
-165
lines changed

src/components/spatialdisplay/SpatialDisplayComponent.vue

Lines changed: 34 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,18 @@
1313
:streamlineOptions="layerCapabilities?.animatedVectors"
1414
@doubleclick="onCoordinateClick"
1515
/>
16-
<div class="colourbar-container" v-if="colourScalesStore.currentScale">
16+
<div class="colourbar-container" v-if="currentColourScale">
1717
<ColourLegend
18-
v-if="!colourScalesStore.currentScale.useGradients"
19-
:colourMap="colourScalesStore.currentScale.colourMap"
20-
:title="colourScalesStore.currentScale.title"
18+
v-if="!currentColourScale.useGradients"
19+
:colourMap="currentColourScale.colourMap"
20+
:title="currentColourScale.title"
2121
/>
2222
<ColourBar
2323
v-else
24-
:colourMap="colourScalesStore.currentScale.colourMap"
25-
:title="colourScalesStore.currentScale.title"
26-
:useGradients="colourScalesStore.currentScale.useGradients"
27-
v-model:range="colourScalesStore.currentScale.range"
24+
:colourMap="currentColourScale.colourMap"
25+
:title="currentColourScale.title"
26+
:useGradients="currentColourScale.useGradients"
27+
v-model:range="currentColourScale.range"
2828
/>
2929
</div>
3030
<SelectedCoordinateLayer
@@ -80,6 +80,8 @@
8080
:canUseStreamlines="canUseStreamlines"
8181
v-model:layer-kind="layerKind"
8282
v-model:show-layer="showLayer"
83+
:currentColourScaleIds="currentColourScaleIds"
84+
@update:current-colour-scale="currentColourScale = $event"
8385
/>
8486
<LocationsSearchControl
8587
v-if="showLocationSearchControl"
@@ -116,7 +118,7 @@
116118
<template #below-track>
117119
<DateTimeSliderValues
118120
:values="maxValuesTimeSeries ?? []"
119-
:colour-scale="colourScalesStore.currentScale ?? null"
121+
:colour-scale="currentColourScale ?? null"
120122
height="6px"
121123
class="mb-1"
122124
style="margin-top: -7px"
@@ -130,12 +132,8 @@ import DateTimeSliderValues from '@/components/general/DateTimeSliderValues.vue'
130132
import MapComponent from '@/components/map/MapComponent.vue'
131133
import AnimatedStreamlineRasterLayer from '@/components/wms/AnimatedStreamlineRasterLayer.vue'
132134
133-
import { ref, computed, onBeforeMount, reactive, watch, watchEffect } from 'vue'
134-
import {
135-
convertBoundingBoxToLngLatBounds,
136-
fetchWmsLegend,
137-
useWmsLegend,
138-
} from '@/services/useWms'
135+
import { ref, computed, onBeforeMount, watch, watchEffect } from 'vue'
136+
import { convertBoundingBoxToLngLatBounds } from '@/services/useWms'
139137
import ColourBar from '@/components/wms/ColourBar.vue'
140138
import AnimatedRasterLayer, {
141139
AnimatedRasterLayerOptions,
@@ -161,16 +159,11 @@ import {
161159
import { configManager } from '@/services/application-config'
162160
import type { Layer, Style } from '@deltares/fews-wms-requests'
163161
import { LayerKind } from '@/lib/streamlines'
164-
import { useColourScalesStore } from '@/stores/colourScales'
162+
import { ColourScale, useColourScalesStore } from '@/stores/colourScales'
165163
import { useDisplay } from 'vuetify'
166164
import { useFilterLocations } from '@/services/useFilterLocations'
167165
import ColourLegend from '@/components/wms/ColourLegend.vue'
168-
import {
169-
getLegendTitle,
170-
legendToRange,
171-
rangeToString,
172-
styleToId,
173-
} from '@/lib/legend'
166+
import { rangeToString, styleToId } from '@/lib/legend'
174167
import { useWorkflowsStore } from '@/stores/workflows'
175168
import { TimeSeriesData } from '@/lib/timeseries/types/SeriesData'
176169
import CoordinateSelectorLayer from '@/components/wms/CoordinateSelectorLayer.vue'
@@ -235,7 +228,6 @@ const forecastTime = ref<Date>()
235228
const isLoading = ref(false)
236229
let debouncedSetLayerOptions!: () => void
237230
238-
const legendLayerName = ref(props.layerName)
239231
const legendLayerStyles = ref<Style[]>()
240232
const userSettings = useUserSettingsStore()
241233
@@ -246,6 +238,9 @@ const layerKind = ref(LayerKind.Static)
246238
247239
const colourScalesStore = useColourScalesStore()
248240
const componentSettingsStore = useComponentSettingsStore()
241+
const currentColourScale = ref<ColourScale>()
242+
const currentColourScaleIds = ref<string[]>([])
243+
249244
const workflowsStore = useWorkflowsStore()
250245
251246
const showLocationsLayer = ref<boolean>(true)
@@ -263,73 +258,22 @@ watchEffect(() => {
263258
264259
watch(
265260
legendLayerStyles,
266-
() => {
267-
const styles = legendLayerStyles.value
261+
(styles) => {
268262
if (styles === undefined) {
269-
colourScalesStore.currentIds = []
270-
colourScalesStore.currentIndex = 0
263+
currentColourScaleIds.value = []
271264
return
272265
}
273266
274-
legendLayerName.value = props.layerName
275-
colourScalesStore.currentIds = styles.map(styleToId)
276-
colourScalesStore.currentIndex = 0
277-
278-
styles.forEach(async (style) => {
279-
const styleId = styleToId(style)
280-
281-
if (!(styleId in colourScalesStore.scales)) {
282-
const initialLegendGraphic = await fetchWmsLegend(
283-
baseUrl,
284-
legendLayerName.value,
285-
userSettings.useDisplayUnits,
286-
undefined,
287-
style,
288-
)
289-
290-
const legend = initialLegendGraphic.legend
291-
const newColourScale = reactive({
292-
title: getLegendTitle(
293-
props.layerCapabilities?.title ?? '',
294-
initialLegendGraphic,
295-
),
296-
style: style,
297-
colourMap: legend,
298-
range: legendToRange(legend),
299-
initialRange: legendToRange(legend),
300-
useGradients: !legend.some((entry) => entry.colorSmoothing === false),
301-
})
302-
colourScalesStore.scales[styleId] = newColourScale
303-
304-
const range = computed(() => {
305-
const newRange = rangeToString(newColourScale.range)
306-
const initialRange = rangeToString(newColourScale.initialRange)
307-
308-
return newRange !== initialRange ? newRange : undefined
309-
})
310-
311-
const newLegendGraphic = useWmsLegend(
312-
baseUrl,
313-
legendLayerName,
314-
() => userSettings.useDisplayUnits,
315-
range,
316-
style,
317-
() =>
318-
props.layerCapabilities
319-
? (props.layerCapabilities.styles ?? [style])
320-
: undefined,
321-
)
322-
323-
watch(newLegendGraphic, () => {
324-
if (newLegendGraphic.value?.legend === undefined) return
325-
colourScalesStore.scales[styleId].title = getLegendTitle(
326-
props.layerCapabilities?.title ?? '',
327-
newLegendGraphic.value,
328-
)
329-
colourScalesStore.scales[styleId].colourMap =
330-
newLegendGraphic.value.legend
331-
})
332-
}
267+
currentColourScaleIds.value = styles.map(styleToId)
268+
269+
styles.forEach((style) => {
270+
colourScalesStore.addScale(
271+
style,
272+
props.layerName,
273+
() => props.layerCapabilities?.title,
274+
() => userSettings.useDisplayUnits,
275+
() => props.layerCapabilities?.styles ?? [],
276+
)
333277
})
334278
},
335279
{ immediate: true },
@@ -383,7 +327,6 @@ watch(
383327
const _forecastTime = layer?.keywordList?.[0].forecastTime
384328
forecastTime.value = _forecastTime ? new Date(_forecastTime) : undefined
385329
386-
legendLayerName.value = props.layerName
387330
legendLayerStyles.value = props.layerCapabilities?.styles
388331
if (legendLayerStyles.value === undefined && props.layerName) {
389332
legendLayerStyles.value = [
@@ -414,7 +357,7 @@ watch(currentElevation, () => {
414357
})
415358
416359
watch(
417-
[() => colourScalesStore.currentScale?.range, () => userSettings.useDisplayUnits],
360+
[() => currentColourScale.value?.range, () => userSettings.useDisplayUnits],
418361
() => {
419362
setLayerOptions()
420363
},
@@ -462,10 +405,10 @@ function setLayerOptions(): void {
462405
? convertBoundingBoxToLngLatBounds(props.layerCapabilities.boundingBox)
463406
: undefined,
464407
elevation: currentElevation.value,
465-
colorScaleRange: colourScalesStore.currentScale?.range
466-
? rangeToString(colourScalesStore.currentScale?.range)
408+
colorScaleRange: currentColourScale.value?.range
409+
? rangeToString(currentColourScale.value?.range)
467410
: undefined,
468-
style: colourScalesStore.currentScale?.style.name,
411+
style: currentColourScale.value?.style.name,
469412
useDisplayUnits: userSettings.useDisplayUnits,
470413
}
471414
} else {

src/components/wms/InformationPanel.vue

Lines changed: 54 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,11 @@
3636
prepend-icon="mdi-clock-time-four-outline"
3737
>
3838
</v-list-item>
39-
<v-list-item
40-
prepend-icon="mdi-palette"
41-
v-if="colourScalesStore.currentScales"
42-
>
39+
<v-list-item prepend-icon="mdi-palette" v-if="currentScales">
4340
<v-list-item
44-
v-for="(item, index) of colourScalesStore.currentScales"
41+
v-for="(item, index) of currentScales"
4542
:key="index"
46-
@click="colourScalesStore.currentIndex = index"
43+
@click="currentColourScaleIndex = index"
4744
class="px-0"
4845
>
4946
<v-list-item-title>
@@ -62,14 +59,12 @@
6259
<ColourLegendTable :colourMap="item.colourMap" />
6360
</template>
6461
</div>
65-
<template #append v-if="index === colourScalesStore.currentIndex">
62+
<template #append v-if="index === currentColourScaleIndex">
6663
<v-icon>mdi-check</v-icon>
6764
</template>
6865
</v-list-item>
6966
</v-list-item>
70-
<v-list-item
71-
v-if="colourScalesStore.currentScale?.useGradients !== false"
72-
>
67+
<v-list-item v-if="currentScale?.useGradients !== false">
7368
<template v-slot:prepend>
7469
<div class="mx-7"></div>
7570
</template>
@@ -81,8 +76,8 @@
8176
variant="plain"
8277
hide-details
8378
density="comfortable"
84-
@keydown.enter.stop="changecolorScaleRange"
85-
@blur="changecolorScaleRange"
79+
@keydown.enter.stop="changeCurrentColourScaleRange"
80+
@blur="changeCurrentColourScaleRange"
8681
:rules="[rules.required, rules.smallerThanMax]"
8782
></v-text-field>
8883
</v-col>
@@ -93,18 +88,18 @@
9388
variant="plain"
9489
hide-details
9590
density="comfortable"
96-
@keydown.enter.stop="changecolorScaleRange"
97-
@blur="changecolorScaleRange"
91+
@keydown.enter.stop="changeCurrentColourScaleRange"
92+
@blur="changeCurrentColourScaleRange"
9893
:rules="[rules.required, rules.biggerThanMin]"
9994
></v-text-field>
10095
</v-col>
10196
<v-col cols="2" class="d-flex align-center justify-center">
10297
<v-btn
103-
v-if="!colourScalesStore.currentScaleIsInitialRange"
98+
v-if="!currentScaleIsInitialRange"
10499
icon="mdi-restore"
105100
variant="flat"
106101
density="compact"
107-
@click="colourScalesStore.resetCurrentScaleRange"
102+
@click="resetCurrentScaleRange"
108103
/>
109104
</v-col>
110105
</v-row>
@@ -142,9 +137,10 @@ import { ref } from 'vue'
142137
import { LayerKind } from '@/lib/streamlines'
143138
import ColourStrip from '@/components/wms/ColourStrip.vue'
144139
import { watch } from 'vue'
145-
import { useColourScalesStore } from '@/stores/colourScales'
140+
import { useColourScalesStore, type Range } from '@/stores/colourScales'
146141
import ColourLegendTable from './ColourLegendTable.vue'
147142
import ControlChip from '@/components/wms/ControlChip.vue'
143+
import { useColourScales } from '@/services/useColourScales'
148144
149145
interface Props {
150146
layerTitle?: string
@@ -155,36 +151,64 @@ interface Props {
155151
firstValueTime?: Date
156152
lastValueTime?: Date
157153
canUseStreamlines?: boolean
154+
currentColourScaleIds: string[]
158155
}
159156
160-
const colourScalesStore = useColourScalesStore()
161-
162157
const props = withDefaults(defineProps<Props>(), {
163158
layerTitle: '',
164159
completelyMissing: false,
165160
})
166161
167-
const emit = defineEmits(['style-click', 'update:layerKind'])
162+
const emit = defineEmits([
163+
'style-click',
164+
'update:layerKind',
165+
'update:current-colour-scale',
166+
])
167+
168+
const currentColourScaleIndex = ref(0)
169+
watch(
170+
() => props.currentColourScaleIds,
171+
() => {
172+
currentColourScaleIndex.value = 0
173+
},
174+
)
175+
176+
const colourScalesStore = useColourScalesStore()
177+
const {
178+
currentScale,
179+
currentScales,
180+
currentScaleIsInitialRange,
181+
resetCurrentScaleRange,
182+
} = useColourScales(
183+
currentColourScaleIndex,
184+
() => props.currentColourScaleIds,
185+
() => colourScalesStore.scales,
186+
)
168187
169-
const mutableColorScaleRange = ref(
170-
colourScalesStore.currentScale?.range
171-
? { ...colourScalesStore.currentScale?.range }
172-
: undefined,
188+
watch(
189+
currentScale,
190+
() => {
191+
emit('update:current-colour-scale', currentScale.value)
192+
},
193+
{ immediate: true },
173194
)
174195
196+
const mutableColorScaleRange = ref<Range>()
175197
watch(
176-
() => colourScalesStore.currentScale?.range,
198+
() => currentScale.value?.range,
177199
() => {
178-
mutableColorScaleRange.value = colourScalesStore.currentScale?.range
179-
? { ...colourScalesStore.currentScale?.range }
200+
mutableColorScaleRange.value = currentScale.value?.range
201+
? { ...currentScale.value?.range }
180202
: undefined
181203
},
182-
{ deep: true },
204+
{ immediate: true, deep: true },
183205
)
184206
185-
const changecolorScaleRange = () => {
207+
const changeCurrentColourScaleRange = () => {
186208
if (mutableColorScaleRange.value === undefined) return
187-
colourScalesStore.setCurrentScaleRange(mutableColorScaleRange.value)
209+
if (currentScale.value === undefined) return
210+
211+
currentScale.value.range = mutableColorScaleRange.value
188212
}
189213
190214
const showLayer = defineModel<boolean>('showLayer')

0 commit comments

Comments
 (0)