@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
@@ -0,0 +1,124 @@
1
+ import { LitElement, html } from "lit";
2
+ import { filterLayers } from "../helpers";
3
+ import { addToListMethod } from "../methods/optional-list";
4
+
5
+ /**
6
+ * EOxLayerControlOptionalList is a component that renders a dropdown menu to select optional layers. It manages the presentation of a list of layers,
7
+ * allowing users to choose and add specific layers to a selection. The class provides properties to configure the behavior and appearance of the rendered dropdown.
8
+ * It offers the ability to filter layers based on specific properties and provides a method to handle the addition of selected layers to a list.
9
+ *
10
+ * @element eox-layercontrol-optional-list
11
+ * @extends LitElement
12
+ */
13
+ export class EOxLayerControlOptionalList extends LitElement {
14
+ // Define static properties for the component
15
+ static properties = {
16
+ idProperty: { attribute: "id-property" },
17
+ layers: { attribute: false },
18
+ titleProperty: { attribute: "title-property", type: String },
19
+ unstyled: { type: Boolean },
20
+ noShadow: { type: Boolean },
21
+ };
22
+
23
+ constructor() {
24
+ super();
25
+
26
+ /**
27
+ * The layer id property
28
+ *
29
+ * @type {String}
30
+ */
31
+ this.idProperty = "id";
32
+
33
+ /**
34
+ * The OL layer collection
35
+ *
36
+ * @type {import("ol").Collection<import("ol/layer").Layer>}
37
+ * @see {@link https://openlayers.org/en/latest/apidoc/module-ol_Collection-Collection.html}
38
+ */
39
+ this.layers = null;
40
+
41
+ /**
42
+ * The layer title property
43
+ *
44
+ * @type {String}
45
+ */
46
+ this.titleProperty = "title";
47
+
48
+ /**
49
+ * Render the element without additional styles
50
+ *
51
+ * @type {Boolean}
52
+ */
53
+ this.unstyled = false;
54
+
55
+ /**
56
+ * Renders the element without a shadow root
57
+ *
58
+ * @type {Boolean}
59
+ */
60
+ this.noShadow = false;
61
+ }
62
+
63
+ /**
64
+ * Overrides createRenderRoot to handle shadow DOM creation based on the noShadow property.
65
+ */
66
+ createRenderRoot() {
67
+ return this.noShadow ? this : super.createRenderRoot();
68
+ }
69
+
70
+ /**
71
+ * Handles the addition of selected layers to a list.
72
+ * Invokes the 'addToListMethod' with the current context.
73
+ */
74
+ #handleAddToList() {
75
+ addToListMethod(this);
76
+ }
77
+
78
+ /**
79
+ * Renders a dropdown menu to select optional layers. Filters the layers list based on the 'layerControlOptional' property,
80
+ * generates a dropdown list of filtered layers, and provides a button to add selected layers. Utilizes 'filterLayers' to obtain a filtered list and extracts necessary data for each layer.
81
+ * Generates dropdown options based on the extracted layer information.
82
+ */
83
+ render() {
84
+ // Filter the layers list based on the 'layerControlOptional' property
85
+ const filteredLayersList = filterLayers(
86
+ this.layers.getArray(),
87
+ "layerControlOptional",
88
+ true,
89
+ );
90
+
91
+ return html`
92
+ <!-- Label for the dropdown -->
93
+ <label for="optional">Optional layers</label>
94
+
95
+ <!-- Dropdown select element -->
96
+ <select name="optional" data-cy="optionalLayers">
97
+ <!-- Default placeholder option -->
98
+ <option disabled selected value>
99
+ -- select an optional layer to add --
100
+ </option>
101
+
102
+ <!-- Mapping through filtered layers list to generate dropdown options -->
103
+ ${filteredLayersList.map((layer) => {
104
+ // @ts-expect-error TODO
105
+ const value = layer.get(this.idProperty) || layer.ol_uid;
106
+ const title = layer.get(this.titleProperty);
107
+ const id = `layer ${layer.get(this.idProperty)}`;
108
+ const label = title || id;
109
+
110
+ // Generating options for the dropdown
111
+ return html` <option value="${value}">${label}</option> `;
112
+ })}
113
+ </select>
114
+
115
+ <!-- Button to handle adding layers -->
116
+ <button @click="${this.#handleAddToList}">add</button>
117
+ `;
118
+ }
119
+ }
120
+
121
+ customElements.define(
122
+ "eox-layercontrol-optional-list",
123
+ EOxLayerControlOptionalList,
124
+ );
File without changes
@@ -0,0 +1,199 @@
1
+ import { LitElement, html } from "lit";
2
+ import { when } from "lit/directives/when.js";
3
+ import { map } from "lit/directives/map.js";
4
+
5
+ export class EOxLayerControlTabs extends LitElement {
6
+ // Define static properties for the component
7
+ static properties = {
8
+ actions: { attribute: false },
9
+ selectedTab: { state: true },
10
+ tabs: { attribute: false },
11
+ unstyled: { type: Boolean },
12
+ noShadow: { type: Boolean },
13
+ toolsAsList: { type: Boolean },
14
+ };
15
+
16
+ constructor() {
17
+ super();
18
+
19
+ /**
20
+ * List of action ids
21
+ *
22
+ * @type {Array<String>}
23
+ */
24
+ this.actions = [];
25
+
26
+ this.selectedTab = 0;
27
+
28
+ /**
29
+ * List of tab ids
30
+ *
31
+ * @type {Array<String>}
32
+ */
33
+ this.tabs = [];
34
+
35
+ /**
36
+ * Render the element without additional styles
37
+ *
38
+ * @type {Boolean}
39
+ */
40
+ this.unstyled = false;
41
+
42
+ /**
43
+ * Renders the element without a shadow root
44
+ *
45
+ * @type {Boolean}
46
+ */
47
+ this.noShadow = false;
48
+
49
+ /**
50
+ * If enabled, the tools section will be rendered as list.
51
+ *
52
+ * @type {Boolean}
53
+ */
54
+ this.toolsAsList = false;
55
+ }
56
+
57
+ /**
58
+ * Overrides createRenderRoot to handle shadow DOM creation based on the noShadow property.
59
+ */
60
+ createRenderRoot() {
61
+ return this.noShadow ? this : super.createRenderRoot();
62
+ }
63
+
64
+ /** @param {number} index */
65
+ #labelHighlightClass = (index) =>
66
+ (this.selectedTab === index || this.toolsAsList) && "highlighted";
67
+
68
+ /**
69
+ * Renders a tabbed interface that displays tabs and corresponding content areas based on the provided 'tabs' and 'actions'.
70
+ * It sets up navigation for switching between tabs and offers customizable icons for tabs and actions.
71
+ */
72
+ render() {
73
+ const tabs = this.tabs;
74
+ const actions = this.actions;
75
+ const isListAvail = actions.length + tabs.length > 1;
76
+
77
+ return html`
78
+ <style>
79
+ ${this.#styleBasic}
80
+ ${!this.unstyled && this.#styleEOX}
81
+ </style>
82
+ <div class="tabbed">
83
+ <!-- Navigation for tabs and actions -->
84
+ ${when(
85
+ isListAvail,
86
+ () => html`
87
+ <nav>
88
+ ${when(
89
+ !this.toolsAsList,
90
+ () => html`
91
+ <div>
92
+ <!-- Labels for tabs -->
93
+ ${map(
94
+ tabs,
95
+ (tab, index) => html`
96
+ <label
97
+ class=${this.#labelHighlightClass(index)}
98
+ @click=${() => (this.selectedTab = index)}
99
+ >
100
+ <!-- Customizable icon for each tab -->
101
+ <slot name=${`${tab}-icon`}>${tab}</slot>
102
+ </label>
103
+ `,
104
+ )}
105
+ </div>
106
+ <div>
107
+ <!-- Icons for actions -->
108
+ ${map(
109
+ actions,
110
+ (action) => html`
111
+ <span>
112
+ <!-- Customizable icon for each action -->
113
+ <slot name=${`${action}-icon`}>${action}</slot>
114
+ </span>
115
+ `,
116
+ )}
117
+ </div>
118
+ `,
119
+ )}
120
+ </nav>
121
+ `,
122
+ )}
123
+ <figure>
124
+ <!-- Content for each tab -->
125
+ ${map(
126
+ tabs,
127
+ (tab, index) => html`
128
+ ${when(
129
+ this.toolsAsList,
130
+ () => html`
131
+ <label class="listed">
132
+ <!-- Customizable icon for each tab -->
133
+ <slot name=${`${tab}-icon`}>${tab}</slot>
134
+ </label>
135
+ `,
136
+ )}
137
+ <div class="tab ${this.#labelHighlightClass(index)}">
138
+ <!-- Content slot for each tab -->
139
+ <slot name=${`${tab}-content`}>${tab}</slot>
140
+ </div>
141
+ `,
142
+ )}
143
+ </figure>
144
+ </div>
145
+ `;
146
+ }
147
+
148
+ #styleBasic = `
149
+ .tabbed figure {
150
+ margin: 0;
151
+ }
152
+ .tabbed nav {
153
+ display: flex;
154
+ justify-content: space-between;
155
+ }
156
+ .tabbed nav div {
157
+ display: flex;
158
+ }
159
+ .tabbed .tab {
160
+ display: none;
161
+ }
162
+ .tabbed .tab.highlighted {
163
+ display: block;
164
+ }
165
+ .tabbed label.highlighted {
166
+ background: lightgrey;
167
+ }
168
+ `;
169
+
170
+ #styleEOX = `
171
+ .listed {
172
+ background: #ffffff !important;
173
+ display: flex;
174
+ justify-content: end;
175
+ }
176
+ .tabbed {
177
+ font-size: small;
178
+ }
179
+ .tabbed label.highlighted {
180
+ background: #00417011;
181
+ pointer-events: none;
182
+ }
183
+ nav div label,
184
+ nav div span {
185
+ width: 20px;
186
+ height: 20px;
187
+ display: flex;
188
+ align-items: center;
189
+ justify-content: center;
190
+ cursor: pointer;
191
+ }
192
+ figure {
193
+ background: #00417011;
194
+ border-top: 1px solid #0041701a;
195
+ }
196
+ `;
197
+ }
198
+
199
+ customElements.define("eox-layercontrol-tools-items", EOxLayerControlTabs);
@@ -0,0 +1,16 @@
1
+ export {
2
+ STORIES_LAYER_S2,
3
+ STORIES_LAYER_OSM,
4
+ STORIES_LAYER_REGION,
5
+ STORIES_LAYER_SENTINEL_HUB,
6
+ STORIES_MAIN_MAP_LAYERS,
7
+ STORIES_MAP_STYLE,
8
+ STORIES_LAYER_EOX_CLOUDLESS_2021,
9
+ STORIES_LAYER_EOX_CLOUDLESS_2020,
10
+ STORIES_LAYER_EOX_CLOUDLESS_2019,
11
+ STORIES_LAYER_DEFORESTED_BIOMASS,
12
+ STORIES_LAYER_TERRAIN_LIGHT,
13
+ STORIES_LAYER_VESSEL_DENSITY_CARGO,
14
+ STORIES_LAYER_CROPOMHUSC2,
15
+ STORIES_LAYER_SEE,
16
+ } from "./stories";