@eox/layercontrol 0.22.0 → 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.
Files changed (80) hide show
  1. package/README.md +4 -0
  2. package/dist/eox-layercontrol.js +836 -839
  3. package/dist/eox-layercontrol.umd.cjs +119 -122
  4. package/package.json +9 -13
  5. package/src/components/add-layers.js +416 -0
  6. package/src/components/layer-config.js +212 -0
  7. package/src/components/layer-datetime.js +128 -0
  8. package/src/components/layer-group.js +193 -0
  9. package/src/components/layer-legend.js +135 -0
  10. package/src/components/layer-list.js +209 -0
  11. package/src/components/layer-tools.js +353 -0
  12. package/src/components/layer.js +244 -0
  13. package/src/components/optional-list.js +124 -0
  14. package/src/components/tab-sliders.js +0 -0
  15. package/src/components/tools-items.js +199 -0
  16. package/src/enums/index.js +16 -0
  17. package/src/enums/stories/assets/cropomhusc-feature-collection.json +5274 -0
  18. package/src/enums/stories/index.js +536 -0
  19. package/src/helpers/check-properties.js +41 -0
  20. package/src/helpers/clean-json-input.js +29 -0
  21. package/src/helpers/create-sortable.js +104 -0
  22. package/src/helpers/detect-map-url-type.js +20 -0
  23. package/src/helpers/fetch-capabilities.js +32 -0
  24. package/src/helpers/filter-layers.js +45 -0
  25. package/src/helpers/get-layer-type.js +35 -0
  26. package/src/helpers/get-legend-config.js +25 -0
  27. package/src/helpers/get-start-vals.js +73 -0
  28. package/src/helpers/hide-layers-based-on-property.js +11 -0
  29. package/src/helpers/index.js +22 -0
  30. package/src/helpers/is-layer-json-valid.js +19 -0
  31. package/src/helpers/is-layer-visible-based-on-zoom-state.js +31 -0
  32. package/src/helpers/is-layer-zoom-state-req.js +17 -0
  33. package/src/helpers/is-map-url-valid.js +22 -0
  34. package/src/helpers/layer-tools.js +82 -0
  35. package/src/helpers/update-url.js +32 -0
  36. package/src/main.js +269 -0
  37. package/src/methods/add-layer/add-layer.js +33 -0
  38. package/src/methods/add-layer/index.js +8 -0
  39. package/src/methods/add-layer/json-input-change.js +15 -0
  40. package/src/methods/add-layer/open-close-tab.js +21 -0
  41. package/src/methods/add-layer/url-input-change.js +17 -0
  42. package/src/methods/add-layer/url-layer.js +37 -0
  43. package/src/methods/add-layer/wms-search-url.js +44 -0
  44. package/src/methods/layer/first-updated.js +65 -0
  45. package/src/methods/layer/index.js +4 -0
  46. package/src/methods/layer/input-click.js +43 -0
  47. package/src/methods/layer-config/apply-updated-styles.js +98 -0
  48. package/src/methods/layer-config/data-change.js +44 -0
  49. package/src/methods/layer-config/index.js +7 -0
  50. package/src/methods/layer-list/first-updated.js +55 -0
  51. package/src/methods/layer-list/index.js +3 -0
  52. package/src/methods/layercontrol/first-update.js +22 -0
  53. package/src/methods/layercontrol/index.js +4 -0
  54. package/src/methods/layercontrol/layer-list-change.js +23 -0
  55. package/src/methods/optional-list/add-to-list.js +44 -0
  56. package/src/methods/optional-list/index.js +3 -0
  57. package/test/_mockMap.js +0 -154
  58. package/test/cases/general/check-layer-legend.js +0 -67
  59. package/test/cases/general/check-layer-size.js +0 -25
  60. package/test/cases/general/check-pre-open-layer-tools.js +0 -26
  61. package/test/cases/general/check-pre-open-section.js +0 -29
  62. package/test/cases/general/disable-drag.js +0 -26
  63. package/test/cases/general/empty-groups.js +0 -41
  64. package/test/cases/general/exclusive-layers.js +0 -35
  65. package/test/cases/general/hide-layers.js +0 -23
  66. package/test/cases/general/index.js +0 -10
  67. package/test/cases/general/render-optional-layer.js +0 -31
  68. package/test/cases/general/show-layer-title.js +0 -23
  69. package/test/cases/layer-update/add-external-layer.js +0 -96
  70. package/test/cases/layer-update/add-layer-from-optional.js +0 -51
  71. package/test/cases/layer-update/check-if-layer-pushed-to-group.js +0 -33
  72. package/test/cases/layer-update/check-layer-changed-event.js +0 -29
  73. package/test/cases/layer-update/check-layer-is-pushed-to-root.js +0 -22
  74. package/test/cases/layer-update/check-layer-removed-from-group.js +0 -33
  75. package/test/cases/layer-update/check-layer-removed-from-root.js +0 -27
  76. package/test/cases/layer-update/check-layer-size-after-multiple-calls.js +0 -34
  77. package/test/cases/layer-update/check-layer-zoom-state.js +0 -54
  78. package/test/cases/layer-update/index.js +0 -9
  79. package/test/general.cy.js +0 -61
  80. package/test/layersUpdate.cy.js +0 -72
