@eox/layercontrol 1.8.3 → 1.9.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eox/layercontrol",
3
- "version": "1.8.3",
3
+ "version": "1.9.0",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -11,8 +11,8 @@
11
11
  "@eox/map": "*",
12
12
  "@types/lodash.throttle": "^4.1.9",
13
13
  "@types/sortablejs": "^1.15.1",
14
- "ol": "^10.9.0",
15
- "vite": "^8.2.1"
14
+ "ol": "^10.10.0",
15
+ "vite": "^8.2.2"
16
16
  },
17
17
  "engines": {
18
18
  "npm": ">=8.0.0",
@@ -18,7 +18,7 @@ export function getStartVals(layer, layerConfig) {
18
18
  (layer)["style_"]?.variables
19
19
  : layerConfig.style?.variables;
20
20
  if ((layerConfig.type === "style" || layerConfig.style) && styleVars) {
21
- nestedValues = styleVars;
21
+ nestedValues = { ...styleVars };
22
22
  } else if (/** @type {any} */ (layer.getSource())?.getParams?.()) {
23
23
  nestedValues = /** @type {any} */ (layer.getSource()).getParams();
24
24
  } else if (
@@ -52,6 +52,7 @@ export function getStartVals(layer, layerConfig) {
52
52
  Object.keys(fieldSchemas).length ? fieldSchemas : layerConfig.schema,
53
53
  nestedValues,
54
54
  layerConfig.schema,
55
+ layer,
55
56
  );
56
57
 
57
58
  return Object.keys(startVals).length ? startVals : null;
@@ -106,9 +107,15 @@ function collectFieldSchemas(
106
107
  * @param {{[key: string]: any}} schema - The schema object to traverse.
107
108
  * @param {{[key: string]: any}} nestedValues - values of nested properties to extract startVals.
108
109
  * @param {{[key: string]: any}} [rootSchema] - The root schema `$ref`s resolve against.
110
+ * @param {import("ol/layer/Base").default | any} [layer] - The layer object.
109
111
  * @returns {object} - Object containing the startVals.
110
112
  */
111
- export function getNestedStartVals(schema, nestedValues, rootSchema = schema) {
113
+ export function getNestedStartVals(
114
+ schema,
115
+ nestedValues,
116
+ rootSchema = schema,
117
+ layer = null,
118
+ ) {
112
119
  let startVals = {};
113
120
 
114
121
  for (const key in schema) {
@@ -120,12 +127,39 @@ export function getNestedStartVals(schema, nestedValues, rootSchema = schema) {
120
127
  : nestedValues[key];
121
128
  // keep the raw URL value instead of NaN (e.g. "auto" on a number field)
122
129
  startVals[key] = Number.isNaN(value) ? nestedValues[key] : value;
130
+ } else if (
131
+ type &&
132
+ type !== "object" &&
133
+ schema[key]?.default !== undefined
134
+ ) {
135
+ startVals[key] = schema[key].default;
136
+ } else if (
137
+ type &&
138
+ type !== "object" &&
139
+ Array.isArray(schema[key]?.enum) &&
140
+ schema[key].enum.length > 0
141
+ ) {
142
+ 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
+ }
123
156
  } else {
124
157
  // Recursively traverse nested properties
125
158
  const nestedStartVals = getNestedStartVals(
126
159
  collectFieldSchemas(schema[key], rootSchema),
127
160
  nestedValues,
128
161
  rootSchema,
162
+ layer,
129
163
  );
130
164
  if (Object.keys(nestedStartVals).length > 0) {
131
165
  startVals[key] = nestedStartVals;
@@ -4,6 +4,17 @@
4
4
  * @param {HTMLElement} element
5
5
  */
6
6
  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
+ }
7
18
  element.dispatchEvent(
8
19
  new CustomEvent("datetime:updated", { detail: evt.detail, bubbles: true }),
9
20
  );
@@ -2,7 +2,7 @@ import {
2
2
  isLayerVisibleBasedOnZoomState,
3
3
  isLayerZoomStateRequired,
4
4
  } from "../../helpers";
5
-
5
+ import { isGeoZarrLayer, setupGeoZarrLayer } from "@eox/map";
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
@@ -60,6 +60,12 @@ const firstUpdatedMethod = (EOxLayerControlLayer) => {
60
60
  .getView()
61
61
  .on("change:resolution", () => updateLayerZoomVisibility());
62
62
  }
63
+
64
+ if (isGeoZarrLayer(EOxLayerControlLayer.layer)) {
65
+ setupGeoZarrLayer(EOxLayerControlLayer.layer).then(() => {
66
+ EOxLayerControlLayer.requestUpdate();
67
+ });
68
+ }
63
69
  };
64
70
 
65
71
  export default firstUpdatedMethod;
@@ -11,26 +11,54 @@ export default function (jsonformOutput, layer, layerConfig) {
11
11
  const styles = isTile
12
12
  ? /** @type {import('ol/layer/WebGLTile').default} */ (layer)["style_"]
13
13
  : layerConfig.style;
14
- let styleVars = styles?.variables;
15
- if (styleVars) {
16
- const updatedValues = flattenObject(jsonformOutput);
14
+ const updatedValues = flattenObject(jsonformOutput);
15
+
16
+ if (styles) {
17
+ const styleVars = styles.variables || {};
17
18
  /** @type {Record<string,any>} */
18
19
  styles.variables = {
19
20
  ...styleVars,
20
21
  ...updatedValues,
21
22
  };
23
+ }
22
24
 
23
- // check if it supports updating the variables using ol first
24
- if (isTile) {
25
- /** @type {import('ol/layer/WebGLTile').default} */ (
26
- layer
27
- ).updateStyleVariables(updatedValues);
28
- } else if (isVector) {
29
- const updatedStyles = updateVectorLayerStyle(styles);
30
- /** @type {import('ol/layer/Vector').default} */ (layer).setStyle(
31
- updatedStyles,
25
+ // check if it supports updating the variables using ol first
26
+ if (isTile) {
27
+ if (jsonformOutput?.variable) {
28
+ const sourceUrl =
29
+ layer.get("_geozarrSourceUrl") ||
30
+ layer.get("_jsonDefinition")?.source?.url ||
31
+ layer.get("source")?.url ||
32
+ layer.get("_geozarrRootUrl");
33
+ const source = /** @type {any} */ (
34
+ layer.getSource ? layer.getSource() : null
32
35
  );
36
+ if (source) {
37
+ if (typeof source.setBands === "function") {
38
+ source.setBands([jsonformOutput.variable]);
39
+ } else if (sourceUrl && source.constructor) {
40
+ const GeoZarrClass = /** @type {any} */ (source.constructor);
41
+ const newSource = new GeoZarrClass({
42
+ url: sourceUrl,
43
+ bands: [jsonformOutput.variable],
44
+ crossOrigin: "anonymous",
45
+ });
46
+ layer.setSource(newSource);
47
+ }
48
+ }
49
+ const lastVar = layer.get("_lastVariable");
50
+ if (jsonformOutput.variable !== lastVar) {
51
+ layer.set("_lastVariable", jsonformOutput.variable);
52
+ }
33
53
  }
54
+ /** @type {import('ol/layer/WebGLTile').default} */ (
55
+ layer
56
+ ).updateStyleVariables(updatedValues);
57
+ } else if (isVector && styles) {
58
+ const updatedStyles = updateVectorLayerStyle(styles);
59
+ /** @type {import('ol/layer/Vector').default} */ (layer).setStyle(
60
+ updatedStyles,
61
+ );
34
62
  }
35
63
  }
36
64
 
@@ -12,6 +12,7 @@ export function getStartVals(layer: import("ol/layer").Layer, layerConfig: impor
12
12
  * @param {{[key: string]: any}} schema - The schema object to traverse.
13
13
  * @param {{[key: string]: any}} nestedValues - values of nested properties to extract startVals.
14
14
  * @param {{[key: string]: any}} [rootSchema] - The root schema `$ref`s resolve against.
15
+ * @param {import("ol/layer/Base").default | any} [layer] - The layer object.
15
16
  * @returns {object} - Object containing the startVals.
16
17
  */
17
18
  export function getNestedStartVals(schema: {
@@ -20,5 +21,5 @@ export function getNestedStartVals(schema: {
20
21
  [key: string]: any;
21
22
  }, rootSchema?: {
22
23
  [key: string]: any;
23
- }): object;
24
+ }, layer?: import("ol/layer/Base").default | any): object;
24
25
  //# sourceMappingURL=get-start-vals.d.ts.map
@@ -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,CAoDzB;AA6CD;;;;;;;GAOG;AACH,2CALW;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,GAClB,MAAM,CA2BlB"}
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,CAqDzB;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,CA2DlB"}
@@ -1 +1 @@
1
- {"version":3,"file":"handle-datetime-update.d.ts","sourceRoot":"","sources":["../../src/helpers/handle-datetime-update.js"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,0CAHW,WAAW,WACX,WAAW,QAMrB"}
1
+ {"version":3,"file":"handle-datetime-update.d.ts","sourceRoot":"","sources":["../../src/helpers/handle-datetime-update.js"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,0CAHW,WAAW,WACX,WAAW,QAiBrB"}
@@ -1 +1 @@
1
- {"version":3,"file":"first-updated.d.ts","sourceRoot":"","sources":["../../../src/methods/layer/first-updated.js"],"names":[],"mappings":";AAKA;;;;;GAKG;AACH,0DAFW,OAAO,wBAAwB,EAAE,oBAAoB,QAqD/D"}
1
+ {"version":3,"file":"first-updated.d.ts","sourceRoot":"","sources":["../../../src/methods/layer/first-updated.js"],"names":[],"mappings":";AAKA;;;;;GAKG;AACH,0DAFW,OAAO,wBAAwB,EAAE,oBAAoB,QA2D/D"}
@@ -1 +1 @@
1
- {"version":3,"file":"apply-updated-styles.d.ts","sourceRoot":"","sources":["../../../src/methods/layer-config/apply-updated-styles.js"],"names":[],"mappings":"AAAA;;;;KAIK;AACL,iDAJW,MAAM,CAAC,MAAM,EAAC,MAAM,CAAC,SACpB,OAAO,gBAAgB,EAAE,OAAO,eAChC,OAAO,+BAA+B,EAAE,0BAA0B,CAAC,aAAa,CAAC,QA+B5F;AA+BD;;;;;GAKG;AACH,+CAHW,MAAM,CAAC,MAAM,EAAC,GAAG,CAAC,uBA+B5B;AA5DM,mCAFI,MAAM,CAAC,MAAM,EAAC,GAAG,CAAC,uBA0B5B"}
1
+ {"version":3,"file":"apply-updated-styles.d.ts","sourceRoot":"","sources":["../../../src/methods/layer-config/apply-updated-styles.js"],"names":[],"mappings":"AAAA;;;;KAIK;AACL,iDAJW,MAAM,CAAC,MAAM,EAAC,MAAM,CAAC,SACpB,OAAO,gBAAgB,EAAE,OAAO,eAChC,OAAO,+BAA+B,EAAE,0BAA0B,CAAC,aAAa,CAAC,QA2D5F;AA+BD;;;;;GAKG;AACH,+CAHW,MAAM,CAAC,MAAM,EAAC,GAAG,CAAC,uBA+B5B;AA5DM,mCAFI,MAAM,CAAC,MAAM,EAAC,GAAG,CAAC,uBA0B5B"}