@eox/layercontrol 1.9.0 → 1.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/eox-layercontrol.js +3778 -47284
- package/dist/eox-layercontrol.umd.cjs +175 -1353
- package/package.json +2 -2
- package/src/components/layer-config.js +181 -14
- package/src/components/layer-tools.js +13 -0
- package/src/helpers/get-start-vals.js +56 -15
- package/src/helpers/index.js +6 -0
- package/src/helpers/update-geozarr-band.js +445 -0
- package/src/methods/layer/first-updated.js +11 -5
- package/src/methods/layer-config/apply-updated-styles.js +61 -24
- package/types/components/layer-config.d.ts +6 -6
- package/types/components/layer-config.d.ts.map +1 -1
- package/types/components/layer-tools.d.ts +1 -0
- package/types/components/layer-tools.d.ts.map +1 -1
- package/types/helpers/get-start-vals.d.ts.map +1 -1
- package/types/helpers/index.d.ts +1 -0
- package/types/helpers/update-geozarr-band.d.ts +49 -0
- package/types/helpers/update-geozarr-band.d.ts.map +1 -0
- package/types/methods/layer/first-updated.d.ts.map +1 -1
- package/types/methods/layer-config/apply-updated-styles.d.ts +1 -1
- package/types/methods/layer-config/apply-updated-styles.d.ts.map +1 -1
- package/dist/blosc-JROzDOnd.js +0 -692
- package/dist/chunk-INHXZS53-CsrPGdTf.js +0 -13
- package/dist/lz4-CUYSbVey.js +0 -626
- package/dist/zstd-YMzMcush.js +0 -583
|
@@ -0,0 +1,445 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Computes an appropriate step for number/range inputs based on the range difference.
|
|
3
|
+
* @param {number} min
|
|
4
|
+
* @param {number} max
|
|
5
|
+
* @returns {number}
|
|
6
|
+
*/
|
|
7
|
+
export function computeStep(min, max) {
|
|
8
|
+
const diff = Math.abs(max - min);
|
|
9
|
+
if (diff === 0) return 0.01;
|
|
10
|
+
if (diff <= 0.01) return 0.0001;
|
|
11
|
+
if (diff <= 0.1) return 0.001;
|
|
12
|
+
if (diff <= 1) return 0.01;
|
|
13
|
+
if (diff <= 10) return 0.1;
|
|
14
|
+
return 1;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Builds schema property definitions for min and max controls based on valid_range.
|
|
19
|
+
* If validRange is available, uses number inputs with native incrementing buttons (format: "number").
|
|
20
|
+
* If no validRange is available, uses range sliders (format: "range").
|
|
21
|
+
*
|
|
22
|
+
* @param {number} [min]
|
|
23
|
+
* @param {number} [max]
|
|
24
|
+
* @param {number[] | null | undefined} [validRange]
|
|
25
|
+
* @returns {{ minProp: Record<string, any>, maxProp: Record<string, any> }}
|
|
26
|
+
*/
|
|
27
|
+
export function buildMinMaxProperties(min, max, validRange) {
|
|
28
|
+
const hasValidRange =
|
|
29
|
+
Array.isArray(validRange) &&
|
|
30
|
+
validRange.length === 2 &&
|
|
31
|
+
typeof validRange[0] === "number" &&
|
|
32
|
+
typeof validRange[1] === "number" &&
|
|
33
|
+
!Number.isNaN(validRange[0]) &&
|
|
34
|
+
!Number.isNaN(validRange[1]);
|
|
35
|
+
|
|
36
|
+
if (hasValidRange) {
|
|
37
|
+
const rangeMin = validRange[0];
|
|
38
|
+
const rangeMax = validRange[1];
|
|
39
|
+
const step = computeStep(rangeMin, rangeMax);
|
|
40
|
+
const resolvedMin = min !== undefined ? min : rangeMin;
|
|
41
|
+
const resolvedMax = max !== undefined ? max : rangeMax;
|
|
42
|
+
return {
|
|
43
|
+
minProp: {
|
|
44
|
+
type: "number",
|
|
45
|
+
format: "number",
|
|
46
|
+
title: "Min Value",
|
|
47
|
+
default: resolvedMin,
|
|
48
|
+
minimum: rangeMin,
|
|
49
|
+
maximum: rangeMax,
|
|
50
|
+
step,
|
|
51
|
+
},
|
|
52
|
+
maxProp: {
|
|
53
|
+
type: "number",
|
|
54
|
+
format: "number",
|
|
55
|
+
title: "Max Value",
|
|
56
|
+
default: resolvedMax,
|
|
57
|
+
minimum: rangeMin,
|
|
58
|
+
maximum: rangeMax,
|
|
59
|
+
step,
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const resolvedMin = min !== undefined ? min : 0;
|
|
65
|
+
const resolvedMax = max !== undefined ? max : 1;
|
|
66
|
+
const sliderMin = typeof min === "number" ? Math.min(0, min) : 0;
|
|
67
|
+
const sliderMax =
|
|
68
|
+
typeof max === "number" && max > sliderMin ? max : sliderMin + 1;
|
|
69
|
+
const step = computeStep(sliderMin, sliderMax);
|
|
70
|
+
return {
|
|
71
|
+
minProp: {
|
|
72
|
+
type: "number",
|
|
73
|
+
format: "range",
|
|
74
|
+
title: "Min Value",
|
|
75
|
+
default: resolvedMin,
|
|
76
|
+
minimum: sliderMin,
|
|
77
|
+
maximum: sliderMax,
|
|
78
|
+
step,
|
|
79
|
+
},
|
|
80
|
+
maxProp: {
|
|
81
|
+
type: "number",
|
|
82
|
+
format: "range",
|
|
83
|
+
title: "Max Value",
|
|
84
|
+
default: resolvedMax,
|
|
85
|
+
minimum: sliderMin,
|
|
86
|
+
maximum: sliderMax,
|
|
87
|
+
step,
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Resolves the target min and max range for a given GeoZarr band.
|
|
94
|
+
* Uses 'valid_range' from layer's _geozarrVariables if available,
|
|
95
|
+
* otherwise falls back to defaults 0/1.
|
|
96
|
+
*
|
|
97
|
+
* @param {import("ol/layer/Base").default|any} layer
|
|
98
|
+
* @param {string} band
|
|
99
|
+
* @param {any} [_layerConfig]
|
|
100
|
+
* @returns {{ targetMin: number, targetMax: number }}
|
|
101
|
+
*/
|
|
102
|
+
export function getGeoZarrBandRange(layer, band, _layerConfig) {
|
|
103
|
+
const geozarrVars = layer?.get
|
|
104
|
+
? layer.get("_geozarrVariables")
|
|
105
|
+
: layer?._geozarrVariables;
|
|
106
|
+
const varMeta = geozarrVars?.[band];
|
|
107
|
+
const validRange = varMeta?.valid_range;
|
|
108
|
+
|
|
109
|
+
let targetMin = undefined;
|
|
110
|
+
let targetMax = undefined;
|
|
111
|
+
if (
|
|
112
|
+
Array.isArray(validRange) &&
|
|
113
|
+
validRange.length === 2 &&
|
|
114
|
+
typeof validRange[0] === "number" &&
|
|
115
|
+
typeof validRange[1] === "number" &&
|
|
116
|
+
!Number.isNaN(validRange[0]) &&
|
|
117
|
+
!Number.isNaN(validRange[1])
|
|
118
|
+
) {
|
|
119
|
+
targetMin = validRange[0];
|
|
120
|
+
targetMax = validRange[1];
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return {
|
|
124
|
+
targetMin: targetMin !== undefined ? targetMin : 0,
|
|
125
|
+
targetMax: targetMax !== undefined ? targetMax : 1,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Updates the active band on a GeoZarr layer, updating its source,
|
|
131
|
+
* updating bands and min/max style variables and layerConfig from valid_range (or fallback to defaults),
|
|
132
|
+
* and updating layerDatetime / timeControlValues.
|
|
133
|
+
*
|
|
134
|
+
* @param {import("ol/layer/Base").default|any} layer
|
|
135
|
+
* @param {string} newBand
|
|
136
|
+
* @returns {Promise<{ targetMin: number, targetMax: number } | undefined>}
|
|
137
|
+
*/
|
|
138
|
+
export async function updateGeoZarrBand(layer, newBand) {
|
|
139
|
+
if (!layer || !newBand) return undefined;
|
|
140
|
+
|
|
141
|
+
const source = /** @type {any} */ (
|
|
142
|
+
layer.getSource ? layer.getSource() : null
|
|
143
|
+
);
|
|
144
|
+
const sourceUrl =
|
|
145
|
+
layer.get("_geozarrSourceUrl") ||
|
|
146
|
+
layer.get("_jsonDefinition")?.source?.url ||
|
|
147
|
+
layer.get("source")?.url ||
|
|
148
|
+
layer.get("_geozarrRootUrl");
|
|
149
|
+
|
|
150
|
+
// 1. Re-create or update GeoZarr source with the newly selected band
|
|
151
|
+
let updatedSource = source;
|
|
152
|
+
if (source) {
|
|
153
|
+
if (typeof source.setBands === "function") {
|
|
154
|
+
source.setBands([newBand]);
|
|
155
|
+
} else if (sourceUrl && source.constructor) {
|
|
156
|
+
const GeoZarrClass = /** @type {any} */ (source.constructor);
|
|
157
|
+
const proj =
|
|
158
|
+
source.getProjection?.() ||
|
|
159
|
+
layer.get("_mapProjection") ||
|
|
160
|
+
layer.get("_jsonDefinition")?.source?.projection;
|
|
161
|
+
const newSource = new GeoZarrClass({
|
|
162
|
+
url: sourceUrl,
|
|
163
|
+
bands: [newBand],
|
|
164
|
+
crossOrigin: "anonymous",
|
|
165
|
+
...(proj ? { projection: proj } : {}),
|
|
166
|
+
});
|
|
167
|
+
layer.setSource(newSource);
|
|
168
|
+
updatedSource = newSource;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
if (typeof updatedSource?.ready === "function") {
|
|
173
|
+
try {
|
|
174
|
+
await updatedSource.ready();
|
|
175
|
+
} catch {
|
|
176
|
+
// ignore
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
layer.set("_lastVariable", newBand);
|
|
181
|
+
const existingBands =
|
|
182
|
+
layer.get("bands") ||
|
|
183
|
+
(Array.isArray(layer.get("_jsonDefinition")?.source?.bands)
|
|
184
|
+
? layer.get("_jsonDefinition")?.source?.bands
|
|
185
|
+
: null);
|
|
186
|
+
const resolvedBands =
|
|
187
|
+
Array.isArray(existingBands) && existingBands.length > 1
|
|
188
|
+
? existingBands
|
|
189
|
+
: [newBand];
|
|
190
|
+
if (layer.get("bands") !== undefined) {
|
|
191
|
+
layer.set("bands", resolvedBands);
|
|
192
|
+
}
|
|
193
|
+
if (layer.get("band") !== undefined) {
|
|
194
|
+
layer.set("band", newBand);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// 2. Resolve target min / max from valid_range or defaults
|
|
198
|
+
const layerConfig = layer.get("layerConfig");
|
|
199
|
+
const { targetMin, targetMax } = getGeoZarrBandRange(
|
|
200
|
+
layer,
|
|
201
|
+
newBand,
|
|
202
|
+
layerConfig,
|
|
203
|
+
);
|
|
204
|
+
const geozarrVars = layer?.get
|
|
205
|
+
? layer.get("_geozarrVariables")
|
|
206
|
+
: layer?._geozarrVariables;
|
|
207
|
+
const validRange = geozarrVars?.[newBand]?.valid_range;
|
|
208
|
+
const { minProp, maxProp } = buildMinMaxProperties(
|
|
209
|
+
targetMin,
|
|
210
|
+
targetMax,
|
|
211
|
+
validRange,
|
|
212
|
+
);
|
|
213
|
+
|
|
214
|
+
// 3. Update layerConfig (bands, min, max)
|
|
215
|
+
let updatedLayerConfig = layerConfig;
|
|
216
|
+
if (layerConfig) {
|
|
217
|
+
const isAutofill =
|
|
218
|
+
layerConfig?.autofill === true || layerConfig?.schema?.autofill === true;
|
|
219
|
+
let props = undefined;
|
|
220
|
+
if (layerConfig.schema?.properties) {
|
|
221
|
+
props = { ...layerConfig.schema.properties };
|
|
222
|
+
if (props.variable) {
|
|
223
|
+
props.variable = { ...props.variable, default: newBand };
|
|
224
|
+
}
|
|
225
|
+
if (props.band) {
|
|
226
|
+
props.band = { ...props.band, default: newBand };
|
|
227
|
+
}
|
|
228
|
+
if (props.bands) {
|
|
229
|
+
props.bands = {
|
|
230
|
+
...props.bands,
|
|
231
|
+
default:
|
|
232
|
+
props.bands.type === "array" ? resolvedBands : resolvedBands[0],
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// Check if multi-channel configuration (e.g. redMax, greenMax, blueMax)
|
|
237
|
+
const isMultiChannel =
|
|
238
|
+
!!props.redMax || !!props.greenMax || !!props.blueMax;
|
|
239
|
+
|
|
240
|
+
if (!isMultiChannel) {
|
|
241
|
+
if (props.min !== undefined || isAutofill) {
|
|
242
|
+
props.min = {
|
|
243
|
+
...(props.min || {}),
|
|
244
|
+
...minProp,
|
|
245
|
+
default: targetMin,
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
if (props.max !== undefined || isAutofill) {
|
|
249
|
+
props.max = {
|
|
250
|
+
...(props.max || {}),
|
|
251
|
+
...maxProp,
|
|
252
|
+
default: targetMax,
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
updatedLayerConfig = {
|
|
259
|
+
...layerConfig,
|
|
260
|
+
bands: resolvedBands,
|
|
261
|
+
band: newBand,
|
|
262
|
+
...(isAutofill || layerConfig.min !== undefined
|
|
263
|
+
? { min: targetMin }
|
|
264
|
+
: {}),
|
|
265
|
+
...(isAutofill || layerConfig.max !== undefined
|
|
266
|
+
? { max: targetMax }
|
|
267
|
+
: {}),
|
|
268
|
+
schema: props
|
|
269
|
+
? {
|
|
270
|
+
...layerConfig.schema,
|
|
271
|
+
properties: props,
|
|
272
|
+
}
|
|
273
|
+
: layerConfig.schema,
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
layer.set("layerConfig", updatedLayerConfig);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
// 4. Update style variables on layer
|
|
280
|
+
const isAutofill =
|
|
281
|
+
layerConfig?.autofill === true || layerConfig?.schema?.autofill === true;
|
|
282
|
+
const hasMinMaxStyle =
|
|
283
|
+
isAutofill ||
|
|
284
|
+
layer.styleVariables_?.min !== undefined ||
|
|
285
|
+
layer.styleVariables_?.max !== undefined ||
|
|
286
|
+
layer.style_?.variables?.min !== undefined ||
|
|
287
|
+
layer.style_?.variables?.max !== undefined ||
|
|
288
|
+
layer.get?.("style")?.variables?.min !== undefined ||
|
|
289
|
+
layer.get?.("style")?.variables?.max !== undefined ||
|
|
290
|
+
layerConfig?.schema?.properties?.min !== undefined ||
|
|
291
|
+
layerConfig?.schema?.properties?.max !== undefined;
|
|
292
|
+
|
|
293
|
+
if (hasMinMaxStyle) {
|
|
294
|
+
if (typeof layer.updateStyleVariables === "function") {
|
|
295
|
+
layer.updateStyleVariables({ min: targetMin, max: targetMax });
|
|
296
|
+
}
|
|
297
|
+
if (layer.styleVariables_) {
|
|
298
|
+
layer.styleVariables_.min = targetMin;
|
|
299
|
+
layer.styleVariables_.max = targetMax;
|
|
300
|
+
}
|
|
301
|
+
if (layer.style_?.variables) {
|
|
302
|
+
layer.style_.variables.min = targetMin;
|
|
303
|
+
layer.style_.variables.max = targetMax;
|
|
304
|
+
}
|
|
305
|
+
const styleObj = layer.get?.("style");
|
|
306
|
+
if (styleObj?.variables) {
|
|
307
|
+
styleObj.variables.min = targetMin;
|
|
308
|
+
styleObj.variables.max = targetMax;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
// 5. Update dimensions (time and non-temporal extra dimensions)
|
|
313
|
+
if (updatedSource && typeof updatedSource.getDimensions === "function") {
|
|
314
|
+
try {
|
|
315
|
+
const dimensions = await updatedSource.getDimensions();
|
|
316
|
+
if (dimensions) {
|
|
317
|
+
/** @type {Record<string, any>} */
|
|
318
|
+
const nonTemporalDims = {};
|
|
319
|
+
|
|
320
|
+
// Discover and inject non-temporal dimensions (depth, height, level, etc.)
|
|
321
|
+
for (const [dimName, dimMeta] of Object.entries(dimensions)) {
|
|
322
|
+
if (dimName === "time" || !dimMeta || dimMeta.size <= 0) continue;
|
|
323
|
+
nonTemporalDims[dimName] = dimMeta;
|
|
324
|
+
|
|
325
|
+
const currentCfg = layer.get("layerConfig") || updatedLayerConfig;
|
|
326
|
+
const isAutofill =
|
|
327
|
+
currentCfg?.autofill === true ||
|
|
328
|
+
currentCfg?.schema?.autofill === true;
|
|
329
|
+
if (
|
|
330
|
+
currentCfg?.schema?.properties &&
|
|
331
|
+
(currentCfg.schema.properties[dimName] !== undefined || isAutofill)
|
|
332
|
+
) {
|
|
333
|
+
const title =
|
|
334
|
+
dimMeta.attributes?.long_name ||
|
|
335
|
+
dimName.charAt(0).toUpperCase() + dimName.slice(1);
|
|
336
|
+
const units = dimMeta.attributes?.units;
|
|
337
|
+
const displayTitle = units ? `${title} (${units})` : title;
|
|
338
|
+
|
|
339
|
+
const currentProps = { ...currentCfg.schema.properties };
|
|
340
|
+
currentProps[dimName] = {
|
|
341
|
+
type: "integer",
|
|
342
|
+
title: displayTitle,
|
|
343
|
+
default: 0,
|
|
344
|
+
minimum: 0,
|
|
345
|
+
maximum: dimMeta.size - 1,
|
|
346
|
+
step: 1,
|
|
347
|
+
format: "range",
|
|
348
|
+
...(currentProps[dimName] || {}),
|
|
349
|
+
};
|
|
350
|
+
updatedLayerConfig = {
|
|
351
|
+
...currentCfg,
|
|
352
|
+
schema: {
|
|
353
|
+
...currentCfg.schema,
|
|
354
|
+
properties: currentProps,
|
|
355
|
+
},
|
|
356
|
+
};
|
|
357
|
+
layer.set("layerConfig", updatedLayerConfig);
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
if (typeof updatedSource.updateDimensions === "function") {
|
|
361
|
+
updatedSource.updateDimensions({ [dimName]: 0 });
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
layer.set("_geozarrDimensions", nonTemporalDims);
|
|
365
|
+
|
|
366
|
+
// Process time dimension
|
|
367
|
+
if (dimensions?.time && dimensions.time.size > 0) {
|
|
368
|
+
const timeDim = dimensions.time;
|
|
369
|
+
const { units } = timeDim.attributes || {};
|
|
370
|
+
let epoch = 0;
|
|
371
|
+
let multiplier = 1000;
|
|
372
|
+
if (units && typeof units === "string" && units.includes(" since ")) {
|
|
373
|
+
const parts = units.split(" since ");
|
|
374
|
+
let dateStr = parts[1].trim();
|
|
375
|
+
if (!dateStr.includes("T") && !dateStr.includes("Z")) {
|
|
376
|
+
dateStr = dateStr.replace(" ", "T") + "Z";
|
|
377
|
+
}
|
|
378
|
+
epoch = Date.parse(dateStr) || 0;
|
|
379
|
+
const unitType = parts[0].toLowerCase();
|
|
380
|
+
if (unitType.includes("day")) multiplier = 86400 * 1000;
|
|
381
|
+
else if (unitType.includes("nanosecond")) multiplier = 1e-6;
|
|
382
|
+
else if (unitType.includes("microsecond")) multiplier = 1e-3;
|
|
383
|
+
else if (unitType.includes("millisecond")) multiplier = 1;
|
|
384
|
+
else if (unitType.includes("second")) multiplier = 1000;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
const toDate = (value) => {
|
|
388
|
+
if (typeof value === "string") return new Date(value);
|
|
389
|
+
return new Date(epoch + Number(value) * multiplier);
|
|
390
|
+
};
|
|
391
|
+
|
|
392
|
+
const slices = await Promise.all(
|
|
393
|
+
[...Array(timeDim.size).keys()].map(async (index) => {
|
|
394
|
+
const rawVal =
|
|
395
|
+
typeof updatedSource.getValue === "function"
|
|
396
|
+
? await updatedSource.getValue("time", index)
|
|
397
|
+
: index;
|
|
398
|
+
return {
|
|
399
|
+
index,
|
|
400
|
+
date: toDate(rawVal),
|
|
401
|
+
};
|
|
402
|
+
}),
|
|
403
|
+
);
|
|
404
|
+
slices.sort((a, b) => a.date.getTime() - b.date.getTime());
|
|
405
|
+
|
|
406
|
+
const sliceMap = {};
|
|
407
|
+
const controlValues = slices.map((s) => {
|
|
408
|
+
const iso = s.date.toISOString();
|
|
409
|
+
sliceMap[iso] = s.index;
|
|
410
|
+
return iso;
|
|
411
|
+
});
|
|
412
|
+
|
|
413
|
+
const currentDatetime = layer.get("layerDatetime") || {};
|
|
414
|
+
const currentStep =
|
|
415
|
+
currentDatetime.currentStep &&
|
|
416
|
+
controlValues.includes(currentDatetime.currentStep)
|
|
417
|
+
? currentDatetime.currentStep
|
|
418
|
+
: controlValues[0];
|
|
419
|
+
|
|
420
|
+
layer.set("layerDatetime", {
|
|
421
|
+
showUTC: true,
|
|
422
|
+
slider: true,
|
|
423
|
+
navigation: true,
|
|
424
|
+
...currentDatetime,
|
|
425
|
+
controlValues,
|
|
426
|
+
sliceMap,
|
|
427
|
+
currentStep,
|
|
428
|
+
});
|
|
429
|
+
|
|
430
|
+
const timeControlValues = controlValues.map((date) => ({ date }));
|
|
431
|
+
layer.set("timeControlValues", timeControlValues);
|
|
432
|
+
|
|
433
|
+
const initialIndex = sliceMap[currentStep] ?? 0;
|
|
434
|
+
if (typeof updatedSource.updateDimensions === "function") {
|
|
435
|
+
updatedSource.updateDimensions({ time: initialIndex });
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
} catch (err) {
|
|
440
|
+
console.warn("Could not refresh GeoZarr dimensions for new band:", err);
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
return { targetMin, targetMax };
|
|
445
|
+
}
|
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
isLayerVisibleBasedOnZoomState,
|
|
3
3
|
isLayerZoomStateRequired,
|
|
4
4
|
} from "../../helpers";
|
|
5
|
-
|
|
5
|
+
|
|
6
6
|
/**
|
|
7
7
|
* Check and update layer zoom visibility at beginning
|
|
8
8
|
* and register "change:resolution" ones at the beginning if `showLayerZoomState` is present
|
|
@@ -61,11 +61,17 @@ const firstUpdatedMethod = (EOxLayerControlLayer) => {
|
|
|
61
61
|
.on("change:resolution", () => updateLayerZoomVisibility());
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
// Listen for dynamic property changes (e.g. GeoZarr layerDatetime, layerConfig, timeControlValues)
|
|
65
|
+
EOxLayerControlLayer.layer?.on?.("propertychange", (e) => {
|
|
66
|
+
const propEvent = /** @type {import("ol/Object").ObjectEvent} */ (e);
|
|
67
|
+
if (
|
|
68
|
+
propEvent.key === "layerDatetime" ||
|
|
69
|
+
propEvent.key === "layerConfig" ||
|
|
70
|
+
propEvent.key === "timeControlValues"
|
|
71
|
+
) {
|
|
66
72
|
EOxLayerControlLayer.requestUpdate();
|
|
67
|
-
}
|
|
68
|
-
}
|
|
73
|
+
}
|
|
74
|
+
});
|
|
69
75
|
};
|
|
70
76
|
|
|
71
77
|
export default firstUpdatedMethod;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import { getGeoZarrBandRange, updateGeoZarrBand } from "../../helpers";
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* @param {Record<string,number>} jsonformOutput
|
|
3
5
|
* @param { import("ol/layer/Layer").default} layer
|
|
4
6
|
* @param { import("../../components/layer-config").EOxLayerControlLayerConfig['layerConfig']} layerConfig
|
|
5
7
|
* */
|
|
6
|
-
export default function (jsonformOutput, layer, layerConfig) {
|
|
8
|
+
export default async function (jsonformOutput, layer, layerConfig) {
|
|
7
9
|
// check whether the layer is Vector or Tile
|
|
8
10
|
const isTile = "updateStyleVariables" in layer;
|
|
9
11
|
const isVector = "setStyle" in layer;
|
|
@@ -24,33 +26,68 @@ export default function (jsonformOutput, layer, layerConfig) {
|
|
|
24
26
|
|
|
25
27
|
// check if it supports updating the variables using ol first
|
|
26
28
|
if (isTile) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
layer
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
29
|
+
const selectedVar = jsonformOutput?.variable ?? jsonformOutput?.band;
|
|
30
|
+
if (selectedVar !== undefined) {
|
|
31
|
+
const lastVar = layer.get("_lastVariable");
|
|
32
|
+
if (selectedVar !== lastVar) {
|
|
33
|
+
const rangeResult = await updateGeoZarrBand(layer, String(selectedVar));
|
|
34
|
+
|
|
35
|
+
const targetMin =
|
|
36
|
+
rangeResult?.targetMin ??
|
|
37
|
+
getGeoZarrBandRange(layer, String(selectedVar), layerConfig)
|
|
38
|
+
.targetMin;
|
|
39
|
+
const targetMax =
|
|
40
|
+
rangeResult?.targetMax ??
|
|
41
|
+
getGeoZarrBandRange(layer, String(selectedVar), layerConfig)
|
|
42
|
+
.targetMax;
|
|
43
|
+
|
|
44
|
+
const isAutofill =
|
|
45
|
+
layerConfig?.autofill === true ||
|
|
46
|
+
layerConfig?.schema?.autofill === true;
|
|
47
|
+
const hasMinMaxStyle =
|
|
48
|
+
isAutofill ||
|
|
49
|
+
styles?.variables?.min !== undefined ||
|
|
50
|
+
styles?.variables?.max !== undefined ||
|
|
51
|
+
layerConfig?.schema?.properties?.min !== undefined ||
|
|
52
|
+
layerConfig?.schema?.properties?.max !== undefined;
|
|
53
|
+
|
|
54
|
+
if (hasMinMaxStyle) {
|
|
55
|
+
if (jsonformOutput) {
|
|
56
|
+
if ("min" in jsonformOutput) jsonformOutput.min = targetMin;
|
|
57
|
+
if ("max" in jsonformOutput) jsonformOutput.max = targetMax;
|
|
58
|
+
}
|
|
59
|
+
updatedValues.min = targetMin;
|
|
60
|
+
updatedValues.max = targetMax;
|
|
61
|
+
if (styles?.variables) {
|
|
62
|
+
styles.variables.min = targetMin;
|
|
63
|
+
styles.variables.max = targetMax;
|
|
64
|
+
}
|
|
47
65
|
}
|
|
48
66
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Check and update non-temporal GeoZarr dimensions if present
|
|
70
|
+
const geozarrDims = layer.get("_geozarrDimensions");
|
|
71
|
+
const source = /** @type {any} */ (
|
|
72
|
+
layer.getSource ? layer.getSource() : null
|
|
73
|
+
);
|
|
74
|
+
if (
|
|
75
|
+
source &&
|
|
76
|
+
typeof source.updateDimensions === "function" &&
|
|
77
|
+
geozarrDims
|
|
78
|
+
) {
|
|
79
|
+
/** @type {Record<string, number>} */
|
|
80
|
+
const dimUpdates = {};
|
|
81
|
+
for (const dimName of Object.keys(geozarrDims)) {
|
|
82
|
+
if (jsonformOutput[dimName] !== undefined) {
|
|
83
|
+
dimUpdates[dimName] = Number(jsonformOutput[dimName]);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
if (Object.keys(dimUpdates).length > 0) {
|
|
87
|
+
source.updateDimensions(dimUpdates);
|
|
52
88
|
}
|
|
53
89
|
}
|
|
90
|
+
|
|
54
91
|
/** @type {import('ol/layer/WebGLTile').default} */ (
|
|
55
92
|
layer
|
|
56
93
|
).updateStyleVariables(updatedValues);
|
|
@@ -62,8 +62,9 @@ export class EOxLayerControlLayerConfig extends LitElement {
|
|
|
62
62
|
* schema: Record<string,any>;
|
|
63
63
|
* element: string;
|
|
64
64
|
* type?: "tileUrl" | "style";
|
|
65
|
-
* style?: import("ol/layer/WebGLTile").Style
|
|
66
|
-
* legend?: layerConfigLegend | layerConfigLegend[]
|
|
65
|
+
* style?: import("ol/layer/WebGLTile").Style;
|
|
66
|
+
* legend?: layerConfigLegend | layerConfigLegend[];
|
|
67
|
+
* [key: string]: any;
|
|
67
68
|
* }}
|
|
68
69
|
*/
|
|
69
70
|
layerConfig: {
|
|
@@ -72,15 +73,14 @@ export class EOxLayerControlLayerConfig extends LitElement {
|
|
|
72
73
|
type?: "tileUrl" | "style";
|
|
73
74
|
style?: import("ol/layer/WebGLTile").Style;
|
|
74
75
|
legend?: layerConfigLegend | layerConfigLegend[];
|
|
76
|
+
[key: string]: any;
|
|
75
77
|
};
|
|
76
78
|
/**
|
|
77
79
|
* Throttle #handleDataChange() by 1000 milliseconds
|
|
78
80
|
*/
|
|
79
81
|
throttleDataChange: import("lodash").DebouncedFuncLeading<(e: {
|
|
80
|
-
detail:
|
|
81
|
-
|
|
82
|
-
};
|
|
83
|
-
}) => void>;
|
|
82
|
+
detail: Record<string, any>;
|
|
83
|
+
}) => Promise<void>>;
|
|
84
84
|
/**
|
|
85
85
|
* List of custom editor interfaces for layer config eox-jsonform
|
|
86
86
|
* Read more about the implementation of custom editor interfaces here:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"layer-config.d.ts","sourceRoot":"","sources":["../../src/components/layer-config.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"layer-config.d.ts","sourceRoot":"","sources":["../../src/components/layer-config.js"],"names":[],"mappings":"AAMA;;;;;;IAMI;AAEJ;;;;;;;GAOG;AACH;IAEE;;;;;;;;;;;;;;;;;;;;;MAOE;IA0BA;;;;;OAKG;IACH,OAHU,OAAO,UAAU,EAAE,KAAK,CAGjB;IAEjB;;;;OAIG;IACH,kBAAqB;IAErB;;;;OAIG;IACH,kBAAqB;IAErB;;;;;;;;;;;OAWG;IACH,aATU;QACN,MAAM,EAAE,MAAM,CAAC,MAAM,EAAC,GAAG,CAAC,CAAC;QAC3B,OAAO,EAAE,MAAM,CAAC;QAChB,IAAI,CAAC,EAAE,SAAS,GAAG,OAAO,CAAC;QAC3B,KAAK,CAAC,EAAE,OAAO,oBAAoB,EAAE,KAAK,CAAC;QAC3C,MAAM,CAAC,EAAE,iBAAiB,GAAG,iBAAiB,EAAE,CAAC;QACpD,CAAI,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;KAClB,CAEkB;IAEvB;;OAEG;IACH,8DAiHS;QAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;KAAE,oBAjHwB;IAEjE;;;;;;OAMG;IACH,8BAAgC;IAEhC;;;;OAIG;IACH,kBAFU,MAAM,CAAC,MAAM,EAAC,MAAM,EAAE,CAAC,CAEL;IA0N9B;;OAEG;IACH,+CA+DC;;CA8BF;gCAnaY,OAAO,CAAC,OAAO,gBAAgB,EAAE,YAAY,CAAC,GAAG;IACvD,OAAO,CAAC,EAAC;QAAC,GAAG,EAAE,MAAM,CAAC;QAAA,KAAK,EAAE,MAAM,GAAC,MAAM,GAAC,OAAO,CAAA;KAAC,CAAA;IACnD,gBAAgB,EAAE,MAAM,EAAE,CAAA;IAC1B,aAAa,CAAC,EAAE,MAAM,CAAA;CACtB;2BAX+B,KAAK"}
|
|
@@ -100,6 +100,7 @@ export class EOxLayerControlLayerTools extends LitElement {
|
|
|
100
100
|
* @type {Record<string,string[]>}
|
|
101
101
|
*/
|
|
102
102
|
colormapRegistry: Record<string, string[]>;
|
|
103
|
+
firstUpdated(): void;
|
|
103
104
|
updated(changedProperties: any): void;
|
|
104
105
|
_removeButton: (icon: any) => import("lit-html").HTMLTemplateResult;
|
|
105
106
|
_sortButton: (icon: any) => import("lit-html").HTMLTemplateResult;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"layer-tools.d.ts","sourceRoot":"","sources":["../../src/components/layer-tools.js"],"names":[],"mappings":"AAoBA;;;;;;GAMG;AACH;IAEE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAcE;IAKA;;;;;OAKG;IACH,OAHU,OAAO,UAAU,EAAE,KAAK,CAGjB;IAEjB;;;;OAIG;IACH,OAFU,KAAK,CAAC,MAAM,CAAC,CAER;IAEf;;;;OAIG;IACH,kBAAqB;IAErB;;;;OAIG;IACH,kBAAqB;IAErB;;;;OAIG;IACH,qBAAwB;IAExB;;;;OAIG;IACH,cAAiB;IAEjB;;;;OAIG;IACH,yBAA4B;IAW1B,kBAA4D;IAc9D;;;;;;OAMG;IACH,8BAAgC;IAEhC;;;;OAIG;IACH,kBAFU,MAAM,CAAC,MAAM,EAAC,MAAM,EAAE,CAAC,CAEL;IAU9B,sCAQC;IAmBD,gBAAiB,SAAI,2CAA8B;IAGnD,cAAe,SAAI,2CAA2C;IAE9D;;;;;;OAMG;IACH,UAAW,MAHA,MAGI,EAAE,SAAI,KAFR,OAAO,KAAK,EAAE,kBAAkB,CAEe;IAE5D,mBAAoB,UAAK,0CA8EvB;IAEF,+CA2DC;;CAgEF;
|
|
1
|
+
{"version":3,"file":"layer-tools.d.ts","sourceRoot":"","sources":["../../src/components/layer-tools.js"],"names":[],"mappings":"AAoBA;;;;;;GAMG;AACH;IAEE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAcE;IAKA;;;;;OAKG;IACH,OAHU,OAAO,UAAU,EAAE,KAAK,CAGjB;IAEjB;;;;OAIG;IACH,OAFU,KAAK,CAAC,MAAM,CAAC,CAER;IAEf;;;;OAIG;IACH,kBAAqB;IAErB;;;;OAIG;IACH,kBAAqB;IAErB;;;;OAIG;IACH,qBAAwB;IAExB;;;;OAIG;IACH,cAAiB;IAEjB;;;;OAIG;IACH,yBAA4B;IAW1B,kBAA4D;IAc9D;;;;;;OAMG;IACH,8BAAgC;IAEhC;;;;OAIG;IACH,kBAFU,MAAM,CAAC,MAAM,EAAC,MAAM,EAAE,CAAC,CAEL;IAU9B,qBAWC;IAED,sCAQC;IAmBD,gBAAiB,SAAI,2CAA8B;IAGnD,cAAe,SAAI,2CAA2C;IAE9D;;;;;;OAMG;IACH,UAAW,MAHA,MAGI,EAAE,SAAI,KAFR,OAAO,KAAK,EAAE,kBAAkB,CAEe;IAE5D,mBAAoB,UAAK,0CA8EvB;IAEF,+CA2DC;;CAgEF;2BAlZgC,KAAK"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-start-vals.d.ts","sourceRoot":"","sources":["../../src/helpers/get-start-vals.js"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,oCAJW,OAAO,UAAU,EAAE,KAAK,eACxB,OAAO,4BAA4B,EAAE,0BAA0B,CAAC,aAAa,CAAC,GAC5E,MAAM,GAAG,IAAI,
|
|
1
|
+
{"version":3,"file":"get-start-vals.d.ts","sourceRoot":"","sources":["../../src/helpers/get-start-vals.js"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,oCAJW,OAAO,UAAU,EAAE,KAAK,eACxB,OAAO,4BAA4B,EAAE,0BAA0B,CAAC,aAAa,CAAC,GAC5E,MAAM,GAAG,IAAI,CA6EzB;AA6CD;;;;;;;;GAQG;AACH,2CANW;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CAAC,gBACpB;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CAAC,eACpB;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CAAC,UACpB,OAAO,eAAe,EAAE,OAAO,GAAG,GAAG,GACnC,MAAM,CA4ElB"}
|
package/types/helpers/index.d.ts
CHANGED
|
@@ -15,4 +15,5 @@ export { hideLayersBasedOnProperties } from "./hide-layers-based-on-property";
|
|
|
15
15
|
export { handleDatetimeUpdate } from "./handle-datetime-update";
|
|
16
16
|
export { getNestedStartVals, getStartVals } from "./get-start-vals";
|
|
17
17
|
export { Button, _parseActions, _parseTools, removeButton, sortButton, getToolsIcon } from "./layer-tools";
|
|
18
|
+
export { getGeoZarrBandRange, updateGeoZarrBand, computeStep, buildMinMaxProperties } from "./update-geozarr-band";
|
|
18
19
|
//# sourceMappingURL=index.d.ts.map
|