package/package.json CHANGED
@@ -1,19 +1,14 @@
1
1
  {
2
2
  "name": "@eox/layercontrol",
3
- "version": "0.22.0",
3
+ "version": "0.23.0",
4
4
  "type": "module",
5
5
  "devDependencies": {
6
- "@eox/eslint-config": "^1.0.0",
7
6
  "@eox/jsonform": "latest",
8
7
  "@eox/map": "latest",
9
8
  "@eox/timecontrol": "latest",
10
9
  "@types/sortablejs": "^1.15.1",
11
- "@typescript-eslint/eslint-plugin": "^7.0.1",
12
- "@typescript-eslint/parser": "^7.0.1",
13
- "eslint-plugin-typescript": "^0.14.0",
14
10
  "ol": "^10.0.0",
15
11
  "sortablejs": "^1.15.0",
16
- "typescript": "^5.2.2",
17
12
  "vite": "^5.0.2"
18
13
  },
19
14
  "engines": {
@@ -22,22 +17,23 @@
22
17
  },
23
18
  "files": [
24
19
  "dist",
25
- "test"
20
+ "src"
26
21
  ],
27
- "main": "./dist/eox-layercontrol.js",
22
+ "main": "./src/main.js",
28
23
  "scripts": {
29
24
  "build": "vite build",
30
- "watch": "vite build --watch",
31
- "format": "prettier --write .",
32
- "lint": "eslint --ext .js,.ts .",
33
- "lint:fix": "eslint --ext .js,.ts . --fix",
34
- "typecheck": "tsc"
25
+ "watch": "vite build --watch"
35
26
  },
36
27
  "dependencies": {
28
+ "@eox/elements-utils": "^0.0.1",
37
29
  "color-legend-element": "^1.3.0",
38
30
  "dayjs": "^1.11.8",
39
31
  "lit": "^3.0.2",
40
32
  "lodash.throttle": "^4.1.1",
41
33
  "wms-capabilities": "^0.6.0"
34
+ },
35
+ "peerDependencies": {
36
+ "@eox/jsonform": "^0.8.2",
37
+ "@eox/timecontrol": "^0.8.0"
42
38
  }
43
39
  }
