@eox/layercontrol 0.21.1 → 0.23.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/README.md +4 -0
- package/dist/eox-layercontrol.js +1360 -1216
- package/dist/eox-layercontrol.umd.cjs +220 -147
- package/package.json +10 -13
- package/src/components/add-layers.js +416 -0
- package/src/components/layer-config.js +212 -0
- package/src/components/layer-datetime.js +128 -0
- package/src/components/layer-group.js +193 -0
- package/src/components/layer-legend.js +135 -0
- package/src/components/layer-list.js +209 -0
- package/src/components/layer-tools.js +353 -0
- package/src/components/layer.js +244 -0
- package/src/components/optional-list.js +124 -0
- package/src/components/tab-sliders.js +0 -0
- package/src/components/tools-items.js +199 -0
- package/src/enums/index.js +16 -0
- package/src/enums/stories/assets/cropomhusc-feature-collection.json +5274 -0
- package/src/enums/stories/index.js +536 -0
- package/src/helpers/check-properties.js +41 -0
- package/src/helpers/clean-json-input.js +29 -0
- package/src/helpers/create-sortable.js +104 -0
- package/src/helpers/detect-map-url-type.js +20 -0
- package/src/helpers/fetch-capabilities.js +32 -0
- package/src/helpers/filter-layers.js +45 -0
- package/src/helpers/get-layer-type.js +35 -0
- package/src/helpers/get-legend-config.js +25 -0
- package/src/helpers/get-start-vals.js +73 -0
- package/src/helpers/hide-layers-based-on-property.js +11 -0
- package/src/helpers/index.js +22 -0
- package/src/helpers/is-layer-json-valid.js +19 -0
- package/src/helpers/is-layer-visible-based-on-zoom-state.js +31 -0
- package/src/helpers/is-layer-zoom-state-req.js +17 -0
- package/src/helpers/is-map-url-valid.js +22 -0
- package/src/helpers/layer-tools.js +82 -0
- package/src/helpers/update-url.js +32 -0
- package/src/main.js +269 -0
- package/src/methods/add-layer/add-layer.js +33 -0
- package/src/methods/add-layer/index.js +8 -0
- package/src/methods/add-layer/json-input-change.js +15 -0
- package/src/methods/add-layer/open-close-tab.js +21 -0
- package/src/methods/add-layer/url-input-change.js +17 -0
- package/src/methods/add-layer/url-layer.js +37 -0
- package/src/methods/add-layer/wms-search-url.js +44 -0
- package/src/methods/layer/first-updated.js +65 -0
- package/src/methods/layer/index.js +4 -0
- package/src/methods/layer/input-click.js +43 -0
- package/src/methods/layer-config/apply-updated-styles.js +98 -0
- package/src/methods/layer-config/data-change.js +44 -0
- package/src/methods/layer-config/index.js +7 -0
- package/src/methods/layer-list/first-updated.js +55 -0
- package/src/methods/layer-list/index.js +3 -0
- package/src/methods/layercontrol/first-update.js +22 -0
- package/src/methods/layercontrol/index.js +4 -0
- package/src/methods/layercontrol/layer-list-change.js +23 -0
- package/src/methods/optional-list/add-to-list.js +44 -0
- package/src/methods/optional-list/index.js +3 -0
- package/test/_mockMap.js +0 -154
- package/test/cases/general/check-layer-size.js +0 -25
- package/test/cases/general/check-pre-open-layer-tools.js +0 -26
- package/test/cases/general/check-pre-open-section.js +0 -29
- package/test/cases/general/disable-drag.js +0 -26
- package/test/cases/general/empty-groups.js +0 -41
- package/test/cases/general/exclusive-layers.js +0 -35
- package/test/cases/general/hide-layers.js +0 -23
- package/test/cases/general/index.js +0 -9
- package/test/cases/general/render-optional-layer.js +0 -31
- package/test/cases/general/show-layer-title.js +0 -23
- package/test/cases/layer-update/add-external-layer.js +0 -96
- package/test/cases/layer-update/add-layer-from-optional.js +0 -51
- package/test/cases/layer-update/check-if-layer-pushed-to-group.js +0 -33
- package/test/cases/layer-update/check-layer-changed-event.js +0 -29
- package/test/cases/layer-update/check-layer-is-pushed-to-root.js +0 -22
- package/test/cases/layer-update/check-layer-removed-from-group.js +0 -33
- package/test/cases/layer-update/check-layer-removed-from-root.js +0 -27
- package/test/cases/layer-update/check-layer-size-after-multiple-calls.js +0 -34
- package/test/cases/layer-update/check-layer-zoom-state.js +0 -54
- package/test/cases/layer-update/index.js +0 -9
- package/test/general.cy.js +0 -57
- package/test/layersUpdate.cy.js +0 -72
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Detects the type of map URL based on WMS and XYZ patterns.
|
|
3
|
+
*
|
|
4
|
+
* @param {string} url - The URL to analyze.
|
|
5
|
+
* @returns {"TileWMS" | false | "XYZ"} - The detected map URL type, or false if not recognized.
|
|
6
|
+
*/
|
|
7
|
+
export default function detectMapURLType(url) {
|
|
8
|
+
// Regular expressions to match WMS and XYZ patterns
|
|
9
|
+
const wmsPattern = /\b(?:wms|ows)\b/i;
|
|
10
|
+
const xyzPattern = /{(?:z|x|y-?)}\/{(?:z|x|y-?)}\/{(?:z|x|y-?)}/i;
|
|
11
|
+
|
|
12
|
+
// Check if the URL matches the WMS pattern
|
|
13
|
+
if (wmsPattern.test(url)) return "TileWMS";
|
|
14
|
+
|
|
15
|
+
// Check if the URL matches the XYZ pattern
|
|
16
|
+
if (xyzPattern.test(url)) return "XYZ";
|
|
17
|
+
|
|
18
|
+
// Neither WMS nor XYZ pattern matched
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import WMSCapabilities from "wms-capabilities";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Fetches WMS capabilities data from the provided original URL.
|
|
5
|
+
* It constructs a new URL with additional parameters, makes a fetch request,
|
|
6
|
+
* and returns the WMS capabilities in JSON format.
|
|
7
|
+
*
|
|
8
|
+
* @param {string} originalURL - The original URL to fetch capabilities from.
|
|
9
|
+
* @returns {Promise<import("wms-capabilities").WMSCapabilitiesJSON>} - A Promise resolving to the fetched WMS capabilities in JSON format.
|
|
10
|
+
*/
|
|
11
|
+
export default async function fetchCapabilities(originalURL) {
|
|
12
|
+
// Create a URL object from the original URL string
|
|
13
|
+
let url = new URL(originalURL);
|
|
14
|
+
let params = url.searchParams;
|
|
15
|
+
|
|
16
|
+
// Update or add multiple parameters for WMS capabilities
|
|
17
|
+
params.set("SERVICE", "WMS");
|
|
18
|
+
params.set("REQUEST", "GetCapabilities"); // Change or add a new parameter
|
|
19
|
+
|
|
20
|
+
// Generate the updated URL string
|
|
21
|
+
let updatedURL = url.toString();
|
|
22
|
+
|
|
23
|
+
// Fetch the updated URL to get capabilities data
|
|
24
|
+
const response = await fetch(updatedURL);
|
|
25
|
+
if (!response.ok) throw new Error(`Error: ${response.status}`);
|
|
26
|
+
else {
|
|
27
|
+
const capabilitiesText = await response.text();
|
|
28
|
+
|
|
29
|
+
// Convert the WMS capabilities data to JSON format
|
|
30
|
+
return new WMSCapabilities(capabilitiesText).toJSON();
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Filter all map layers by property.
|
|
3
|
+
*
|
|
4
|
+
* @param {any[]} layers - Array of layers to search through.
|
|
5
|
+
* @param {string} key - Property key to filter by.
|
|
6
|
+
* @param {any} value - Value to match against the property.
|
|
7
|
+
* @returns {Array<import("ol/layer").Group>} - Array of found layers.
|
|
8
|
+
*/
|
|
9
|
+
export default function filterLayers(layers, key, value) {
|
|
10
|
+
/** @type {Array<import("ol/layer").Group>} */
|
|
11
|
+
let found = [];
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Filter all map layers by property.
|
|
15
|
+
*
|
|
16
|
+
* @param {Array<import("ol/layer").Group>} searchLayers - Array of layers to search through.
|
|
17
|
+
* @param {string} key - Property key to filter by.
|
|
18
|
+
* @param {any} value - Value to match against the property.
|
|
19
|
+
* @returns {Array<import("ol/layer").Group>} - Array of found layers.
|
|
20
|
+
*/
|
|
21
|
+
const search = (searchLayers, key, value) => {
|
|
22
|
+
// Filter layers based on the provided key and value
|
|
23
|
+
found = [
|
|
24
|
+
...found,
|
|
25
|
+
...searchLayers.filter((layer) => layer.get(key) === value),
|
|
26
|
+
];
|
|
27
|
+
|
|
28
|
+
// Check if there are sub-layers (groups)
|
|
29
|
+
const groups = searchLayers.filter(
|
|
30
|
+
(layer) => /** @type {import("ol/layer").Group} */ (layer).getLayers,
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
// If sub-layers are present, recursively search through them
|
|
34
|
+
if (groups.length > 0)
|
|
35
|
+
groups.forEach((group) =>
|
|
36
|
+
// @ts-expect-error TODO
|
|
37
|
+
search(group.getLayers().getArray(), key, value),
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
return found;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
search(layers, key, value);
|
|
44
|
+
return found;
|
|
45
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tries to infer the layer type based on certain properties without direct dependency on OL.
|
|
3
|
+
*
|
|
4
|
+
* @param {import("ol/layer").Layer | import("ol/layer").Group} layer - The layer or layer group.
|
|
5
|
+
* @param {import("ol").Map} map - The OL map instance.
|
|
6
|
+
* @returns {string|undefined} - The inferred layer type: "group", "draw", "vector", "raster", or undefined if not determinable.
|
|
7
|
+
*/
|
|
8
|
+
export default function getLayerType(layer, map) {
|
|
9
|
+
// Unable to determine layer type without necessary objects
|
|
10
|
+
if (!layer || !map) return undefined;
|
|
11
|
+
|
|
12
|
+
// Check if the layer is a group
|
|
13
|
+
// @ts-expect-error TODO
|
|
14
|
+
if (layer.getLayers) return "group"; // Identified as a layer group
|
|
15
|
+
|
|
16
|
+
// Attempt to infer based on other properties
|
|
17
|
+
const interactions = map.getInteractions().getArray();
|
|
18
|
+
|
|
19
|
+
// Filter interactions for drawing - assuming freehand_ property as an indicator
|
|
20
|
+
const isDrawing = interactions
|
|
21
|
+
// @ts-expect-error TODO
|
|
22
|
+
.filter((i) => i.freehand_ !== undefined)
|
|
23
|
+
// @ts-expect-error TODO
|
|
24
|
+
.map((i) => i.source_)
|
|
25
|
+
// @ts-expect-error TODO
|
|
26
|
+
?.ol_uid?.includes(
|
|
27
|
+
// @ts-expect-error TODO
|
|
28
|
+
layer.getSource ? layer.getSource()?.ol_uid : undefined,
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
if (isDrawing) return "draw";
|
|
32
|
+
// @ts-expect-error TODO
|
|
33
|
+
else if (layer.declutter_ !== undefined) return "vector";
|
|
34
|
+
else return "raster";
|
|
35
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { flattenObject } from "../methods/layer-config";
|
|
2
|
+
/**
|
|
3
|
+
* extracts legend configurations from `LayerConfig`
|
|
4
|
+
*
|
|
5
|
+
* @param {import("../components/layer-config").EOxLayerControlLayerConfig["layerConfig"]["legend"]} legendConfig
|
|
6
|
+
* @param {Record<string,unknown>} data
|
|
7
|
+
*/
|
|
8
|
+
const getLegendConfig = (legendConfig, data) => {
|
|
9
|
+
if (!legendConfig) return undefined;
|
|
10
|
+
if (!("domainProperties" in legendConfig) || "domain" in legendConfig) {
|
|
11
|
+
return { ...legendConfig };
|
|
12
|
+
}
|
|
13
|
+
return Object.keys(legendConfig)?.reduce((legend, key) => {
|
|
14
|
+
if (key === "domainProperties") {
|
|
15
|
+
const flatData_ = flattenObject(data);
|
|
16
|
+
legend["domain"] = legendConfig[key].map((k) => flatData_[k]);
|
|
17
|
+
} else {
|
|
18
|
+
// @ts-expect-error TODO
|
|
19
|
+
legend[key] = legendConfig[key];
|
|
20
|
+
}
|
|
21
|
+
return legend;
|
|
22
|
+
}, /** @type {import("../components/layer-legend").LegendConfig} */ ({}));
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export default getLegendConfig;
|
|
@@ -0,0 +1,73 @@
|
|
|
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
|
+
|
|
14
|
+
// Extract startVal based on type
|
|
15
|
+
if (type && type !== "object") {
|
|
16
|
+
// @ts-expect-error TODO
|
|
17
|
+
startVals[key] =
|
|
18
|
+
type === "number" ? Number(nestedValues[key]) : nestedValues[key];
|
|
19
|
+
} else if (typeof schema[key] === "object" && schema[key]?.properties) {
|
|
20
|
+
// Recursively traverse nested properties
|
|
21
|
+
const nestedStartVals = getNestedStartVals(
|
|
22
|
+
schema[key].properties,
|
|
23
|
+
nestedValues,
|
|
24
|
+
);
|
|
25
|
+
if (Object.keys(nestedStartVals).length > 0) {
|
|
26
|
+
// @ts-expect-error TODO
|
|
27
|
+
startVals[key] = nestedStartVals;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return startVals;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Retrieves startVals from Query Params or style variables based on layer configuration.
|
|
36
|
+
*
|
|
37
|
+
* @param {import("ol/layer").Layer} layer - The layer object.
|
|
38
|
+
* @param {import("../components/layer-config").EOxLayerControlLayerConfig['layerConfig']} layerConfig - Configuration object for the layer.
|
|
39
|
+
* @returns {object | null} - Object containing the startVals or null if not found.
|
|
40
|
+
*/
|
|
41
|
+
export function getStartVals(layer, layerConfig) {
|
|
42
|
+
// Check for layer configuration and tile URL function availability
|
|
43
|
+
if (!layerConfig) return null;
|
|
44
|
+
|
|
45
|
+
/** @type {Record<string,unknown>}*/
|
|
46
|
+
let nestedValues = {};
|
|
47
|
+
// extract style variables from layer
|
|
48
|
+
let styleVars =
|
|
49
|
+
"updateStyleVariables" in layer
|
|
50
|
+
? /** @type {import("ol/layer/WebGLTile").default} */
|
|
51
|
+
(layer)["style_"]?.variables
|
|
52
|
+
: layerConfig.style?.variables;
|
|
53
|
+
if ((layerConfig.type === "style" || layerConfig.style) && styleVars) {
|
|
54
|
+
nestedValues = styleVars;
|
|
55
|
+
|
|
56
|
+
// @ts-expect-error TODO
|
|
57
|
+
} else if (layer.getSource()?.getTileUrlFunction?.()) {
|
|
58
|
+
// Extract query parameters from tile URL
|
|
59
|
+
// @ts-expect-error TODO
|
|
60
|
+
const url = new URL(layer.getSource().getTileUrlFunction()([0, 0, 0]));
|
|
61
|
+
|
|
62
|
+
// Retrieve startVals based on schema and query parameters
|
|
63
|
+
// @ts-expect-error TODO
|
|
64
|
+
nestedValues = Object.fromEntries(url.searchParams.entries());
|
|
65
|
+
} else return null;
|
|
66
|
+
|
|
67
|
+
const startVals = getNestedStartVals(
|
|
68
|
+
layerConfig.schema?.properties || layerConfig.schema,
|
|
69
|
+
nestedValues,
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
return Object.keys(startVals).length ? startVals : null;
|
|
73
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Run the layer collection through a set of property filters before rendering
|
|
3
|
+
*
|
|
4
|
+
* @param {import("ol").Collection<import("ol/layer").Layer | import("ol/layer").Group>} collection - The collection of layers to be checked.
|
|
5
|
+
*/
|
|
6
|
+
export const hideLayersBasedOnProperties = (collection) => {
|
|
7
|
+
const propertyFilters = ["layerControlHide", "layerControlOptional"];
|
|
8
|
+
return collection
|
|
9
|
+
?.getArray()
|
|
10
|
+
?.filter((l) => propertyFilters.every((p) => !l.get(p)));
|
|
11
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export { default as fetchCapabilities } from "./fetch-capabilities";
|
|
2
|
+
export { default as detectMapURLType } from "./detect-map-url-type";
|
|
3
|
+
export { default as isMapUrlValid } from "./is-map-url-valid";
|
|
4
|
+
export { default as cleanJSONInput } from "./clean-json-input";
|
|
5
|
+
export { default as isLayerJSONValid } from "./is-layer-json-valid";
|
|
6
|
+
export { default as updateUrl } from "./update-url";
|
|
7
|
+
export { default as createSortable } from "./create-sortable";
|
|
8
|
+
export { default as checkProperties } from "./check-properties";
|
|
9
|
+
export { default as filterLayers } from "./filter-layers";
|
|
10
|
+
export { default as isLayerVisibleBasedOnZoomState } from "./is-layer-visible-based-on-zoom-state";
|
|
11
|
+
export { default as isLayerZoomStateRequired } from "./is-layer-zoom-state-req";
|
|
12
|
+
export { default as getLayerType } from "./get-layer-type";
|
|
13
|
+
export { default as getLegendConfig } from "./get-legend-config.js";
|
|
14
|
+
export { getNestedStartVals, getStartVals } from "./get-start-vals";
|
|
15
|
+
export {
|
|
16
|
+
Button,
|
|
17
|
+
_parseActions,
|
|
18
|
+
_parseTools,
|
|
19
|
+
removeButton,
|
|
20
|
+
sortButton,
|
|
21
|
+
} from "./layer-tools";
|
|
22
|
+
export { hideLayersBasedOnProperties } from "./hide-layers-based-on-property";
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import cleanJSONInput from "./clean-json-input";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Checks if the stored 'jsonInput' is a valid JSON string.
|
|
5
|
+
* @param {string} str
|
|
6
|
+
* @returns {boolean} - Returns true if the 'jsonInput' is a valid JSON, otherwise false.
|
|
7
|
+
*/
|
|
8
|
+
export default function isLayerJSONValid(str) {
|
|
9
|
+
try {
|
|
10
|
+
// Parsing the jsonInput to test if it's a valid JSON
|
|
11
|
+
JSON.parse(cleanJSONInput(str));
|
|
12
|
+
|
|
13
|
+
// Returning true if 'jsonInput' is not empty
|
|
14
|
+
return !!str;
|
|
15
|
+
} catch (_) {
|
|
16
|
+
// Returning false if there's an error parsing or if 'jsonInput' is empty
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { isLayerZoomStateRequired } from ".";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Determines layer visibility state based on minZoom and maxZoom
|
|
5
|
+
* concerning the current zoom level.
|
|
6
|
+
*
|
|
7
|
+
* @param {import("ol/layer").Layer | import("ol/layer").Group} layer - The layer or layer group to check visibility for.
|
|
8
|
+
* @param {import("ol").Map} map - The map instance to retrieve the current zoom level.
|
|
9
|
+
* @param {Boolean} showLayerZoomState - Flag indicating if zoom-based visibility is enabled.
|
|
10
|
+
* @returns {Boolean} - The visibility state of the layer based on zoom levels.
|
|
11
|
+
*/
|
|
12
|
+
export default function isLayerVisibleBasedOnZoomState(
|
|
13
|
+
layer,
|
|
14
|
+
map,
|
|
15
|
+
showLayerZoomState,
|
|
16
|
+
) {
|
|
17
|
+
// If layer or map is unavailable or layer zoom state is not required, return false
|
|
18
|
+
if (!layer || !map) return false;
|
|
19
|
+
|
|
20
|
+
if (!isLayerZoomStateRequired(layer, showLayerZoomState)) return true;
|
|
21
|
+
|
|
22
|
+
// Retrieve minimum and maximum zoom levels set for the layer
|
|
23
|
+
const minZoom = layer.get("minZoom");
|
|
24
|
+
const maxZoom = layer.get("maxZoom");
|
|
25
|
+
|
|
26
|
+
// Retrieve the current zoom level of the map
|
|
27
|
+
const zoom = map.getView().getZoom();
|
|
28
|
+
|
|
29
|
+
// Return the visibility state of the layer
|
|
30
|
+
return zoom > minZoom && zoom < maxZoom ? true : false;
|
|
31
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns whether zoom layer state be enabled or not for a particular layer
|
|
3
|
+
*
|
|
4
|
+
* @param {import("ol/layer").Layer | import("ol/layer").Group} layer - The layer or layer group to check for zoom-based visibility.
|
|
5
|
+
* @param {Boolean} showLayerZoomState - Flag indicating if zoom-based visibility is requested.
|
|
6
|
+
* @returns {Boolean} - Indicates if the zoom-based layer visibility state is required.
|
|
7
|
+
*/
|
|
8
|
+
export default function isLayerZoomStateRequired(layer, showLayerZoomState) {
|
|
9
|
+
// Retrieve minimum and maximum zoom levels set for the layer
|
|
10
|
+
const minZoom = layer.get("minZoom");
|
|
11
|
+
const maxZoom = layer.get("maxZoom");
|
|
12
|
+
|
|
13
|
+
// Check if zoom-based visibility is requested and if minZoom or maxZoom are finite
|
|
14
|
+
if (showLayerZoomState && (minZoom !== -Infinity || maxZoom !== Infinity))
|
|
15
|
+
return true;
|
|
16
|
+
else return false;
|
|
17
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import detectMapURLType from "./detect-map-url-type";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Checks if the given URL is a valid map URL based on specified criteria.
|
|
5
|
+
*
|
|
6
|
+
* @param {string} url - The URL to validate.
|
|
7
|
+
* @returns {boolean} - Indicates whether the URL is a valid map URL.
|
|
8
|
+
*/
|
|
9
|
+
export default function isMapUrlValid(url) {
|
|
10
|
+
// Regular expression pattern to match URLs with localhost, domain, and IP addresses
|
|
11
|
+
const urlRegex =
|
|
12
|
+
/^(?:(?:https?|ftp):\/\/|\/\/)?(?:localhost|\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}|(?:\w+[\w-]*\.)+\w+)(?::\d+)?(?:\/\S*)?$/;
|
|
13
|
+
|
|
14
|
+
// Check if the URL matches the defined pattern
|
|
15
|
+
const urlMatchesPattern = urlRegex.test(url);
|
|
16
|
+
|
|
17
|
+
// Detect the type of map URL using the provided function
|
|
18
|
+
const mapUrlType = detectMapURLType(url);
|
|
19
|
+
|
|
20
|
+
// Return true if the URL is not empty and matches the pattern and has a valid map URL type, otherwise false
|
|
21
|
+
return !!(url && urlMatchesPattern && mapUrlType);
|
|
22
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { html, nothing } from "lit";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Filters actions based on provided tools and layer properties.
|
|
5
|
+
*
|
|
6
|
+
* @param {Array<string>} tools - Array of tool names.
|
|
7
|
+
* @param {import("ol/layer").Layer} layer - The native OL layer
|
|
8
|
+
* @returns {Array<string>} - Filtered array of action names.
|
|
9
|
+
*/
|
|
10
|
+
export const _parseActions = (tools, layer) => {
|
|
11
|
+
return tools?.filter((t) =>
|
|
12
|
+
["remove", "sort"]
|
|
13
|
+
.filter((k) => (layer?.get("layerControlDisable") ? k !== "sort" : true))
|
|
14
|
+
.includes(t),
|
|
15
|
+
);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Parses tools based on provided tools and layer properties.
|
|
20
|
+
*
|
|
21
|
+
* @param {Array<string>} tools - Array of tool names.
|
|
22
|
+
* @param {import("ol/layer").Layer} layer - The native OL layer
|
|
23
|
+
* @returns {Array<string>} - Parsed array of tool names.
|
|
24
|
+
*/
|
|
25
|
+
export const _parseTools = (tools, layer) =>
|
|
26
|
+
tools?.filter((t) => {
|
|
27
|
+
let pass = true;
|
|
28
|
+
if (["remove", "sort"].includes(t)) pass = false;
|
|
29
|
+
if (t === "info") pass = layer.get("description");
|
|
30
|
+
if (t === "config") pass = layer.get("layerConfig");
|
|
31
|
+
if (t === "datetime") pass = layer.get("layerDatetime");
|
|
32
|
+
if (t === "legend") pass = layer.get("layerLegend");
|
|
33
|
+
return pass;
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Generates a button element based on the provided tool and style preference.
|
|
38
|
+
*
|
|
39
|
+
* @param {string} tool - Tool name for the button.
|
|
40
|
+
* @param {boolean} unstyled - Style preference for the button.
|
|
41
|
+
* @returns {import("lit").HTMLTemplateResult} - Button element.
|
|
42
|
+
*/
|
|
43
|
+
export const Button = (tool, unstyled) => html`
|
|
44
|
+
<button slot="${tool}-icon" class="icon">${unstyled ? tool : nothing}</button>
|
|
45
|
+
`;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Generates a remove button element with event handling and layer control logic.
|
|
49
|
+
*
|
|
50
|
+
* @param {import("../components/layer-tools").EOxLayerControlLayerTools} EOxLayerControlLayerTools - Instance of EOxLayerControlLayerTools
|
|
51
|
+
* @returns {import("lit").HTMLTemplateResult} - Remove button element.
|
|
52
|
+
*/
|
|
53
|
+
export const removeButton = (EOxLayerControlLayerTools) => html`
|
|
54
|
+
<button
|
|
55
|
+
class="remove-icon icon"
|
|
56
|
+
@click=${() => {
|
|
57
|
+
const { layer } = EOxLayerControlLayerTools;
|
|
58
|
+
layer?.set("layerControlOptional", true);
|
|
59
|
+
layer?.setVisible(false);
|
|
60
|
+
EOxLayerControlLayerTools.dispatchEvent(
|
|
61
|
+
new CustomEvent("changed", {
|
|
62
|
+
detail: layer,
|
|
63
|
+
bubbles: true,
|
|
64
|
+
}),
|
|
65
|
+
);
|
|
66
|
+
}}
|
|
67
|
+
>
|
|
68
|
+
${EOxLayerControlLayerTools.unstyled ? "x" : nothing}
|
|
69
|
+
</button>
|
|
70
|
+
`;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Generates a sort button element based on the style preference.
|
|
74
|
+
*
|
|
75
|
+
* @param {boolean} unstyled - Style preference for the button.
|
|
76
|
+
* @returns {import("lit").HTMLTemplateResult} - Sort button element.
|
|
77
|
+
*/
|
|
78
|
+
export const sortButton = (unstyled) => html`
|
|
79
|
+
<span class="button sort-icon icon drag-handle">
|
|
80
|
+
${unstyled ? "═" : nothing}
|
|
81
|
+
</span>
|
|
82
|
+
`;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Updates the layer's URL using input values and returns the modified URL.
|
|
3
|
+
*
|
|
4
|
+
* @param {String} url - The original URL to be updated.
|
|
5
|
+
* @param {Object} values - The key-value pairs to update in the URL.
|
|
6
|
+
* @returns {String} - The updated URL based on the provided values.
|
|
7
|
+
*/
|
|
8
|
+
export default function updateUrl(url, values) {
|
|
9
|
+
// Create a search params object from the URL
|
|
10
|
+
const searchParams = new URL(url).searchParams;
|
|
11
|
+
|
|
12
|
+
// Loop through each key-value pair in the input values
|
|
13
|
+
Object.entries(values).forEach(([key, value]) => {
|
|
14
|
+
// If the value is an object (and not an array or null), set its properties as search parameters
|
|
15
|
+
if (typeof value === "object" && !Array.isArray(value) && value !== null) {
|
|
16
|
+
Object.keys(value).forEach((k) => {
|
|
17
|
+
searchParams.set(k, value[k]);
|
|
18
|
+
});
|
|
19
|
+
} else searchParams.set(key, value); // Set the key-value pair as a search parameter
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
// Extract the URL without query parameters
|
|
23
|
+
const urlWithPath = url.split("?")[0];
|
|
24
|
+
|
|
25
|
+
// Convert the modified search params back to a string
|
|
26
|
+
const searchParamsStr = searchParams.toString();
|
|
27
|
+
|
|
28
|
+
// Combine the URL path with the updated search parameters to get the new URL
|
|
29
|
+
const newUrl = `${urlWithPath}?${searchParamsStr}`;
|
|
30
|
+
|
|
31
|
+
return newUrl;
|
|
32
|
+
}
|