@eox/layercontrol 1.9.0 → 1.10.1

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.
Files changed (31) hide show
  1. package/dist/eox-layercontrol.js +3800 -47305
  2. package/dist/eox-layercontrol.umd.cjs +178 -1356
  3. package/package.json +2 -2
  4. package/src/components/layer-config.js +187 -14
  5. package/src/components/layer-datetime.js +13 -1
  6. package/src/components/layer-tools.js +13 -0
  7. package/src/helpers/get-start-vals.js +56 -15
  8. package/src/helpers/handle-datetime-update.js +13 -11
  9. package/src/helpers/index.js +6 -0
  10. package/src/helpers/layer-tools.js +1 -1
  11. package/src/helpers/update-geozarr-band.js +445 -0
  12. package/src/methods/layer/first-updated.js +11 -5
  13. package/src/methods/layer-config/apply-updated-styles.js +61 -24
  14. package/types/components/layer-config.d.ts +6 -6
  15. package/types/components/layer-config.d.ts.map +1 -1
  16. package/types/components/layer-datetime.d.ts.map +1 -1
  17. package/types/components/layer-tools.d.ts +1 -0
  18. package/types/components/layer-tools.d.ts.map +1 -1
  19. package/types/helpers/get-start-vals.d.ts.map +1 -1
  20. package/types/helpers/handle-datetime-update.d.ts +6 -0
  21. package/types/helpers/handle-datetime-update.d.ts.map +1 -1
  22. package/types/helpers/index.d.ts +1 -0
  23. package/types/helpers/update-geozarr-band.d.ts +49 -0
  24. package/types/helpers/update-geozarr-band.d.ts.map +1 -0
  25. package/types/methods/layer/first-updated.d.ts.map +1 -1
  26. package/types/methods/layer-config/apply-updated-styles.d.ts +1 -1
  27. package/types/methods/layer-config/apply-updated-styles.d.ts.map +1 -1
  28. package/dist/blosc-JROzDOnd.js +0 -692
  29. package/dist/chunk-INHXZS53-CsrPGdTf.js +0 -13
  30. package/dist/lz4-CUYSbVey.js +0 -626
  31. package/dist/zstd-YMzMcush.js +0 -583
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eox/layercontrol",
3
- "version": "1.9.0",
3
+ "version": "1.10.1",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -11,7 +11,7 @@
11
11
  "@eox/map": "*",
12
12
  "@types/lodash.throttle": "^4.1.9",
13
13
  "@types/sortablejs": "^1.15.1",
14
- "ol": "^10.10.0",
14
+ "ol": "^10.11.0",
15
15
  "vite": "^8.2.2"
16
16
  },
17
17
  "engines": {
@@ -1,6 +1,5 @@
1
1
  import { LitElement, html, css } from "lit";
2
- import { getLegendConfig } from "../helpers";
3
- import { getStartVals } from "../helpers";
2
+ import { getLegendConfig, getStartVals, getGeoZarrBandRange } from "../helpers";
4
3
  import { dataChangeMethod, applyUpdatedStyles } from "../methods/layer-config";
5
4
  import { when } from "lit/directives/when.js";
6
5
  import _throttle from "lodash.throttle";
@@ -85,8 +84,9 @@ export class EOxLayerControlLayerConfig extends LitElement {
85
84
  * schema: Record<string,any>;
86
85
  * element: string;
87
86
  * type?: "tileUrl" | "style";
88
- * style?: import("ol/layer/WebGLTile").Style
89
- * legend?: layerConfigLegend | layerConfigLegend[]
87
+ * style?: import("ol/layer/WebGLTile").Style;
88
+ * legend?: layerConfigLegend | layerConfigLegend[];
89
+ * [key: string]: any;
90
90
  * }}
91
91
  */
92
92
  this.layerConfig = null;
@@ -113,11 +113,88 @@ export class EOxLayerControlLayerConfig extends LitElement {
113
113
  this.colormapRegistry = null;
114
114
  }
115
115
 