@@ -0,0 +1,416 @@
1
+ import { LitElement, html, nothing } from "lit";
2
+ import "./layer";
3
+ import "./layer-group";
4
+ import { isMapUrlValid, isLayerJSONValid } from "../helpers";
5
+ import {
6
+ addLayerMethod,
7
+ urlLayerMethod,
8
+ openCloseTabMethod,
9
+ wmsSearchURLMethod,
10
+ urlInputChangeMethod,
11
+ jsonInputChangeMethod,
12
+ } from "../methods/add-layer";
13
+
14
+ /**
15
+ * EOxLayerControlAddLayers is a class that extends LitElement and provides functionalities
16
+ * for managing layers on an OpenLayers map within an EOxMap context.
17
+ * It allows users to add WMS or XYZ layers to the map using URLs or JSON data.
18
+ * The class provides input fields to handle URLs and JSON, along with methods
19
+ * to validate and process the input for adding layers dynamically to the map.
20
+ *
21
+ * @element eox-layercontrol-add-layers
22
+ * @extends LitElement
23
+ */
24
+ export class EOxLayerControlAddLayers extends LitElement {
25
+ // Define static properties for the component
26
+ static properties = {
27
+ eoxMap: { attribute: false, state: true },
28
+ unstyled: { type: Boolean },
29
+ noShadow: { type: Boolean },
30
+ };
31
+
32
+ /**
33
+ * State for URL Input for WMS/XYZ URLs
34
+ *
35
+ * @type {String}
36
+ */
37
+ urlInput = null;
38
+
39
+ /**
40
+ * State for JSON Textarea - For EOxMap JSON
41
+ *
42
+ * @type {String}
43
+ */
44
+ jsonInput = null;
45
+
46
+ /**
47
+ * State for add layer - consist of url/json
48
+ *
49
+ * @type {"url" | "json" | null}
50
+ */
51
+ open = null;
52
+
53
+ /**
54
+ * Loader state when search is triggered
55
+ *
56
+ * @type {Boolean}
57
+ */
58
+ searchLoad = false;
59
+
60
+ /**
61
+ * State for `WMS Capabilities JSON`
62
+ *
63
+ * @type {import("wms-capabilities").WMSCapabilitiesJSON}
64
+ */
65
+ wmsCapabilities = null;
66
+
67
+ constructor() {
68
+ super();
69
+
70
+ /**
71
+ * Instance of `eox-map` which is a wrapper for the OL
72
+ *
73
+ * @type {import("@eox/map/main").EOxMap}
74
+ */
75
+ this.eoxMap = null;
76
+
77
+ /**
78
+ * Render the element without additional styles
79
+ *
80
+ * @type {Boolean}
81
+ */
82
+ this.unstyled = false;
83
+
84
+ /**
85
+ * Renders the element without a shadow root
86
+ *
87
+ * @type {Boolean}
88
+ */
89
+ this.noShadow = false;
90
+ }
91
+
92
+ /**
93
+ * Overrides the default behavior of creating the render root element.
94
+ * If 'noShadow' is set to true, returns 'this'; otherwise, falls back to the default behavior
95
+ * of creating a shadow root using 'super.createRenderRoot()'.
96
+ */
97
+ createRenderRoot() {
98
+ return this.noShadow ? this : super.createRenderRoot();
99
+ }
100
+
101
+ /**
102
+ * Handles changes in the input field by invoking the 'urlInputChangeMethod'.
103
+ * This method is triggered upon an @input change event.
104
+ *
105
+ * @param {Event} evt - The input change event triggering the method.
106
+ */
107
+ #handleURLChange(evt) {
108
+ urlInputChangeMethod(evt, this);
109
+ }
110
+
111
+ /**
112
+ * Asynchronously handles WMS URL search, invokes further processing if data is available.
113
+ */
114
+ async #handleWMSSearchURL() {
115
+ const data = await wmsSearchURLMethod(this);
116
+ if (data) this.#handleUrlLayerMethod(data);
117
+ }
118
+
119
+ /**
120
+ * Handles input field changes by triggering layer processing and adding layers.
121
+ *
122
+ * @param {{"Name": string}} layer - The layer information triggering the method.
123
+ */
124
+ #handleUrlLayerMethod(layer) {
125
+ urlLayerMethod(layer, this);
126
+ addLayerMethod(this);
127
+ }
128
+
129
+ /**
130
+ * Initiates the addition of layers, triggering the handleAddLayerMethod.
131
+ */
132
+ #handleAddLayer() {
133
+ addLayerMethod(this);
134
+ }
135
+
136
+ /**
137
+ * Handles input field changes by invoking the 'handleJsonInputChangeMethod'.
138
+ *
139
+ * @param {{target: { value: string }}} evt - The input change event triggering the method.
140
+ */
141
+ #handleInputChange(evt) {
142
+ jsonInputChangeMethod(evt, this);
143
+ }
144
+
145
+ /**
146
+ * Handles tab changes by invoking the 'openCloseTabMethod'.
147
+ *
148
+ * @param {"url" | "json" | null} tab - The tab identifier triggering the method.
149
+ */
150
+ #handleOpenCloseTab(tab) {
151
+ openCloseTabMethod(tab, this);
152
+ }
153
+
154
+ /**
155
+ * Renders the EOx Layer Control component with tabbed interface for URL and JSON.
156
+ * Handles input fields, search, and addition of layers.
157
+ */
158
+ render() {
159
+ // Determine classes and tab states based on 'open' property
160
+ const openCloseClassName = this.open ? "open" : "close";
161
+ const isUrlTabOpen = this.open === "url";
162
+ const isJsonTabOpen = this.open === "json";
163
+ const disableSearchBtn =
164
+ !isMapUrlValid(this.urlInput) || this.searchLoad ? true : nothing;
165
+
166
+ return html`
167
+ <style>
168
+ ${this.#styleBasic}
169
+ ${!this.unstyled && this.#styleEOX}
170
+ </style>
171
+ <div class="eox-add-layer-main">
172
+ <div class="eox-add-layer-col">
173
+ <!-- Tabbed interface for URL and JSON -->
174
+ <ul class="eox-add-layer-tab ${openCloseClassName}">
175
+ <li
176
+ @click=${() => this.#handleOpenCloseTab("url")}
177
+ class="${isUrlTabOpen ? "active" : ""}"
178
+ >
179
+ URL
180
+ </li>
181
+ <li
182
+ @click=${() => this.#handleOpenCloseTab("json")}
183
+ class="${isJsonTabOpen ? "active" : ""}"
184
+ >
185
+ JSON
186
+ </li>
187
+ </ul>
188
+
189
+ <!-- Button to toggle tabs -->
190
+ <button
191
+ class="add-icon icon"
192
+ @click=${() => this.#handleOpenCloseTab(!this.open ? "url" : null)}
193
+ >
194
+ ${this.unstyled ? "Add Layer" : ""}
195
+ </button>
196
+ </div>
197
+ <div class="eox-add ${openCloseClassName}">
198
+ ${isUrlTabOpen
199
+ ? html`
200
+ <!-- Input field for URL -->
201
+ <div class="eox-add-layer-col">
202
+ <input
203
+ type="text"
204
+ class="add-url"
205
+ placeholder="Add URL (WMS/XYZ)"
206
+ .value="${this.urlInput}"
207
+ @input=${this.#handleURLChange}
208
+ >
209
+ </input>
210
+ <!-- Search button for URL -->
211
+ <button
212
+ class="search-icon"
213
+ disabled=${disableSearchBtn}
214
+ @click=${this.#handleWMSSearchURL}
215
+ >
216
+ ${this.unstyled ? "Search" : ""}
217
+ </button>
218
+ </div>
219
+
220
+ <!-- Display layers for WMS capabilities -->
221
+ ${
222
+ this.wmsCapabilities
223
+ ? html`<ul class="search-lists">
224
+ ${this.wmsCapabilities.Capability.Layer.Layer.map(
225
+ (layer) => {
226
+ // @ts-expect-error TODO
227
+ const name = layer.Name;
228
+
229
+ return html`
230
+ <li class="search-list">
231
+ ${name}
232
+ <!-- Button to add layer -->
233
+ <button
234
+ class="add-layer-icon icon"
235
+ @click=${() =>
236
+ // @ts-expect-error TODO
237
+ this.#handleUrlLayerMethod(layer)}
238
+ >
239
+ ${this.unstyled ? "+" : ""}
240
+ </button>
241
+ </li>
242
+ `;
243
+ },
244
+ )}
245
+ </ul>`
246
+ : nothing
247
+ }
248
+ `
249
+ : html`
250
+ <!-- Textarea for JSON input -->
251
+ <textarea
252
+ class="add-layer-input"
253
+ placeholder="Please put a valid eox-map layer JSON."
254
+ @input=${this.#handleInputChange}
255
+ .value=${this.jsonInput}
256
+ ></textarea>
257
+
258
+ <!-- Button to add JSON layer -->
259
+ <button
260
+ class="add-layer-icon json-add-layer"
261
+ disabled=${isLayerJSONValid(this.jsonInput) ? nothing : true}
262
+ @click=${this.#handleAddLayer}
263
+ >
264
+ ${this.unstyled ? "Add JSON" : ""}
265
+ </button>
266
+ `}
267
+ </div>
268
+ </div>
269
+ `;
270
+ }
271
+
272
+ #styleBasic = `
273
+ .eox-add-layer-main .open {
274
+ position: relative;
275
+ }
276
+ .eox-add-layer-main .close {
277
+ display: none;
278
+ }
279
+ `;
280
+ #styleEOX = `
281
+ .eox-add {
282
+ background: #f0f2f5;
283
+ border-top: 1px solid #0041701a;
284
+ padding: 0.5rem;
285
+ font-size: small;
286
+ }
287
+ .eox-add-layer-col, .eox-add-layer-tab {
288
+ display: flex;
289
+ width: 100%;
290
+ }
291
+ .eox-add-layer-main .close {
292
+ display: none;
293
+ }
294
+ .eox-add-layer-main .open {
295
+ position: relative;
296
+ }
297
+ button.icon.add-icon {
298
+ flex-grow: 1;
299
+ }
300
+ .eox-add-layer-tab li {
301
+ border: 0 !important;
302
+ font-size: smaller;
303
+ padding: 0.2rem 0.7rem;
304
+ background: #f0f2f5;
305
+ border-radius: 4px 4px 0px 0px;
306
+ font-size: 0.8rem;
307
+ font-weight: 500;
308
+ cursor: pointer;
309
+ }
310
+ .eox-add-layer-tab li.active {
311
+ background: #204270;
312
+ color: white;
313
+ font-weight: 700;
314
+ }
315
+ .relative {
316
+ position: relative
317
+ }
318
+ .eox-add-layer-col.justify-end {
319
+ justify-content: end;
320
+ }
321
+ .eox-add ul {
322
+ max-height: 120px;
323
+ overflow: scroll;
324
+ }
325
+ .eox-add ul li {
326
+ display: flex;
327
+ align-items: center;
328
+ justify-content: space-between;
329
+ padding: 0.1rem 0.2rem;
330
+ }
331
+ button.icon {
332
+ justify-content: end;
333
+ transition: opacity .2s;
334
+ opacity: .7;
335
+ }
336
+ button.icon:hover {
337
+ opacity: 1;
338
+ }
339
+ button.icon.add-layer-icon::before {
340
+ width: 16px;
341
+ min-width: 16px;
342
+ height: 16px;
343
+ }
344
+ button.icon.add-icon::before {
345
+ width: 18px;
346
+ min-width: 18px;
347
+ height: 18px;
348
+ }
349
+ .add-icon.icon::before {
350
+ content: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath xmlns='http://www.w3.org/2000/svg' d='M17,14H19V17H22V19H19V22H17V19H14V17H17V14M11,16L2,9L11,2L20,9L11,16M11,18.54L12,17.75V18C12,18.71 12.12,19.39 12.35,20L11,21.07L2,14.07L3.62,12.81L11,18.54Z' fill='%23004270'/%3E%3C/svg%3E");
351
+ }
352
+ .add-layer-icon::before {
353
+ content: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Ctitle%3Eplus-thick%3C/title%3E%3Cpath fill='%23004270' d='M20 14H14V20H10V14H4V10H10V4H14V10H20V14Z' /%3E%3C/svg%3E");
354
+ }
355
+ .json-add-layer {
356
+ content: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Ctitle%3Eplus-thick%3C/title%3E%3Cpath fill='white' d='M20 14H14V20H10V14H4V10H10V4H14V10H20V14Z' /%3E%3C/svg%3E");
357
+ }
358
+ .search-icon::after {
359
+ content: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Ctitle%3Emagnify%3C/title%3E%3Cpath d='M9.5,3A6.5,6.5 0 0,1 16,9.5C16,11.11 15.41,12.59 14.44,13.73L14.71,14H15.5L20.5,19L19,20.5L14,15.5V14.71L13.73,14.44C12.59,15.41 11.11,16 9.5,16A6.5,6.5 0 0,1 3,9.5A6.5,6.5 0 0,1 9.5,3M9.5,5C7,5 5,7 5,9.5C5,12 7,14 9.5,14C12,14 14,12 14,9.5C14,7 12,5 9.5,5Z' fill='white' /%3E%3C/svg%3E");
360
+ }
361
+ .search-icon::after, .json-add-layer::before {
362
+ width: 14px;
363
+ min-width: 14px;
364
+ height: 14px;
365
+ display:flex
366
+ margin-right: 6px;
367
+ color: white;
368
+ }
369
+ .search-icon, .json-add-layer {
370
+ padding: 4px 6px;
371
+ height: 28px;
372
+ border-radius: 0px 4px 4px 0px;
373
+ box-shadow: none;
374
+ }
375
+ .json-add-layer {
376
+ position: absolute;
377
+ bottom: 16px;
378
+ right: 14px;
379
+ border-radius: 4px;
380
+ height: 24px;
381
+ padding: 4px;
382
+ }
383
+ input.add-url, textarea.add-layer-input {
384
+ box-sizing: border-box !important;
385
+ width: 100%;
386
+ height: 28px;
387
+ padding: 5px 7px !important;
388
+ border: 1px solid #0004 !important;
389
+ font-size: smaller;
390
+ border-radius: 4px 0px 0px 4px;
391
+ }
392
+ textarea.add-layer-input {
393
+ height: 90px;
394
+ resize: none;
395
+ border-radius: 4px;
396
+ }
397
+ .divider {
398
+ margin: 1rem 0px;
399
+ height: 1px;
400
+ border-top: 1.5px solid #00417059;
401
+ text-align: center;
402
+ position: relative;
403
+ }
404
+ .divider span {
405
+ position: relative;
406
+ top: -.6em;
407
+ padding: 0px 0.5rem;
408
+ background: #f0f2f5;
409
+ color: #00417059;
410
+ font-weight: bold;
411
+ display: inline-block;
412
+ }
413
+ `;
414
+ }
415
+
416
+ customElements.define("eox-layercontrol-add-layers", EOxLayerControlAddLayers);
@@ -0,0 +1,212 @@
1
+ import { LitElement, html, css } from "lit";
2
+ import { getLegendConfig } from "../helpers";
3
+ import { getStartVals } from "../helpers";
4
+ import { dataChangeMethod, applyUpdatedStyles } from "../methods/layer-config";
5
+ import { when } from "lit/directives/when.js";
6
+ import _throttle from "lodash.throttle";
7
+ import "./layer-legend";
8
+ /**
9
+ * `EOxLayerControlLayerConfig` is a component that handles configuration options for layers using eox-jsonform.
10
+ * It allows users to input data, modify layer settings, and update the UI based on those settings.
11
+ *
12
+ *
13
+ * @element eox-layercontrol-layerconfig
14
+ * @extends LitElement
15
+ */
16
+ export class EOxLayerControlLayerConfig extends LitElement {
17
+ // Define static properties for the component
18
+ static properties = {
19
+ layer: { attribute: false },
20
+ unstyled: { type: Boolean },
21
+ noShadow: { type: Boolean },
22
+ layerConfig: { attribute: false },
23
+ };
24
+
25
+ /**
26
+ * data input by the user
27
+ *
28
+ * @type {{[key: string]: any}}
29
+ */
30
+ #data = {};
31
+
32
+ /**
33
+ * data input by the user
34
+ *
35
+ * @type {{[key: string]: any}}
36
+ */
37
+ #startVals = null;
38
+
39
+ /**
40
+ * Original tile url function, if it exist
41
+ *
42
+ * @type {Function}
43
+ */
44
+ #originalTileUrlFunction;
45
+
46
+ constructor() {
47
+ super();
48
+
49
+ /**
50
+ * The native OL layer
51
+ *
52
+ * @type {import("ol/layer").Layer}
53
+ * @see {@link https://openlayers.org/en/latest/apidoc/module-ol_layer_Layer-Layer.html}
54
+ */
55
+ this.layer = null;
56
+
57
+ /**
58
+ * Render the element without additional styles
59
+ *
60
+ * @type {Boolean}
61
+ */
62
+ this.unstyled = false;
63
+
64
+ /**
65
+ * Renders the element without a shadow root
66
+ *
67
+ * @type {Boolean}
68
+ */
69
+ this.noShadow = false;
70
+
71
+ /**
72
+ * Layer config for eox-jsonform
73
+ *
74
+ * @type {{
75
+ * schema: Record<string,any>;
76
+ * element: string;
77
+ * type?:"tileUrl"|"style";
78
+ * style?:import("ol/layer/WebGLTile").Style
79
+ * legend?: Partial<import("./layer-legend").LegendConfig> & {
80
+ * range:string[];
81
+ * domainProperties:string[]
82
+ * }
83
+ * }}
84
+ */
85
+ this.layerConfig = null;
86
+
87
+ /**
88
+ * Throttle #handleDataChange() by 1000 milliseconds
89
+ */
90
+ this.throttleDataChange = _throttle(this.#handleDataChange, 1000);
91
+ }
92
+
93
+ /** Decide what type of throttling to do based on layerConfig type
94
+ *
95
+ * @param {import("lit").PropertyValues} changedProperties - The changed properties.
96
+ */
97
+ updated(changedProperties) {
98
+ if (changedProperties.has("layerConfig")) {
99
+ const throttleTime =
100
+ this.layerConfig.type === "style" || this.layerConfig.style
101
+ ? 100
102
+ : 1000;
103
+
104
+ this.throttleDataChange = _throttle(this.#handleDataChange, throttleTime);
105
+ this.requestUpdate();
106
+ }
107
+ }
108
+ /**
109
+ * Handles changes in eox-jsonform values.
110
+ *
111
+ * @param {{ detail: { value: string; }; }} e
112
+ */
113
+ #handleDataChange(e) {
114
+ this.#data = e.detail;
115
+ if (this.layerConfig.type === "style" || this.layerConfig.style) {
116
+ const supportStyleConfig =
117
+ "setStyle" in this.layer || "updateStyleVariables" in this.layer;
118
+ if (supportStyleConfig) {
119
+ applyUpdatedStyles(this.#data, this.layer, this.layerConfig);
120
+ } else {
121
+ console.error(
122
+ `Layer type ${
123
+ this.layer.get("type") ?? ""
124
+ } does not support styles configuration`,
125
+ );
126
+ }
127
+ } else {
128
+ this.#originalTileUrlFunction = dataChangeMethod(
129
+ this.#data,
130
+ this.#originalTileUrlFunction,
131
+ this,
132
+ );
133
+ }
134
+ this.requestUpdate();
135
+ }
136
+
137
+ /**
138
+ * Overrides createRenderRoot to handle shadow DOM creation based on the noShadow property.
139
+ */
140
+ createRenderRoot() {
141
+ return this.noShadow ? this : super.createRenderRoot();
142
+ }
143
+
144
+ /**
145
+ * Renders a JSON form for configuration options of a layer.
146
+ */
147
+ render() {
148
+ // Fetch initial values for the layer and its configuration
149
+ this.#startVals = getStartVals(this.layer, this.layerConfig);
150
+ if (Object.keys(this.#data).length !== 0) {
151
+ this.#startVals = this.#data;
152
+ }
153
+ if (!customElements.get("eox-jsonform")) {
154
+ console.error("Please import @eox/jsonform in order to use layerconfig");
155
+ }
156
+
157
+ // Options for the JSON form rendering
158
+ const options = {
159
+ disable_edit_json: true,
160
+ disable_collapse: true,
161
+ disable_properties: true,
162
+ };
163
+ return html`
164
+ <style>
165
+ ${this.#styleBasic}
166
+ ${!this.unstyled && this.#styleEOX}
167
+ </style>
168
+ ${when(
169
+ this.layerConfig,
170
+ () => html`
171
+ ${when(
172
+ this.layerConfig.legend,
173
+ () => html`
174
+ <eox-layercontrol-layer-legend
175
+ .noShadow=${true}
176
+ .unstyled=${this.unstyled}
177
+ .layer=${this.layer}
178
+ .layerLegend=${getLegendConfig(
179
+ this.layerConfig.legend,
180
+ this.#data,
181
+ )}
182
+ ></eox-layercontrol-layer-legend>
183
+ `,
184
+ )}
185
+ <!-- Render a JSON form for layer configuration -->
186
+ <eox-jsonform
187
+ .schema=${this.layerConfig.schema}
188
+ .value=${this.#startVals}
189
+ .options=${options}
190
+ @change=${this.throttleDataChange}
191
+ ></eox-jsonform>
192
+ `,
193
+ )}
194
+ `;
195
+ }
196
+
197
+ #styleBasic = css`
198
+ color-legend {
199
+ --cle-background: transparent;
200
+ --cle-font-family: inherit;
201
+ --cle-font-size: inherit;
202
+ --cle-font-weight: inherit --cle-letter-spacing: inherit;
203
+ --cle-letter-spacing-title: inherit;
204
+ }
205
+ `;
206
+ #styleEOX = ``;
207
+ }
208
+
209
+ customElements.define(
210
+ "eox-layercontrol-layerconfig",
211
+ EOxLayerControlLayerConfig,
212
+ );