@eox/layercontrol 1.8.0 → 1.8.2
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 +418 -407
- package/dist/eox-layercontrol.umd.cjs +40 -40
- package/package.json +2 -2
- package/src/helpers/get-start-vals.js +100 -31
- package/src/methods/layer-config/data-change.js +17 -27
- package/types/helpers/get-start-vals.d.ts +11 -8
- package/types/helpers/get-start-vals.d.ts.map +1 -1
- package/types/methods/layer-config/data-change.d.ts.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eox/layercontrol",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"@types/lodash.throttle": "^4.1.9",
|
|
13
13
|
"@types/sortablejs": "^1.15.1",
|
|
14
14
|
"ol": "^10.9.0",
|
|
15
|
-
"vite": "^8.0
|
|
15
|
+
"vite": "^8.1.0"
|
|
16
16
|
},
|
|
17
17
|
"engines": {
|
|
18
18
|
"npm": ">=8.0.0",
|
|
@@ -1,33 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Recursively traverses the schema object to extract startVals based on values of nested properties.
|
|
3
|
-
*
|
|
4
|
-
* @param {{[key: string]: any}} schema - The schema object to traverse.
|
|
5
|
-
* @param {{[key: string]: any}} nestedValues - values of nested properties to extract startVals.
|
|
6
|
-
* @returns {object} - Object containing the startVals.
|
|
7
|
-
*/
|
|
8
|
-
export function getNestedStartVals(schema, nestedValues) {
|
|
9
|
-
let startVals = {};
|
|
10
|
-
|
|
11
|
-
for (const key in schema) {
|
|
12
|
-
const type = schema[key].type;
|
|
13
|
-
// Extract startVal based on type
|
|
14
|
-
if (type && type !== "object" && nestedValues[key] !== undefined) {
|
|
15
|
-
startVals[key] =
|
|
16
|
-
type === "number" ? Number(nestedValues[key]) : nestedValues[key];
|
|
17
|
-
} else if (typeof schema[key] === "object" && schema[key]?.properties) {
|
|
18
|
-
// Recursively traverse nested properties
|
|
19
|
-
const nestedStartVals = getNestedStartVals(
|
|
20
|
-
schema[key].properties,
|
|
21
|
-
nestedValues,
|
|
22
|
-
);
|
|
23
|
-
if (Object.keys(nestedStartVals).length > 0) {
|
|
24
|
-
startVals[key] = nestedStartVals;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
return startVals;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
1
|
/**
|
|
32
2
|
* Retrieves startVals from Query Params or style variables based on layer configuration.
|
|
33
3
|
*
|
|
@@ -76,10 +46,109 @@ export function getStartVals(layer, layerConfig) {
|
|
|
76
46
|
}
|
|
77
47
|
} else return null;
|
|
78
48
|
|
|
49
|
+
// fall back for schemas passed as a bare map of field definitions
|
|
50
|
+
const fieldSchemas = collectFieldSchemas(layerConfig.schema);
|
|
79
51
|
const startVals = getNestedStartVals(
|
|
80
|
-
|
|
52
|
+
Object.keys(fieldSchemas).length ? fieldSchemas : layerConfig.schema,
|
|
81
53
|
nestedValues,
|
|
54
|
+
layerConfig.schema,
|
|
82
55
|
);
|
|
83
56
|
|
|
84
57
|
return Object.keys(startVals).length ? startVals : null;
|
|
85
58
|
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Collects a schema's field definitions from `properties` and from `anyOf`/`oneOf`/`allOf`
|
|
62
|
+
* branches, resolving `$ref` branches against the root schema. json-editor uses those
|
|
63
|
+
* combinators for "pick one variant" forms, where `properties` alone is empty.
|
|
64
|
+
*
|
|
65
|
+
* @param {{[key: string]: any}} schema - The schema object to collect fields from.
|
|
66
|
+
* @param {{[key: string]: any}} [rootSchema] - The root schema `$ref`s resolve against.
|
|
67
|
+
* @param {Set<string>} [seenRefs] - Already-resolved refs, guards against circular `$ref`s.
|
|
68
|
+
* @returns {{[key: string]: any}} - Field definitions keyed by property name.
|
|
69
|
+
*/
|
|
70
|
+
function collectFieldSchemas(
|
|
71
|
+
schema,
|
|
72
|
+
rootSchema = schema,
|
|
73
|
+
seenRefs = new Set(),
|
|
74
|
+
) {
|
|
75
|
+
if (!schema || typeof schema !== "object") return {};
|
|
76
|
+
|
|
77
|
+
const fields = {};
|
|
78
|
+
if (typeof schema.$ref === "string" && !seenRefs.has(schema.$ref)) {
|
|
79
|
+
seenRefs.add(schema.$ref);
|
|
80
|
+
Object.assign(
|
|
81
|
+
fields,
|
|
82
|
+
collectFieldSchemas(
|
|
83
|
+
resolveLocalRef(schema.$ref, rootSchema),
|
|
84
|
+
rootSchema,
|
|
85
|
+
seenRefs,
|
|
86
|
+
),
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
for (const key of ["anyOf", "oneOf", "allOf"]) {
|
|
90
|
+
if (Array.isArray(schema[key])) {
|
|
91
|
+
for (const branch of schema[key]) {
|
|
92
|
+
Object.assign(
|
|
93
|
+
fields,
|
|
94
|
+
collectFieldSchemas(branch, rootSchema, seenRefs),
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
// `properties` overlays last so constraint-only branch entries can't shadow real fields
|
|
100
|
+
return Object.assign(fields, schema.properties);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Recursively traverses the schema object to extract startVals based on values of nested properties.
|
|
105
|
+
*
|
|
106
|
+
* @param {{[key: string]: any}} schema - The schema object to traverse.
|
|
107
|
+
* @param {{[key: string]: any}} nestedValues - values of nested properties to extract startVals.
|
|
108
|
+
* @param {{[key: string]: any}} [rootSchema] - The root schema `$ref`s resolve against.
|
|
109
|
+
* @returns {object} - Object containing the startVals.
|
|
110
|
+
*/
|
|
111
|
+
export function getNestedStartVals(schema, nestedValues, rootSchema = schema) {
|
|
112
|
+
let startVals = {};
|
|
113
|
+
|
|
114
|
+
for (const key in schema) {
|
|
115
|
+
const type = schema[key]?.type;
|
|
116
|
+
// Extract startVal based on type
|
|
117
|
+
if (type && type !== "object" && nestedValues[key] !== undefined) {
|
|
118
|
+
const value = ["number", "integer"].includes(type)
|
|
119
|
+
? Number(nestedValues[key])
|
|
120
|
+
: nestedValues[key];
|
|
121
|
+
// keep the raw URL value instead of NaN (e.g. "auto" on a number field)
|
|
122
|
+
startVals[key] = Number.isNaN(value) ? nestedValues[key] : value;
|
|
123
|
+
} else {
|
|
124
|
+
// Recursively traverse nested properties
|
|
125
|
+
const nestedStartVals = getNestedStartVals(
|
|
126
|
+
collectFieldSchemas(schema[key], rootSchema),
|
|
127
|
+
nestedValues,
|
|
128
|
+
rootSchema,
|
|
129
|
+
);
|
|
130
|
+
if (Object.keys(nestedStartVals).length > 0) {
|
|
131
|
+
startVals[key] = nestedStartVals;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return startVals;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Resolves a local `$ref` pointer (e.g. `#/definitions/foo`) against the root schema.
|
|
140
|
+
*
|
|
141
|
+
* @param {string} ref - The `$ref` value.
|
|
142
|
+
* @param {{[key: string]: any}} rootSchema - The schema holding `definitions`/`$defs`.
|
|
143
|
+
* @returns {{[key: string]: any} | undefined} - The referenced schema, or undefined for external/unresolvable refs.
|
|
144
|
+
*/
|
|
145
|
+
function resolveLocalRef(ref, rootSchema) {
|
|
146
|
+
if (!ref.startsWith("#/")) return undefined;
|
|
147
|
+
return ref
|
|
148
|
+
.slice(2)
|
|
149
|
+
.split("/")
|
|
150
|
+
.reduce(
|
|
151
|
+
(node, part) => node?.[part.replace(/~1/g, "/").replace(/~0/g, "~")],
|
|
152
|
+
rootSchema,
|
|
153
|
+
);
|
|
154
|
+
}
|
|
@@ -20,38 +20,34 @@ const dataChangeMethod = (data, tileUrlFunc, EOxLayerControlLayerConfig) => {
|
|
|
20
20
|
/** @type {import("ol/source").Source & { getTileUrlFunction: Function, setTileUrlFunction: Function, setKey: Function, updateParams: Function, _updatedUrl: string, getUrls: Function }} */ (
|
|
21
21
|
EOxLayerControlLayerConfig.layer.getSource()
|
|
22
22
|
);
|
|
23
|
+
|
|
24
|
+
const removeProperties =
|
|
25
|
+
EOxLayerControlLayerConfig.layerConfig.schema?.options?.removeProperties ??
|
|
26
|
+
[];
|
|
27
|
+
const updatedData = { ...data };
|
|
28
|
+
removeProperties.forEach((prop) => delete updatedData[prop]);
|
|
29
|
+
|
|
23
30
|
if (source.updateParams) {
|
|
24
|
-
const updatedData = { ...data };
|
|
25
|
-
const removeProperties =
|
|
26
|
-
EOxLayerControlLayerConfig.layerConfig.schema?.options
|
|
27
|
-
?.removeProperties ?? [];
|
|
28
|
-
removeProperties.forEach((prop) => delete updatedData[prop]);
|
|
29
31
|
source.updateParams(updatedData);
|
|
30
32
|
} else if (source.getTileUrlFunction && source.getTileUrlFunction()) {
|
|
31
33
|
if (!newTileUrlFunc) {
|
|
32
34
|
newTileUrlFunc = source.getTileUrlFunction();
|
|
33
35
|
}
|
|
34
36
|
|
|
37
|
+
// Store the updated URL synchronously so switching to the globe reflects the change
|
|
38
|
+
if (source instanceof XYZ_ol) {
|
|
39
|
+
source._updatedUrl = updateUrl(
|
|
40
|
+
/** @type {XYZ_ol} */ (source).getUrls()[0],
|
|
41
|
+
data,
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
35
45
|
// Setting a new tile URL function for the layer's source by applying updated data to the existing function.
|
|
36
46
|
source.setTileUrlFunction((...args) => {
|
|
37
47
|
const url = new URL(newTileUrlFunc(...args));
|
|
38
|
-
const removeProperties =
|
|
39
|
-
EOxLayerControlLayerConfig.layerConfig.schema?.options
|
|
40
|
-
?.removeProperties ?? [];
|
|
41
|
-
|
|
42
|
-
const updatedData = { ...data };
|
|
43
|
-
removeProperties.forEach((prop) => delete updatedData[prop]);
|
|
44
|
-
|
|
45
|
-
// Store the updated URL on the source for other components (like the globe) to use
|
|
46
|
-
if (source instanceof XYZ_ol) {
|
|
47
|
-
source._updatedUrl = updateUrl(
|
|
48
|
-
/** @type {XYZ_ol} */ (source).getUrls()[0],
|
|
49
|
-
updatedData,
|
|
50
|
-
);
|
|
51
|
-
}
|
|
52
48
|
// Remove unwanted properties from query parameters
|
|
53
49
|
removeProperties.forEach((prop) => url.searchParams.delete(prop));
|
|
54
|
-
return updateUrl(url.href,
|
|
50
|
+
return updateUrl(url.href, data);
|
|
55
51
|
});
|
|
56
52
|
|
|
57
53
|
// TODO: It's not advisable to access protected methods directly.
|
|
@@ -65,17 +61,11 @@ const dataChangeMethod = (data, tileUrlFunc, EOxLayerControlLayerConfig) => {
|
|
|
65
61
|
if (map) {
|
|
66
62
|
const globe = map.globe;
|
|
67
63
|
if (globe) {
|
|
68
|
-
const updatedData = { ...data };
|
|
69
|
-
const removeProperties =
|
|
70
|
-
EOxLayerControlLayerConfig.layerConfig.schema?.options
|
|
71
|
-
?.removeProperties ?? [];
|
|
72
|
-
removeProperties.forEach((prop) => delete updatedData[prop]);
|
|
73
|
-
|
|
74
64
|
const globusLayer = globe.planet.layers.filter(
|
|
75
65
|
(l) => l.name == EOxLayerControlLayerConfig.layer.get("id"),
|
|
76
66
|
)[0];
|
|
77
67
|
if (globusLayer) {
|
|
78
|
-
globusLayer.setUrl(updateUrl(globusLayer.url,
|
|
68
|
+
globusLayer.setUrl(updateUrl(globusLayer.url, data));
|
|
79
69
|
}
|
|
80
70
|
window.eoxMapGlobe.refresh();
|
|
81
71
|
}
|
|
@@ -1,21 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Retrieves startVals from Query Params or style variables based on layer configuration.
|
|
3
|
+
*
|
|
4
|
+
* @param {import("ol/layer").Layer} layer - The layer object.
|
|
5
|
+
* @param {import("../components/layer-config").EOxLayerControlLayerConfig['layerConfig']} layerConfig - Configuration object for the layer.
|
|
6
|
+
* @returns {object | null} - Object containing the startVals or null if not found.
|
|
7
|
+
*/
|
|
8
|
+
export function getStartVals(layer: import("ol/layer").Layer, layerConfig: import("../components/layer-config").EOxLayerControlLayerConfig["layerConfig"]): object | null;
|
|
1
9
|
/**
|
|
2
10
|
* Recursively traverses the schema object to extract startVals based on values of nested properties.
|
|
3
11
|
*
|
|
4
12
|
* @param {{[key: string]: any}} schema - The schema object to traverse.
|
|
5
13
|
* @param {{[key: string]: any}} nestedValues - values of nested properties to extract startVals.
|
|
14
|
+
* @param {{[key: string]: any}} [rootSchema] - The root schema `$ref`s resolve against.
|
|
6
15
|
* @returns {object} - Object containing the startVals.
|
|
7
16
|
*/
|
|
8
17
|
export function getNestedStartVals(schema: {
|
|
9
18
|
[key: string]: any;
|
|
10
19
|
}, nestedValues: {
|
|
11
20
|
[key: string]: any;
|
|
21
|
+
}, rootSchema?: {
|
|
22
|
+
[key: string]: any;
|
|
12
23
|
}): object;
|
|
13
|
-
/**
|
|
14
|
-
* Retrieves startVals from Query Params or style variables based on layer configuration.
|
|
15
|
-
*
|
|
16
|
-
* @param {import("ol/layer").Layer} layer - The layer object.
|
|
17
|
-
* @param {import("../components/layer-config").EOxLayerControlLayerConfig['layerConfig']} layerConfig - Configuration object for the layer.
|
|
18
|
-
* @returns {object | null} - Object containing the startVals or null if not found.
|
|
19
|
-
*/
|
|
20
|
-
export function getStartVals(layer: import("ol/layer").Layer, layerConfig: import("../components/layer-config").EOxLayerControlLayerConfig["layerConfig"]): object | null;
|
|
21
24
|
//# 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,
|
|
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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data-change.d.ts","sourceRoot":"","sources":["../../../src/methods/layer-config/data-change.js"],"names":[],"mappings":";AAGA;;;;;;;;GAQG;AACH,wCALW;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CAAC,qDAEpB,OAAO,+BAA+B,EAAE,0BAA0B,
|
|
1
|
+
{"version":3,"file":"data-change.d.ts","sourceRoot":"","sources":["../../../src/methods/layer-config/data-change.js"],"names":[],"mappings":";AAGA;;;;;;;;GAQG;AACH,wCALW;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CAAC,qDAEpB,OAAO,+BAA+B,EAAE,0BAA0B,YAiE5E"}
|