13
13
:streamlineOptions =" layerCapabilities?.animatedVectors"
14
14
@doubleclick =" onCoordinateClick"
15
15
/>
16
- <div class =" colourbar-container" v-if =" colourScalesStore.currentScale " >
16
+ <div class =" colourbar-container" v-if =" currentColourScale " >
17
17
<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"
21
21
/>
22
22
<ColourBar
23
23
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"
28
28
/>
29
29
</div >
30
30
<SelectedCoordinateLayer
80
80
:canUseStreamlines =" canUseStreamlines"
81
81
v-model:layer-kind =" layerKind"
82
82
v-model:show-layer =" showLayer"
83
+ :currentColourScaleIds =" currentColourScaleIds"
84
+ @update:current-colour-scale =" currentColourScale = $event"
83
85
/>
84
86
<LocationsSearchControl
85
87
v-if =" showLocationSearchControl"
116
118
<template #below-track >
117
119
<DateTimeSliderValues
118
120
:values =" maxValuesTimeSeries ?? []"
119
- :colour-scale =" colourScalesStore.currentScale ?? null"
121
+ :colour-scale =" currentColourScale ?? null"
120
122
height =" 6px"
121
123
class =" mb-1"
122
124
style =" margin-top : -7px "
@@ -130,12 +132,8 @@ import DateTimeSliderValues from '@/components/general/DateTimeSliderValues.vue'
130
132
import MapComponent from ' @/components/map/MapComponent.vue'
131
133
import AnimatedStreamlineRasterLayer from ' @/components/wms/AnimatedStreamlineRasterLayer.vue'
132
134
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'
139
137
import ColourBar from ' @/components/wms/ColourBar.vue'
140
138
import AnimatedRasterLayer , {
141
139
AnimatedRasterLayerOptions ,
@@ -161,16 +159,11 @@ import {
161
159
import { configManager } from ' @/services/application-config'
162
160
import type { Layer , Style } from ' @deltares/fews-wms-requests'
163
161
import { LayerKind } from ' @/lib/streamlines'
164
- import { useColourScalesStore } from ' @/stores/colourScales'
162
+ import { ColourScale , useColourScalesStore } from ' @/stores/colourScales'
165
163
import { useDisplay } from ' vuetify'
166
164
import { useFilterLocations } from ' @/services/useFilterLocations'
167
165
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'
174
167
import { useWorkflowsStore } from ' @/stores/workflows'
175
168
import { TimeSeriesData } from ' @/lib/timeseries/types/SeriesData'
176
169
import CoordinateSelectorLayer from ' @/components/wms/CoordinateSelectorLayer.vue'
@@ -235,7 +228,6 @@ const forecastTime = ref<Date>()
235
228
const isLoading = ref (false )
236
229
let debouncedSetLayerOptions! : () => void
237
230
238
- const legendLayerName = ref (props .layerName )
239
231
const legendLayerStyles = ref <Style []>()
240
232
const userSettings = useUserSettingsStore ()
241
233
@@ -246,6 +238,9 @@ const layerKind = ref(LayerKind.Static)
246
238
247
239
const colourScalesStore = useColourScalesStore ()
248
240
const componentSettingsStore = useComponentSettingsStore ()
241
+ const currentColourScale = ref <ColourScale >()
242
+ const currentColourScaleIds = ref <string []>([])
243
+
249
244
const workflowsStore = useWorkflowsStore ()
250
245
251
246
const showLocationsLayer = ref <boolean >(true )
@@ -263,73 +258,22 @@ watchEffect(() => {
263
258
264
259
watch (
265
260
legendLayerStyles ,
266
- () => {
267
- const styles = legendLayerStyles .value
261
+ (styles ) => {
268
262
if (styles === undefined ) {
269
- colourScalesStore .currentIds = []
270
- colourScalesStore .currentIndex = 0
263
+ currentColourScaleIds .value = []
271
264
return
272
265
}
273
266
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
+ )
333
277
})
334
278
},
335
279
{ immediate: true },
@@ -383,7 +327,6 @@ watch(
383
327
const _forecastTime = layer ?.keywordList ?.[0 ].forecastTime
384
328
forecastTime .value = _forecastTime ? new Date (_forecastTime ) : undefined
385
329
386
- legendLayerName .value = props .layerName
387
330
legendLayerStyles .value = props .layerCapabilities ?.styles
388
331
if (legendLayerStyles .value === undefined && props .layerName ) {
389
332
legendLayerStyles .value = [
@@ -414,7 +357,7 @@ watch(currentElevation, () => {
414
357
})
415
358
416
359
watch (
417
- [() => colourScalesStore . currentScale ?.range , () => userSettings .useDisplayUnits ],
360
+ [() => currentColourScale . value ?.range , () => userSettings .useDisplayUnits ],
418
361
() => {
419
362
setLayerOptions ()
420
363
},
@@ -462,10 +405,10 @@ function setLayerOptions(): void {
462
405
? convertBoundingBoxToLngLatBounds (props .layerCapabilities .boundingBox )
463
406
: undefined ,
464
407
elevation: currentElevation .value ,
465
- colorScaleRange: colourScalesStore . currentScale ?.range
466
- ? rangeToString (colourScalesStore . currentScale ?.range )
408
+ colorScaleRange: currentColourScale . value ?.range
409
+ ? rangeToString (currentColourScale . value ?.range )
467
410
: undefined ,
468
- style: colourScalesStore . currentScale ?.style .name ,
411
+ style: currentColourScale . value ?.style .name ,
469
412
useDisplayUnits: userSettings .useDisplayUnits ,
470
413
}
471
414
} else {
0 commit comments