@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,353 @@
|
|
|
1
|
+
import { LitElement, html, nothing } from "lit";
|
|
2
|
+
import { unsafeHTML } from "lit/directives/unsafe-html.js";
|
|
3
|
+
import { map } from "lit/directives/map.js";
|
|
4
|
+
import { when } from "lit/directives/when.js";
|
|
5
|
+
import { live } from "lit/directives/live.js";
|
|
6
|
+
import "./layer-config";
|
|
7
|
+
import "./layer-datetime";
|
|
8
|
+
import "./layer-legend";
|
|
9
|
+
import "./tools-items";
|
|
10
|
+
import { button } from "@eox/elements-utils/styles/button";
|
|
11
|
+
import { radio } from "@eox/elements-utils/styles/radio";
|
|
12
|
+
import { checkbox } from "@eox/elements-utils/styles/checkbox";
|
|
13
|
+
import { slider } from "@eox/elements-utils/styles/slider";
|
|
14
|
+
import {
|
|
15
|
+
Button,
|
|
16
|
+
_parseActions,
|
|
17
|
+
_parseTools,
|
|
18
|
+
removeButton,
|
|
19
|
+
sortButton,
|
|
20
|
+
} from "../helpers";
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* EOxLayerControlLayerTools - Custom element to display tools and actions for a given OpenLayers layer.
|
|
24
|
+
* Manages rendering tools and actions such as remove, sort, information display, layer configuration, and opacity adjustment.
|
|
25
|
+
*
|
|
26
|
+
* @element eox-layercontrol-layer-tools
|
|
27
|
+
* @extends LitElement
|
|
28
|
+
*/
|
|
29
|
+
export class EOxLayerControlLayerTools extends LitElement {
|
|
30
|
+
// Define static properties for the component
|
|
31
|
+
static properties = {
|
|
32
|
+
layer: { attribute: false },
|
|
33
|
+
tools: { attribute: false },
|
|
34
|
+
unstyled: { type: Boolean },
|
|
35
|
+
noShadow: { type: Boolean },
|
|
36
|
+
toolsAsList: { type: Boolean },
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
constructor() {
|
|
40
|
+
super();
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* The native OL layer
|
|
44
|
+
*
|
|
45
|
+
* @type {import("ol/layer").Layer}
|
|
46
|
+
* @see {@link https://openlayers.org/en/latest/apidoc/module-ol_layer_Layer-Layer.html}
|
|
47
|
+
*/
|
|
48
|
+
this.layer = null;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Represents an array of tools.
|
|
52
|
+
*
|
|
53
|
+
* @type {Array<string>}
|
|
54
|
+
*/
|
|
55
|
+
this.tools = [];
|
|
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
|
+
* If enabled, the tools section will be rendered as list.
|
|
73
|
+
*
|
|
74
|
+
* @type {Boolean}
|
|
75
|
+
*/
|
|
76
|
+
this.toolsAsList = false;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Overrides createRenderRoot to handle shadow DOM creation based on the noShadow property.
|
|
81
|
+
*/
|
|
82
|
+
createRenderRoot() {
|
|
83
|
+
return this.noShadow ? this : super.createRenderRoot();
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Initializes '_removeButton' invoking 'removeButton' function with 'this' context.
|
|
87
|
+
_removeButton = () => removeButton(this);
|
|
88
|
+
|
|
89
|
+
// Initializes '_sortButton' invoking 'sortButton' function with 'unstyled' property as a parameter.
|
|
90
|
+
_sortButton = () => sortButton(this.unstyled);
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Initializes '_button' as a function accepting 'tool' parameter to generate a Button.
|
|
94
|
+
* Uses 'this.unstyled' as a context parameter for Button generation.
|
|
95
|
+
*
|
|
96
|
+
* @param {string} tool - Tool parameter for Button generation.
|
|
97
|
+
* @returns {import("lit").HTMLTemplateResult} - The generated Button element.
|
|
98
|
+
*/
|
|
99
|
+
_button = (tool) => Button(tool, this.unstyled);
|
|
100
|
+
|
|
101
|
+
_getDefaultTools = () => {
|
|
102
|
+
return html`
|
|
103
|
+
<div slot="info-content">
|
|
104
|
+
${unsafeHTML(this.layer.get("description"))}
|
|
105
|
+
</div>
|
|
106
|
+
<div slot="opacity-content">
|
|
107
|
+
<!-- Input for opacity -->
|
|
108
|
+
<input
|
|
109
|
+
type="range"
|
|
110
|
+
min="0"
|
|
111
|
+
max="1"
|
|
112
|
+
step="0.01"
|
|
113
|
+
value=${live(this.layer?.getOpacity())}
|
|
114
|
+
@input=${(/** @type {{ target: { value: string; }; }} */ evt) =>
|
|
115
|
+
this.layer.setOpacity(parseFloat(evt.target.value))}
|
|
116
|
+
/>
|
|
117
|
+
</div>
|
|
118
|
+
<div slot="config-content">
|
|
119
|
+
<!-- Layer configuration -->
|
|
120
|
+
${when(
|
|
121
|
+
this.layer.get("layerConfig"),
|
|
122
|
+
() => html`
|
|
123
|
+
<eox-layercontrol-layerconfig
|
|
124
|
+
slot="config-content"
|
|
125
|
+
.layer=${this.layer}
|
|
126
|
+
.noShadow=${true}
|
|
127
|
+
.layerConfig=${this.layer.get("layerConfig")}
|
|
128
|
+
.unstyled=${this.unstyled}
|
|
129
|
+
@changed=${() => this.requestUpdate()}
|
|
130
|
+
></eox-layercontrol-layerconfig>
|
|
131
|
+
`,
|
|
132
|
+
)}
|
|
133
|
+
</div>
|
|
134
|
+
<div slot="datetime-content">
|
|
135
|
+
<!-- Layer datetime -->
|
|
136
|
+
${when(
|
|
137
|
+
this.layer.get("layerDatetime"),
|
|
138
|
+
() => html`
|
|
139
|
+
<eox-layercontrol-layer-datetime
|
|
140
|
+
slot="datetime-content"
|
|
141
|
+
.noShadow=${true}
|
|
142
|
+
.layerDatetime=${this.layer.get("layerDatetime")}
|
|
143
|
+
.layer=${this.layer}
|
|
144
|
+
.unstyled=${this.unstyled}
|
|
145
|
+
@changed=${() => this.requestUpdate()}
|
|
146
|
+
></eox-layercontrol-layer-datetime>
|
|
147
|
+
`,
|
|
148
|
+
)}
|
|
149
|
+
</div>
|
|
150
|
+
<div slot="legend-content">
|
|
151
|
+
<!-- Layer legend -->
|
|
152
|
+
${when(
|
|
153
|
+
this.layer.get("layerLegend"),
|
|
154
|
+
() => html`
|
|
155
|
+
<eox-layercontrol-layer-legend
|
|
156
|
+
slot="legend-content"
|
|
157
|
+
.noShadow=${true}
|
|
158
|
+
.layerLegend=${this.layer.get("layerLegend")}
|
|
159
|
+
.layer=${this.layer}
|
|
160
|
+
.unstyled=${this.unstyled}
|
|
161
|
+
@changed=${() => this.requestUpdate()}
|
|
162
|
+
></eox-layercontrol-layer-legend>
|
|
163
|
+
`,
|
|
164
|
+
)}
|
|
165
|
+
</div>
|
|
166
|
+
<div slot="remove-icon">${this._removeButton()}</div>
|
|
167
|
+
<div slot="sort-icon">${this._sortButton()}</div>
|
|
168
|
+
`;
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
render() {
|
|
172
|
+
// Obtain actions and tools based on this.tools and this.layer
|
|
173
|
+
const actions = _parseActions(this.tools, this.layer);
|
|
174
|
+
const tools = _parseTools(this.tools, this.layer);
|
|
175
|
+
|
|
176
|
+
// Determine the single action element if only one action is present
|
|
177
|
+
// @ts-expect-error TODO
|
|
178
|
+
const singleActionEle = this[`_${actions?.[0]}Button`]
|
|
179
|
+
? // @ts-expect-error TODO
|
|
180
|
+
this[`_${actions?.[0]}Button`]()
|
|
181
|
+
: nothing;
|
|
182
|
+
|
|
183
|
+
// Determine icon class based on the number of tools
|
|
184
|
+
const iconClass = this.tools?.length === 1 ? `${this.tools[0]}-icon` : "";
|
|
185
|
+
|
|
186
|
+
// Determine the number of actions and tools for conditional rendering
|
|
187
|
+
const actionsLen = actions?.length;
|
|
188
|
+
const toolsLen = tools?.length;
|
|
189
|
+
// Render the HTML template based on the conditions
|
|
190
|
+
return html`
|
|
191
|
+
<style>
|
|
192
|
+
${this.#styleBasic}
|
|
193
|
+
${!this.unstyled && this.#styleEOX}
|
|
194
|
+
</style>
|
|
195
|
+
${when(
|
|
196
|
+
actionsLen + toolsLen > 0,
|
|
197
|
+
() => html`
|
|
198
|
+
${when(
|
|
199
|
+
actionsLen === 1 && toolsLen === 0,
|
|
200
|
+
() => html`
|
|
201
|
+
<div class="single-action-container">
|
|
202
|
+
<div class="single-action">${singleActionEle}</div>
|
|
203
|
+
</div>
|
|
204
|
+
`,
|
|
205
|
+
() => html`
|
|
206
|
+
<details
|
|
207
|
+
class="tools"
|
|
208
|
+
open=${this.layer.get("layerControlToolsExpand") || nothing}
|
|
209
|
+
>
|
|
210
|
+
<summary>
|
|
211
|
+
<button class="icon ${iconClass}">Tools</button>
|
|
212
|
+
</summary>
|
|
213
|
+
<eox-layercontrol-tools-items
|
|
214
|
+
class="${this.toolsAsList ? "tools-list" : "tools-tab"}"
|
|
215
|
+
.noShadow=${false}
|
|
216
|
+
.actions=${actions}
|
|
217
|
+
.tabs=${tools}
|
|
218
|
+
.unstyled=${this.unstyled}
|
|
219
|
+
.toolsAsList=${this.toolsAsList}
|
|
220
|
+
>
|
|
221
|
+
<!-- Rendering tabs and content -->
|
|
222
|
+
${map(tools, (tool) => this._button(tool))}
|
|
223
|
+
<!-- Including default tools -->
|
|
224
|
+
${this._getDefaultTools()}
|
|
225
|
+
</eox-layercontrol-tools-items>
|
|
226
|
+
</details>
|
|
227
|
+
`,
|
|
228
|
+
)}
|
|
229
|
+
`,
|
|
230
|
+
)}
|
|
231
|
+
`;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
#styleBasic = ``;
|
|
235
|
+
|
|
236
|
+
#styleEOX = `
|
|
237
|
+
${button}
|
|
238
|
+
${radio}
|
|
239
|
+
${checkbox}
|
|
240
|
+
${slider}
|
|
241
|
+
.drag-handle {
|
|
242
|
+
cursor: n-resize;
|
|
243
|
+
}
|
|
244
|
+
.single-action-container,
|
|
245
|
+
details.tools {
|
|
246
|
+
position: relative;
|
|
247
|
+
}
|
|
248
|
+
eox-layercontrol-layer details summary::before {
|
|
249
|
+
content: "";
|
|
250
|
+
}
|
|
251
|
+
details.tools[open] {
|
|
252
|
+
/*border-top: 1px solid #0041703a;*/
|
|
253
|
+
}
|
|
254
|
+
.single-action {
|
|
255
|
+
position: relative;
|
|
256
|
+
}
|
|
257
|
+
details.tools summary .icon {
|
|
258
|
+
pointer-events: none;
|
|
259
|
+
}
|
|
260
|
+
.single-action,
|
|
261
|
+
details.tools summary {
|
|
262
|
+
position: absolute;
|
|
263
|
+
right: 0;
|
|
264
|
+
top: -24px;
|
|
265
|
+
display: flex;
|
|
266
|
+
border-radius: 4px;
|
|
267
|
+
cursor: pointer;
|
|
268
|
+
}
|
|
269
|
+
.single-action .icon::before,
|
|
270
|
+
details.tools summary .icon::before {
|
|
271
|
+
content: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='%23004170' viewBox='0 0 24 24'%3E%3Ctitle%3Edots-vertical%3C/title%3E%3Cpath d='M12,16A2,2 0 0,1 14,18A2,2 0 0,1 12,20A2,2 0 0,1 10,18A2,2 0 0,1 12,16M12,10A2,2 0 0,1 14,12A2,2 0 0,1 12,14A2,2 0 0,1 10,12A2,2 0 0,1 12,10M12,4A2,2 0 0,1 14,6A2,2 0 0,1 12,8A2,2 0 0,1 10,6A2,2 0 0,1 12,4Z' /%3E%3C/svg%3E");
|
|
272
|
+
}
|
|
273
|
+
.single-action,
|
|
274
|
+
details.tools summary,
|
|
275
|
+
eox-layercontrol-tools-items button.icon {
|
|
276
|
+
transition: opacity .2s;
|
|
277
|
+
}
|
|
278
|
+
.single-action,
|
|
279
|
+
details.tools summary {
|
|
280
|
+
opacity: .5;
|
|
281
|
+
}
|
|
282
|
+
eox-layercontrol-tools-items button.icon {
|
|
283
|
+
opacity: .7;
|
|
284
|
+
}
|
|
285
|
+
eox-layercontrol-tools-items.tools-list button.icon {
|
|
286
|
+
cursor: auto;
|
|
287
|
+
}
|
|
288
|
+
.single-action:hover,
|
|
289
|
+
details.tools summary:hover,
|
|
290
|
+
eox-layercontrol-tools-items button.icon:hover {
|
|
291
|
+
opacity: 1;
|
|
292
|
+
}
|
|
293
|
+
eox-layercontrol-tools-items.tools-list button.icon:hover {
|
|
294
|
+
opacity: .7;
|
|
295
|
+
}
|
|
296
|
+
.tools-placeholder,
|
|
297
|
+
.single-action .icon,
|
|
298
|
+
.single-action .icon::before,
|
|
299
|
+
details.tools summary .icon,
|
|
300
|
+
details.tools summary .icon::before {
|
|
301
|
+
height: 16px;
|
|
302
|
+
width: 16px;
|
|
303
|
+
margin-right: var(--padding);
|
|
304
|
+
}
|
|
305
|
+
eox-layercontrol-tools-items button.icon,
|
|
306
|
+
eox-layercontrol-tools-items .button.icon {
|
|
307
|
+
display: flex;
|
|
308
|
+
justify-content: center;
|
|
309
|
+
}
|
|
310
|
+
eox-layercontrol-tools-items button.icon::before,
|
|
311
|
+
eox-layercontrol-tools-items .button.icon::before {
|
|
312
|
+
width: 16px;
|
|
313
|
+
height: 16px;
|
|
314
|
+
}
|
|
315
|
+
details.tools summary .info-icon,
|
|
316
|
+
button.icon[slot=info-icon]::before {
|
|
317
|
+
content: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='%23004170' viewBox='0 0 24 24'%3E%3Ctitle%3Einformation-outline%3C/title%3E%3Cpath d='M11,9H13V7H11M12,20C7.59,20 4,16.41 4,12C4,7.59 7.59,4 12,4C16.41,4 20,7.59 20,12C20,16.41 16.41,20 12,20M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10,10 0 0,0 12,2M11,17H13V11H11V17Z' /%3E%3C/svg%3E");
|
|
318
|
+
}
|
|
319
|
+
details.tools summary .opacity-icon,
|
|
320
|
+
button.icon[slot=opacity-icon]::before {
|
|
321
|
+
content: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='%23004170' viewBox='0 0 24 24'%3E%3Ctitle%3Eopacity%3C/title%3E%3Cpath d='M17.66,8L12,2.35L6.34,8C4.78,9.56 4,11.64 4,13.64C4,15.64 4.78,17.75 6.34,19.31C7.9,20.87 9.95,21.66 12,21.66C14.05,21.66 16.1,20.87 17.66,19.31C19.22,17.75 20,15.64 20,13.64C20,11.64 19.22,9.56 17.66,8M6,14C6,12 6.62,10.73 7.76,9.6L12,5.27L16.24,9.65C17.38,10.77 18,12 18,14H6Z' /%3E%3C/svg%3E");
|
|
322
|
+
}
|
|
323
|
+
details.tools summary .config-icon,
|
|
324
|
+
button.icon[slot=config-icon]::before {
|
|
325
|
+
content: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='%23004170' viewBox='0 0 24 24'%3E%3Ctitle%3Etune%3C/title%3E%3Cpath d='M3,17V19H9V17H3M3,5V7H13V5H3M13,21V19H21V17H13V15H11V21H13M7,9V11H3V13H7V15H9V9H7M21,13V11H11V13H21M15,9H17V7H21V5H17V3H15V9Z' /%3E%3C/svg%3E");
|
|
326
|
+
}
|
|
327
|
+
details.tools summary .datetime-icon,
|
|
328
|
+
button.icon[slot=datetime-icon]::before {
|
|
329
|
+
content: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Ctitle%3Eclock-outline%3C/title%3E%3Cpath d='M12,20A8,8 0 0,0 20,12A8,8 0 0,0 12,4A8,8 0 0,0 4,12A8,8 0 0,0 12,20M12,2A10,10 0 0,1 22,12A10,10 0 0,1 12,22C6.47,22 2,17.5 2,12A10,10 0 0,1 12,2M12.5,7V12.25L17,14.92L16.25,16.15L11,13V7H12.5Z' /%3E%3C/svg%3E");
|
|
330
|
+
}
|
|
331
|
+
details.tools summary .legend-icon,
|
|
332
|
+
button.icon[slot=legend-icon]::before {
|
|
333
|
+
content: url("data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%2024%2024%22%3E%3Ctitle%3Emap-legend%3C%2Ftitle%3E%3Cpath%20d%3D%22M9%2C3L3.36%2C4.9C3.15%2C4.97%203%2C5.15%203%2C5.38V20.5A0.5%2C0.5%200%200%2C0%203.5%2C21L3.66%2C20.97L9%2C18.9L15%2C21L20.64%2C19.1C20.85%2C19.03%2021%2C18.85%2021%2C18.62V3.5A0.5%2C0.5%200%200%2C0%2020.5%2C3L20.34%2C3.03L15%2C5.1L9%2C3M8%2C5.45V17.15L5%2C18.31V6.46L8%2C5.45M10%2C5.47L14%2C6.87V18.53L10%2C17.13V5.47M19%2C5.7V17.54L16%2C18.55V6.86L19%2C5.7M7.46%2C6.3L5.57%2C6.97V9.12L7.46%2C8.45V6.3M7.46%2C9.05L5.57%2C9.72V11.87L7.46%2C11.2V9.05M7.46%2C11.8L5.57%2C12.47V14.62L7.46%2C13.95V11.8M7.46%2C14.55L5.57%2C15.22V17.37L7.46%2C16.7V14.55Z%22%20%2F%3E%3C%2Fsvg%3E");
|
|
334
|
+
}
|
|
335
|
+
.single-action .remove-icon::before,
|
|
336
|
+
[slot=remove-icon] button.icon::before {
|
|
337
|
+
content: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='%23ff0000' viewBox='0 0 24 24'%3E%3Ctitle%3Edelete-outline%3C/title%3E%3Cpath d='M6,19A2,2 0 0,0 8,21H16A2,2 0 0,0 18,19V7H6V19M8,9H16V19H8V9M15.5,4L14.5,3H9.5L8.5,4H5V6H19V4H15.5Z' /%3E%3C/svg%3E");
|
|
338
|
+
}
|
|
339
|
+
.single-action .sort-icon::before,
|
|
340
|
+
[slot=sort-icon] .button.icon::before {
|
|
341
|
+
content: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='%23004170' viewBox='0 0 24 24'%3E%3Ctitle%3Edrag-horizontal-variant%3C/title%3E%3Cpath d='M21 11H3V9H21V11M21 13H3V15H21V13Z' /%3E%3C/svg%3E");
|
|
342
|
+
}
|
|
343
|
+
[slot=info-content],
|
|
344
|
+
[slot=opacity-content] {
|
|
345
|
+
padding: 12px 6px;
|
|
346
|
+
}
|
|
347
|
+
`;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
customElements.define(
|
|
351
|
+
"eox-layercontrol-layer-tools",
|
|
352
|
+
EOxLayerControlLayerTools,
|
|
353
|
+
);
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import { LitElement, html } from "lit";
|
|
2
|
+
import { when } from "lit/directives/when.js";
|
|
3
|
+
import { live } from "lit/directives/live.js";
|
|
4
|
+
import "./layer-tools";
|
|
5
|
+
import { checkbox } from "@eox/elements-utils/styles/checkbox";
|
|
6
|
+
import { firstUpdatedMethod, inputClickMethod } from "../methods/layer";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* `EOxLayerControlLayer` represents a custom web component managing individual layers within the EOxLayerControl system.
|
|
10
|
+
* This component encapsulates functionalities for handling layers, their properties, and associated tools within the OpenLayers map context.
|
|
11
|
+
*
|
|
12
|
+
* @element eox-layercontrol-layer
|
|
13
|
+
* @extends LitElement
|
|
14
|
+
*/
|
|
15
|
+
export class EOxLayerControlLayer extends LitElement {
|
|
16
|
+
// Define static properties for the component
|
|
17
|
+
static properties = {
|
|
18
|
+
layer: { attribute: false },
|
|
19
|
+
map: { attribute: false, state: true },
|
|
20
|
+
titleProperty: { attribute: "title-property", type: String },
|
|
21
|
+
showLayerZoomState: { attribute: "show-layer-zoom-state", type: Boolean },
|
|
22
|
+
tools: { attribute: false },
|
|
23
|
+
unstyled: { type: Boolean },
|
|
24
|
+
noShadow: { type: Boolean },
|
|
25
|
+
toolsAsList: { type: Boolean },
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Represents the current layer visibility based on zoom level.
|
|
30
|
+
*
|
|
31
|
+
* @type {Boolean}
|
|
32
|
+
*/
|
|
33
|
+
currLayerVisibilityBasedOnZoom = true;
|
|
34
|
+
|
|
35
|
+
constructor() {
|
|
36
|
+
super();
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* The native OL layer
|
|
40
|
+
*
|
|
41
|
+
* @type {import("ol/layer").Layer}
|
|
42
|
+
* @see {@link https://openlayers.org/en/latest/apidoc/module-ol_layer_Layer-Layer.html}
|
|
43
|
+
*/
|
|
44
|
+
this.layer = null;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* The native OL map
|
|
48
|
+
*
|
|
49
|
+
* @type {import("ol").Map}
|
|
50
|
+
* @see {@link https://openlayers.org/en/latest/apidoc/module-ol_Map-Map.html}
|
|
51
|
+
*/
|
|
52
|
+
this.map = null;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* The layer title property
|
|
56
|
+
*
|
|
57
|
+
* @type {String}
|
|
58
|
+
*/
|
|
59
|
+
this.titleProperty = "title";
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Show layer state based on zoom level or not
|
|
63
|
+
*
|
|
64
|
+
* @type {Boolean}
|
|
65
|
+
*/
|
|
66
|
+
this.showLayerZoomState = false;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Represents an array of tools.
|
|
70
|
+
*
|
|
71
|
+
* @type {Array<string>}
|
|
72
|
+
*/
|
|
73
|
+
this.tools = [];
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Render the element without additional styles
|
|
77
|
+
*
|
|
78
|
+
* @type {Boolean}
|
|
79
|
+
*/
|
|
80
|
+
this.unstyled = false;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Renders the element without a shadow root
|
|
84
|
+
*
|
|
85
|
+
* @type {Boolean}
|
|
86
|
+
*/
|
|
87
|
+
this.noShadow = false;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* If enabled, the tools section will be rendered as list.
|
|
91
|
+
*
|
|
92
|
+
* @type {Boolean}
|
|
93
|
+
*/
|
|
94
|
+
this.toolsAsList = false;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Private method to get layer property by key if available.
|
|
99
|
+
*
|
|
100
|
+
* @param {string} key - The key for the layer property.
|
|
101
|
+
* @returns {any} - The value of the layer property if exists, otherwise undefined.
|
|
102
|
+
*/
|
|
103
|
+
#getLayer(key) {
|
|
104
|
+
return this.layer?.get(key);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Overrides createRenderRoot to handle shadow DOM creation based on the noShadow property.
|
|
109
|
+
*/
|
|
110
|
+
createRenderRoot() {
|
|
111
|
+
return this.noShadow ? this : super.createRenderRoot();
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Check and update layer zoom visibility at beginning
|
|
116
|
+
* and register "change:resolution" ones at the beginning if `showLayerZoomState` is present
|
|
117
|
+
*/
|
|
118
|
+
firstUpdated() {
|
|
119
|
+
firstUpdatedMethod(this);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Handles the click event on the input element triggering the method.
|
|
124
|
+
*
|
|
125
|
+
* @param {{target: { checked: boolean }}} evt - The input change event.
|
|
126
|
+
*/
|
|
127
|
+
#handleInputClick(evt) {
|
|
128
|
+
inputClickMethod(evt, this);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Renders layer controls and tools with conditional display based on certain properties.
|
|
133
|
+
* Conditionally renders layer visibility controls, title, and tools for the layer based on availability and settings.
|
|
134
|
+
* Styles are applied conditionally based on the 'unstyled' property.
|
|
135
|
+
*/
|
|
136
|
+
render() {
|
|
137
|
+
// Retrieve the visibility of the layer
|
|
138
|
+
const visibility = this.layer.getVisible();
|
|
139
|
+
|
|
140
|
+
// Apply CSS classes based on the visibility and zoom state of the layer
|
|
141
|
+
const visibilityClass = visibility ? "visible" : "";
|
|
142
|
+
const layerZoomStateClass = !this.currLayerVisibilityBasedOnZoom
|
|
143
|
+
? "zoom-state-invisible"
|
|
144
|
+
: "";
|
|
145
|
+
|
|
146
|
+
// Determine if the layer is disabled based on a specific control property
|
|
147
|
+
const disableClass = this.#getLayer("layerControlDisable")
|
|
148
|
+
? "disabled"
|
|
149
|
+
: "";
|
|
150
|
+
|
|
151
|
+
// Determine the input type (radio or checkbox) based on a specific control property
|
|
152
|
+
const inputType = this.#getLayer("layerControlExclusive")
|
|
153
|
+
? "radio"
|
|
154
|
+
: "checkbox";
|
|
155
|
+
|
|
156
|
+
// Check if tools are available for the layer
|
|
157
|
+
const isToolsAvail = this.tools?.length > 0;
|
|
158
|
+
|
|
159
|
+
return html`
|
|
160
|
+
<style>
|
|
161
|
+
${this.#styleBasic}
|
|
162
|
+
${!this.unstyled && this.#styleEOX}
|
|
163
|
+
</style>
|
|
164
|
+
${when(
|
|
165
|
+
this.layer,
|
|
166
|
+
() => html`
|
|
167
|
+
<!-- Render the layer -->
|
|
168
|
+
<div class="layer ${visibilityClass} ${layerZoomStateClass}">
|
|
169
|
+
<label class="drag-handle ${disableClass}">
|
|
170
|
+
<!-- Input element for layer visibility -->
|
|
171
|
+
<input
|
|
172
|
+
type=${inputType}
|
|
173
|
+
.checked=${live(visibility)}
|
|
174
|
+
@click=${this.#handleInputClick}
|
|
175
|
+
/>
|
|
176
|
+
|
|
177
|
+
<!-- Layer title -->
|
|
178
|
+
<span class="title">${this.#getLayer(this.titleProperty)}</span>
|
|
179
|
+
${when(
|
|
180
|
+
isToolsAvail,
|
|
181
|
+
() => html`<span class="tools-placeholder"></span>`,
|
|
182
|
+
)}
|
|
183
|
+
</label>
|
|
184
|
+
</div>
|
|
185
|
+
|
|
186
|
+
<!-- Render layer tools -->
|
|
187
|
+
<eox-layercontrol-layer-tools
|
|
188
|
+
.noShadow=${true}
|
|
189
|
+
.layer=${this.layer}
|
|
190
|
+
.tools=${this.tools}
|
|
191
|
+
.unstyled=${this.unstyled}
|
|
192
|
+
.toolsAsList=${this.toolsAsList}
|
|
193
|
+
></eox-layercontrol-layer-tools>
|
|
194
|
+
`,
|
|
195
|
+
)}
|
|
196
|
+
`;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
#styleBasic = ``;
|
|
200
|
+
#styleEOX = `
|
|
201
|
+
${checkbox}
|
|
202
|
+
eox-layercontrol-layer {
|
|
203
|
+
width: 100%;
|
|
204
|
+
}
|
|
205
|
+
.layer.zoom-state-invisible {
|
|
206
|
+
background: #d2e2ee;
|
|
207
|
+
opacity: 0.3;
|
|
208
|
+
}
|
|
209
|
+
.layer {
|
|
210
|
+
width: 100%;
|
|
211
|
+
align-items: center;
|
|
212
|
+
justify-content: space-between;
|
|
213
|
+
padding: 4px 0;
|
|
214
|
+
}
|
|
215
|
+
label, span {
|
|
216
|
+
display: flex;
|
|
217
|
+
align-items: center;
|
|
218
|
+
cursor: pointer;
|
|
219
|
+
}
|
|
220
|
+
[data-type] .title::before {
|
|
221
|
+
width: 20px;
|
|
222
|
+
min-width: 20px;
|
|
223
|
+
height: 20px;
|
|
224
|
+
margin-right: 6px;
|
|
225
|
+
}
|
|
226
|
+
[data-type=group] .title::before {
|
|
227
|
+
content: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='%230041703a' viewBox='0 0 24 24'%3E%3Ctitle%3Efolder-outline%3C/title%3E%3Cpath d='M20,18H4V8H20M20,6H12L10,4H4C2.89,4 2,4.89 2,6V18A2,2 0 0,0 4,20H20A2,2 0 0,0 22,18V8C22,6.89 21.1,6 20,6Z' /%3E%3C/svg%3E");
|
|
228
|
+
}
|
|
229
|
+
[data-type=group] > eox-layercontrol-layer-group > details[open] > summary > eox-layercontrol-layer > .layer > label > .title::before {
|
|
230
|
+
content: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='%230041703a' viewBox='0 0 24 24'%3E%3Ctitle%3Efolder-open-outline%3C/title%3E%3Cpath d='M6.1,10L4,18V8H21A2,2 0 0,0 19,6H12L10,4H4A2,2 0 0,0 2,6V18A2,2 0 0,0 4,20H19C19.9,20 20.7,19.4 20.9,18.5L23.2,10H6.1M19,18H6L7.6,12H20.6L19,18Z' /%3E%3C/svg%3E");
|
|
231
|
+
}
|
|
232
|
+
[data-type=raster] .title::before {
|
|
233
|
+
content: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='%230041703a' viewBox='0 0 24 24'%3E%3Ctitle%3Echeckerboard%3C/title%3E%3Cpath d='M2 2V22H22V2H2M20 12H16V16H20V20H16V16H12V20H8V16H4V12H8V8H4V4H8V8H12V4H16V8H20V12M16 8V12H12V8H16M12 12V16H8V12H12Z' /%3E%3C/svg%3E");
|
|
234
|
+
}
|
|
235
|
+
[data-type=vector] .title::before {
|
|
236
|
+
content: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='%230041703a' viewBox='0 0 24 24'%3E%3Ctitle%3Eshape-outline%3C/title%3E%3Cpath d='M11,13.5V21.5H3V13.5H11M9,15.5H5V19.5H9V15.5M12,2L17.5,11H6.5L12,2M12,5.86L10.08,9H13.92L12,5.86M17.5,13C20,13 22,15 22,17.5C22,20 20,22 17.5,22C15,22 13,20 13,17.5C13,15 15,13 17.5,13M17.5,15A2.5,2.5 0 0,0 15,17.5A2.5,2.5 0 0,0 17.5,20A2.5,2.5 0 0,0 20,17.5A2.5,2.5 0 0,0 17.5,15Z' /%3E%3C/svg%3E");
|
|
237
|
+
}
|
|
238
|
+
[data-type=draw] .title::before {
|
|
239
|
+
content: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='%230041703a' viewBox='0 0 24 24'%3E%3Ctitle%3Evector-square-edit%3C/title%3E%3Cpath d='M22.7 14.4L21.7 15.4L19.6 13.3L20.6 12.3C20.8 12.1 21.2 12.1 21.4 12.3L22.7 13.6C22.9 13.8 22.9 14.1 22.7 14.4M13 19.9L19.1 13.8L21.2 15.9L15.1 22H13V19.9M11 19.9V19.1L11.6 18.5L12.1 18H8V16H6V8H8V6H16V8H18V12.1L19.1 11L19.3 10.8C19.5 10.6 19.8 10.4 20.1 10.3V8H22.1V2H16.1V4H8V2H2V8H4V16H2V22H8V20L11 19.9M18 4H20V6H18V4M4 4H6V6H4V4M6 20H4V18H6V20Z' /%3E%3C/svg%3E");
|
|
240
|
+
}
|
|
241
|
+
`;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
customElements.define("eox-layercontrol-layer", EOxLayerControlLayer);
|