116
+ connectedCallback() {
117
+ super.connectedCallback();
118
+ if (this.layer?.on) {
119
+ this.layer.on("propertychange", this.#layerPropertyChangeListener);
120
+ }
121
+ }
122
+
123
+ disconnectedCallback() {
124
+ super.disconnectedCallback();
125
+ if (this.layer?.un) {
126
+ this.layer.un("propertychange", this.#layerPropertyChangeListener);
127
+ }
128
+ }
129
+
130
+ #layerPropertyChangeListener = (e) => {
131
+ const propEvent = /** @type {import("ol/Object").ObjectEvent} */ (e);
132
+ if (propEvent.key === "layerConfig") {
133
+ this.layerConfig = this.layer.get("layerConfig");
134
+ const freshStartVals = getStartVals(this.layer, this.layerConfig) || {};
135
+ const schemaProps = this.layerConfig?.schema?.properties;
136
+ const isAutofill =
137
+ this.layerConfig?.autofill === true ||
138
+ this.layerConfig?.schema?.autofill === true;
139
+
140
+ if (
141
+ this.layerConfig?.min !== undefined &&
142
+ (isAutofill || schemaProps?.min !== undefined)
143
+ ) {
144
+ this.#data.min = this.layerConfig.min;
145
+ }
146
+ if (
147
+ this.layerConfig?.max !== undefined &&
148
+ (isAutofill || schemaProps?.max !== undefined)
149
+ ) {
150
+ this.#data.max = this.layerConfig.max;
151
+ }
152
+ const activeVar =
153
+ this.layer.get("_lastVariable") ||
154
+ this.layerConfig?.band ||
155
+ (Array.isArray(this.layerConfig?.bands)
156
+ ? this.layerConfig.bands[0]
157
+ : undefined);
158
+ if (
159
+ activeVar &&
160
+ (isAutofill ||
161
+ schemaProps?.variable !== undefined ||
162
+ schemaProps?.band !== undefined)
163
+ ) {
164
+ if (schemaProps?.band !== undefined) {
165
+ this.#data.band = activeVar;
166
+ } else {
167
+ this.#data.variable = activeVar;
168
+ }
169
+ }
170
+ this.#startVals = { ...this.#data, ...freshStartVals };
171
+ if (schemaProps && !isAutofill) {
172
+ const allowedKeys = new Set(Object.keys(schemaProps));
173
+ for (const k of Object.keys(this.#startVals)) {
174
+ if (!allowedKeys.has(k)) {
175
+ delete this.#startVals[k];
176
+ }
177
+ }
178
+ }
179
+ this.#data = { ...this.#startVals };
180
+ this.requestUpdate();
181
+ }
182
+ };
183
+
116
184
  /** Decide what type of throttling to do based on layerConfig type
117
185
  *
118
186
  * @param {import("lit").PropertyValues} changedProperties - The changed properties.
119
187
  */
120
188
  updated(changedProperties) {
189
+ if (changedProperties.has("layer")) {
190
+ const oldLayer = changedProperties.get("layer");
191
+ if (oldLayer?.un) {
192
+ oldLayer.un("propertychange", this.#layerPropertyChangeListener);
193
+ }
194
+ if (this.layer?.on) {
195
+ this.layer.on("propertychange", this.#layerPropertyChangeListener);
196
+ }
197
+ }
121
198
  if (changedProperties.has("layerConfig")) {
122
199
  const throttleTime =
123
200
  this.layerConfig?.type === "style" || this.layerConfig?.style
@@ -125,21 +202,51 @@ export class EOxLayerControlLayerConfig extends LitElement {
125
202
  : 1000;
126
203
 
127
204
  this.throttleDataChange = _throttle(this.#handleDataChange, throttleTime);
128
- this.requestUpdate();
129
205
  }
130
206
  }
131
207
  /**
132
208
  * Handles changes in eox-jsonform values.
133
209
  *
134
- * @param {{ detail: { value: string; }; }} e
210
+ * @param {{ detail: Record<string, any>; }} e
135
211
  */
136
- #handleDataChange(e) {
137
- this.#data = e.detail;
138
- if (this.layerConfig.type === "style" || this.layerConfig.style) {
212
+ async #handleDataChange(e) {
213
+ const prevVar =
214
+ this.#data?.variable ??
215
+ this.#data?.band ??
216
+ this.layer?.get?.("_lastVariable") ??
217
+ this.layerConfig?.band ??
218
+ (Array.isArray(this.layerConfig?.bands)
219
+ ? this.layerConfig.bands[0]
220
+ : undefined);
221
+ const currentVar = e.detail?.variable ?? e.detail?.band;
222
+ const isVarChange =
223
+ currentVar !== undefined &&
224
+ prevVar !== undefined &&
225
+ String(currentVar) !== String(prevVar);
226
+
227
+ if (isVarChange) {
228
+ const { targetMin, targetMax } = getGeoZarrBandRange(
229
+ this.layer,
230
+ String(currentVar),
231
+ this.layerConfig,
232
+ );
233
+ if (e.detail) {
234
+ if ("min" in e.detail || this.layerConfig?.min !== undefined) {
235
+ e.detail.min = targetMin;
236
+ }
237
+ if ("max" in e.detail || this.layerConfig?.max !== undefined) {
238
+ e.detail.max = targetMax;
239
+ }
240
+ }
241
+ }
242
+
243
+ this.#data = { ...e.detail };
244
+
245
+ if (this.layerConfig?.type === "style" || this.layerConfig?.style) {
139
246
  const supportStyleConfig =
140
247
  "setStyle" in this.layer || "updateStyleVariables" in this.layer;
141
248
  if (supportStyleConfig) {
142
- applyUpdatedStyles(this.#data, this.layer, this.layerConfig);
249
+ await applyUpdatedStyles(this.#data, this.layer, this.layerConfig);
143
250
  } else {
144
251
  console.error(
145
252
  `Layer type ${
@@ -154,11 +261,59 @@ export class EOxLayerControlLayerConfig extends LitElement {
154
261
  this,
155
262
  );
156
263
  }
264
+ if (isVarChange) {
265
+ this.layerConfig = this.layer?.get?.("layerConfig") || this.layerConfig;
266
+ const freshStartVals = getStartVals(this.layer, this.layerConfig) || {};
267
+ const schemaProps = this.layerConfig?.schema?.properties;
268
+ const isAutofill =
269
+ this.layerConfig?.autofill === true ||
270
+ this.layerConfig?.schema?.autofill === true;
271
+ this.#startVals = {
272
+ ...this.#data,
273
+ ...freshStartVals,
274
+ ...(currentVar &&
275
+ (isAutofill ||
276
+ schemaProps?.variable !== undefined ||
277
+ schemaProps?.band !== undefined)
278
+ ? schemaProps?.band !== undefined
279
+ ? { band: currentVar }
280
+ : { variable: currentVar }
281
+ : {}),
282
+ ...(this.#data.min !== undefined &&
283
+ (isAutofill || schemaProps?.min !== undefined)
284
+ ? { min: this.#data.min }
285
+ : {}),
286
+ ...(this.#data.max !== undefined &&
287
+ (isAutofill || schemaProps?.max !== undefined)
288
+ ? { max: this.#data.max }
289
+ : {}),
290
+ };
291
+ if (schemaProps && !isAutofill) {
292
+ const allowedKeys = new Set(Object.keys(schemaProps));
293
+ for (const k of Object.keys(this.#startVals)) {
294
+ if (!allowedKeys.has(k)) {
295
+ delete this.#startVals[k];
296
+ }
297
+ }
298
+ }
299
+ this.#data = { ...this.#startVals };
300
+
301
+ const jsonform = /** @type {any} */ (
302
+ this.renderRoot?.querySelector("eox-jsonform")
303
+ );
304
+ if (
305
+ jsonform?.editor &&
306
+ !jsonform.editor.destroyed &&
307
+ jsonform.editor.ready
308
+ ) {
309
+ jsonform.editor.setValue(this.#data);
310
+ }
311
+ }
157
312
  this.dispatchEvent(
158
313
  new CustomEvent("layerConfig:change", {
159
314
  bubbles: true,
160
315
  detail: {
161
- jsonformValue: e.detail,
316
+ jsonformValue: this.#data,
162
317
  layer: this.layer,
163
318
  },
164
319
  }),
@@ -178,10 +333,27 @@ export class EOxLayerControlLayerConfig extends LitElement {
178
333
  */
179
334
  render() {
180
335
  // Fetch initial values for the layer and its configuration
181
- this.#startVals = getStartVals(this.layer, this.layerConfig);
182
- if (Object.keys(this.#data).length !== 0) {
183
- this.#startVals = this.#data;
336
+ const freshStartVals = getStartVals(this.layer, this.layerConfig) || {};
337
+ const startVals = { ...freshStartVals, ...this.#data };
338
+ const schemaProps = this.layerConfig?.schema?.properties;
339
+ const isAutofill =
340
+ this.layerConfig?.autofill === true ||
341
+ this.layerConfig?.schema?.autofill === true;
342
+ if (schemaProps && !isAutofill) {
343
+ const allowedKeys = new Set(Object.keys(schemaProps));
344
+ for (const k of Object.keys(startVals)) {
345
+ if (!allowedKeys.has(k)) {
346
+ delete startVals[k];
347
+ }
348
+ }
349
+ }
350
+ // without start values, null lets eox-jsonform build the form from the schema defaults
351
+ const nextStartVals = Object.keys(startVals).length ? startVals : null;
352
+ // a new object on every render makes eox-jsonform reset the form to it
353
+ if (JSON.stringify(nextStartVals) !== JSON.stringify(this.#startVals)) {
354
+ this.#startVals = nextStartVals;
184
355
  }
356
+ this.#data = { ...this.#startVals };
185
357
  if (!customElements.get("eox-jsonform")) {
186
358
  console.error("Please import @eox/jsonform in order to use layerconfig");
187
359
  }
@@ -191,6 +363,7 @@ export class EOxLayerControlLayerConfig extends LitElement {
191
363
  disable_edit_json: true,
192
364
  disable_collapse: true,
193
365
  disable_properties: true,
366
+ no_additional_properties: true,
194
367
  };
195
368
  return html`
196
369
  <style>
@@ -1,5 +1,7 @@
1
1
  import { LitElement, html } from "lit";
2
2
  import { when } from "lit/directives/when.js";
3
+ import _debounce from "lodash.debounce";
4
+ import { updateLayerSlice } from "../helpers/handle-datetime-update";
3
5
 
4
6
  /**
5
7
  * `EOxLayerControlLayerDatetime` is a component that handles date time options for layers using eox-timecontrol.
@@ -67,6 +69,14 @@ export class EOxLayerControlLayerDatetime extends LitElement {
67
69
  return this.noShadow ? this : super.createRenderRoot();
68
70
  }
69
71
 
72
+ disconnectedCallback() {
73
+ // runs a pending slice update before removal
74
+ this.#updateSlice.flush();
75
+ super.disconnectedCallback();
76
+ }
77
+
78
+ #updateSlice = _debounce(updateLayerSlice, 300);
79
+
70
80
  /**
71
81
  * Handles timecontrol Stepchange &
72
82
  * triggers `datetime:updated` event on step change
@@ -103,6 +113,8 @@ export class EOxLayerControlLayerDatetime extends LitElement {
103
113
  }),
104
114
  );
105
115
 
116
+ this.#updateSlice(this.layer, currentStep);
117
+
106
118
  this.layerDatetime.currentStep = currentStep;
107
119
  this.requestUpdate();
108
120
  }
@@ -122,7 +134,7 @@ export class EOxLayerControlLayerDatetime extends LitElement {
122
134
  ${!this.unstyled && this.#styleEOX}
123
135
  </style>
124
136
  ${when(
125
- this.layerDatetime,
137
+ this.layerDatetime?.controlValues,
126
138
  () => html`
127
139
  <eox-timecontrol
128
140
  .initDate=${this.layerDatetime.currentStep
@@ -143,6 +143,19 @@ export class EOxLayerControlLayerTools extends LitElement {
143
143
  return this.noShadow ? this : super.createRenderRoot();
144
144
  }
145
145
 
146
+ firstUpdated() {
147
+ this.layer?.on?.("propertychange", (e) => {
148
+ const propEvent = /** @type {import("ol/Object").ObjectEvent} */ (e);
149
+ if (
150
+ propEvent.key === "layerConfig" ||
151
+ propEvent.key === "layerDatetime" ||
152
+ propEvent.key === "timeControlValues"
153
+ ) {
154
+ this.requestUpdate();
155
+ }
156
+ });
157
+ }
158
+
146
159
  updated(changedProperties) {
147
160
  if (
148
161
  this.toolsAutoExpand &&
@@ -14,8 +14,9 @@ export function getStartVals(layer, layerConfig) {
14
14
  // extract style variables from layer
15
15
  let styleVars =
16
16
  "updateStyleVariables" in layer
17
- ? /** @type {import("ol/layer/WebGLTile").default} */
18
- (layer)["style_"]?.variables
17
+ ? /** @type {any} */ (layer).styleVariables_ ||
18
+ /** @type {any} */ (layer)["style_"]?.variables ||
19
+ layer.get?.("style")?.variables
19
20
  : layerConfig.style?.variables;
20
21
  if ((layerConfig.type === "style" || layerConfig.style) && styleVars) {
21
22
  nestedValues = { ...styleVars };
@@ -46,6 +47,29 @@ export function getStartVals(layer, layerConfig) {
46
47
  }
47
48
  } else return null;
48
49
 
50
+ const cfg = /** @type {any} */ (layerConfig);
51
+ if (nestedValues.min === undefined && cfg.min !== undefined) {
52
+ nestedValues.min = cfg.min;
53
+ }
54
+ if (nestedValues.max === undefined && cfg.max !== undefined) {
55
+ nestedValues.max = cfg.max;
56
+ }
57
+ if (nestedValues.bands === undefined && cfg.bands !== undefined) {
58
+ nestedValues.bands = cfg.bands;
59
+ }
60
+ if (nestedValues.band === undefined && cfg.band !== undefined) {
61
+ nestedValues.band = cfg.band;
62
+ }
63
+ if (nestedValues.variable === undefined) {
64
+ nestedValues.variable =
65
+ cfg.variable ??
66
+ cfg.band ??
67
+ (Array.isArray(cfg.bands) && cfg.bands.length > 0
68
+ ? cfg.bands[0]
69
+ : undefined) ??
70
+ layer.get?.("_lastVariable");
71
+ }
72
+
49
73
  // fall back for schemas passed as a bare map of field definitions
50
74
  const fieldSchemas = collectFieldSchemas(layerConfig.schema);
51
75
  const startVals = getNestedStartVals(
@@ -127,6 +151,36 @@ export function getNestedStartVals(
127
151
  : nestedValues[key];
128
152
  // keep the raw URL value instead of NaN (e.g. "auto" on a number field)
129
153
  startVals[key] = Number.isNaN(value) ? nestedValues[key] : value;
154
+ } else if (key === "variable" && type && type !== "object" && layer) {
155
+ const source = /** @type {any} */ (
156
+ layer.getSource ? layer.getSource() : null
157
+ );
158
+ const bands =
159
+ layer.get?.("_lastVariable") ||
160
+ (typeof source?.getBands === "function" ? source.getBands() : null) ||
161
+ source?.bands_ ||
162
+ layer.get?.("_jsonDefinition")?.source?.bands ||
163
+ layer.get?.("source")?.bands;
164
+ const bandVal =
165
+ Array.isArray(bands) && bands.length > 0
166
+ ? bands[0]
167
+ : typeof bands === "string"
168
+ ? bands
169
+ : undefined;
170
+ if (
171
+ bandVal &&
172
+ (!Array.isArray(schema[key]?.enum) ||
173
+ schema[key].enum.includes(bandVal))
174
+ ) {
175
+ startVals[key] = bandVal;
176
+ } else if (schema[key]?.default !== undefined) {
177
+ startVals[key] = schema[key].default;
178
+ } else if (
179
+ Array.isArray(schema[key]?.enum) &&
180
+ schema[key].enum.length > 0
181
+ ) {
182
+ startVals[key] = schema[key].enum[0];
183
+ }
130
184
  } else if (
131
185
  type &&
132
186
  type !== "object" &&
@@ -140,19 +194,6 @@ export function getNestedStartVals(
140
194
  schema[key].enum.length > 0
141
195
  ) {
142
196
  startVals[key] = schema[key].enum[0];
143
- } else if (key === "variable" && type && type !== "object" && layer) {
144
- const source = /** @type {any} */ (
145
- layer.getSource ? layer.getSource() : null
146
- );
147
- const bands =
148
- (typeof source?.getBands === "function" ? source.getBands() : null) ||
149
- source?.bands_ ||
150
- layer.get?.("_lastVariable") ||
151
- layer.get?.("_jsonDefinition")?.source?.bands ||
152
- layer.get?.("source")?.bands;
153
- if (bands) {
154
- startVals[key] = Array.isArray(bands) ? bands[0] : bands;
155
- }
156
197
  } else {
157
198
  // Recursively traverse nested properties
158
199
  const nestedStartVals = getNestedStartVals(
@@ -1,20 +1,22 @@
1
+ /**
2
+ * Moves a sliced layer (e.g. GeoZarr) to the time slice mapped to the given datetime
3
+ * @param {import("ol/layer").Layer} layer
4
+ * @param {string} datetime
5
+ */
6
+ export function updateLayerSlice(layer, datetime) {
7
+ const sliceMap = layer.get("layerDatetime")?.sliceMap;
8
+ if (!sliceMap || !(datetime in sliceMap)) return;
9
+ const source = /** @type {any} */ (layer.getSource?.());
10
+ if (typeof source?.updateDimensions !== "function") return;
11
+ source.updateDimensions({ time: sliceMap[datetime] });
12
+ }
13
+
1
14
  /**
2
15
  * Dispatches datetime updates from layer datetime to the layercontrol
3
16
  * @param {CustomEvent} evt
4
17
  * @param {HTMLElement} element
5
18
  */
6
19
  export function handleDatetimeUpdate(evt, element) {
7
- const { datetime, layer } = evt.detail || {};
8
- if (layer && datetime) {
9
- const sliceMap = layer.get("layerDatetime")?.sliceMap;
10
- if (sliceMap && datetime in sliceMap) {
11
- const sliceIndex = sliceMap[datetime];
12
- const source = layer.getSource ? layer.getSource() : null;
13
- if (source && typeof source.updateDimensions === "function") {
14
- source.updateDimensions({ time: sliceIndex });
15
- }
16
- }
17
- }
18
20
  element.dispatchEvent(
19
21
  new CustomEvent("datetime:updated", { detail: evt.detail, bubbles: true }),
20
22
  );
@@ -22,3 +22,9 @@ export {
22
22
  } from "./layer-tools";
23
23
  export { hideLayersBasedOnProperties } from "./hide-layers-based-on-property";
24
24
  export { handleDatetimeUpdate } from "./handle-datetime-update";
25
+ export {
26
+ getGeoZarrBandRange,
27
+ updateGeoZarrBand,
28
+ computeStep,
29
+ buildMinMaxProperties,
30
+ } from "./update-geozarr-band";
@@ -28,7 +28,7 @@ export const _parseTools = (tools, layer) =>
28
28
  if (["remove", "sort"].includes(t)) pass = false;
29
29
  if (t === "info") pass = layer.get("description");
30
30
  if (t === "config") pass = layer.get("layerConfig");
31
- if (t === "datetime") pass = layer.get("layerDatetime");
31
+ if (t === "datetime") pass = layer.get("layerDatetime")?.controlValues;
32
32
  if (t === "legend") pass = layer.get("layerLegend");
33
33
  return pass;
34
34
  });