@eox/layercontrol 1.7.0 → 1.8.1

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 (36) hide show
  1. package/dist/eox-layercontrol.js +502 -431
  2. package/dist/eox-layercontrol.umd.cjs +48 -41
  3. package/package.json +5 -4
  4. package/src/components/layer-config.js +12 -2
  5. package/src/components/layer-group.js +4 -0
  6. package/src/components/layer-list.js +4 -0
  7. package/src/components/layer-tools.js +9 -0
  8. package/src/components/layer.js +9 -0
  9. package/src/enums/index.js +3 -0
  10. package/src/enums/stories/assets/colormaps.json +50 -0
  11. package/src/enums/stories/index.js +179 -6
  12. package/src/helpers/get-legend-config.js +30 -14
  13. package/src/helpers/get-start-vals.js +123 -42
  14. package/src/main.js +3 -0
  15. package/src/methods/layer-config/data-change.js +42 -31
  16. package/types/components/layer-config.d.ts +12 -0
  17. package/types/components/layer-config.d.ts.map +1 -1
  18. package/types/components/layer-group.d.ts +5 -0
  19. package/types/components/layer-group.d.ts.map +1 -1
  20. package/types/components/layer-list.d.ts +5 -0
  21. package/types/components/layer-list.d.ts.map +1 -1
  22. package/types/components/layer-tools.d.ts +10 -0
  23. package/types/components/layer-tools.d.ts.map +1 -1
  24. package/types/components/layer.d.ts +10 -0
  25. package/types/components/layer.d.ts.map +1 -1
  26. package/types/enums/index.d.ts +1 -1
  27. package/types/enums/stories/index.d.ts +442 -176
  28. package/types/enums/stories/index.d.ts.map +1 -1
  29. package/types/helpers/get-legend-config.d.ts +2 -1
  30. package/types/helpers/get-legend-config.d.ts.map +1 -1
  31. package/types/helpers/get-start-vals.d.ts +11 -8
  32. package/types/helpers/get-start-vals.d.ts.map +1 -1
  33. package/types/main.d.ts +5 -0
  34. package/types/main.d.ts.map +1 -1
  35. package/types/methods/layer-config/data-change.d.ts.map +1 -1
  36. package/src/enums/stories/assets/cropomhusc-feature-collection.json +0 -5274
package/package.json CHANGED
@@ -1,17 +1,18 @@
1
1
  {
2
2
  "name": "@eox/layercontrol",
3
- "version": "1.7.0",
3
+ "version": "1.8.1",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git@github.com:EOX-A/EOxElements.git"
8
8
  },
9
9
  "devDependencies": {
10
+ "@eox/jsonform": "*",
10
11
  "@eox/map": "*",
11
12
  "@types/lodash.throttle": "^4.1.9",
12
13
  "@types/sortablejs": "^1.15.1",
13
14
  "ol": "^10.9.0",
14
- "vite": "^8.0.12"
15
+ "vite": "^8.1.0"
15
16
  },
16
17
  "engines": {
17
18
  "npm": ">=8.0.0",
@@ -41,10 +42,10 @@
41
42
  "watch": "vite build --watch"
42
43
  },
43
44
  "dependencies": {
44
- "@eox/elements-utils": "^1.1.0",
45
+ "@eox/elements-utils": "^1.2.0",
45
46
  "@eox/ui": "^1.1.0",
46
47
  "color-legend-element": "^1.5.0",
47
- "lit": "^3.2.0",
48
+ "lit": "^3.3.3",
48
49
  "lodash.debounce": "^4.0.8",
49
50
  "lodash.throttle": "^4.1.1",
50
51
  "sortablejs": "^1.15.0",
@@ -9,6 +9,7 @@ import "./layer-legend";
9
9
  * @typedef {Partial<import("./layer-legend").LegendConfig> & {
10
10
  * boundTo?:{key: string;value: string|number|boolean}
11
11
  * domainProperties: string[]
12
+ * rangeProperty?: string
12
13
  * }} layerConfigLegend
13
14
  **/
14
15
 
@@ -27,6 +28,7 @@ export class EOxLayerControlLayerConfig extends LitElement {
27
28
  unstyled: { type: Boolean },
28
29
  noShadow: { type: Boolean },
29
30
  layerConfig: { attribute: false },
31
+ colormapRegistry: { attribute: false, type: Object },
30
32
  customEditorInterfaces: { attribute: false, type: Array },
31
33
  };
32
34
 
@@ -102,6 +104,13 @@ export class EOxLayerControlLayerConfig extends LitElement {
102
104
  * @type {Array}
103
105
  */
104
106
  this.customEditorInterfaces = [];
107
+
108
+ /**
109
+ * Optional colormap registry for dynamic legend updates
110
+ *
111
+ * @type {Record<string,string[]>}
112
+ */
113
+ this.colormapRegistry = null;
105
114
  }
106
115
 
107
116
  /** Decide what type of throttling to do based on layerConfig type
@@ -111,7 +120,7 @@ export class EOxLayerControlLayerConfig extends LitElement {
111
120
  updated(changedProperties) {
112
121
  if (changedProperties.has("layerConfig")) {
113
122
  const throttleTime =
114
- this.layerConfig.type === "style" || this.layerConfig.style
123
+ this.layerConfig?.type === "style" || this.layerConfig?.style
115
124
  ? 100
116
125
  : 1000;
117
126
 
@@ -200,7 +209,8 @@ export class EOxLayerControlLayerConfig extends LitElement {
200
209
  .layer=${this.layer}
201
210
  .layerLegend=${getLegendConfig(
202
211
  this.layerConfig.legend,
203
- this.#data,
212
+ this.#startVals,
213
+ this.colormapRegistry,
204
214
  )}
205
215
  ></eox-layercontrol-layer-legend>
206
216
  `,
@@ -28,6 +28,7 @@ export class EOxLayerControlLayerGroup extends LitElement {
28
28
  attribute: "tools-auto-expand",
29
29
  type: Boolean,
30
30
  },
31
+ colormapRegistry: { attribute: false, type: Object },
31
32
  customEditorInterfaces: { attribute: false, type: Array },
32
33
  };
33
34
 
@@ -120,6 +121,7 @@ export class EOxLayerControlLayerGroup extends LitElement {
120
121
  * @type {Array}
121
122
  */
122
123
  this.customEditorInterfaces = [];
124
+ this.colormapRegistry = null;
123
125
  }
124
126
 
125
127
  /**
@@ -191,6 +193,7 @@ export class EOxLayerControlLayerGroup extends LitElement {
191
193
  .toolsAsList=${this.toolsAsList}
192
194
  .globallyExclusiveLayers=${this.globallyExclusiveLayers}
193
195
  .toolsAutoExpand=${this.toolsAutoExpand}
196
+ .colormapRegistry=${this.colormapRegistry}
194
197
  .customEditorInterfaces=${this.customEditorInterfaces}
195
198
  @changed=${() => this.requestUpdate()}
196
199
  ></eox-layercontrol-layer>
@@ -209,6 +212,7 @@ export class EOxLayerControlLayerGroup extends LitElement {
209
212
  .toolsAsList=${this.toolsAsList}
210
213
  .globallyExclusiveLayers=${this.globallyExclusiveLayers}
211
214
  .toolsAutoExpand=${this.toolsAutoExpand}
215
+ .colormapRegistry=${this.colormapRegistry}
212
216
  .customEditorInterfaces=${this.customEditorInterfaces}
213
217
  @changed=${() => this.requestUpdate()}
214
218
  ></eox-layercontrol-layer-list>
@@ -28,6 +28,7 @@ export class EOxLayerControlLayerList extends LitElement {
28
28
  attribute: "tools-auto-expand",
29
29
  type: Boolean,
30
30
  },
31
+ colormapRegistry: { attribute: false, type: Object },
31
32
  customEditorInterfaces: { attribute: false, type: Array },
32
33
  };
33
34
 
@@ -121,6 +122,7 @@ export class EOxLayerControlLayerList extends LitElement {
121
122
  * @type {Array}
122
123
  */
123
124
  this.customEditorInterfaces = [];
125
+ this.colormapRegistry = null;
124
126
  }
125
127
 
126
128
  /**
@@ -182,6 +184,7 @@ export class EOxLayerControlLayerList extends LitElement {
182
184
  .globallyExclusiveLayers=${this
183
185
  .globallyExclusiveLayers}
184
186
  .toolsAutoExpand=${this.toolsAutoExpand}
187
+ .colormapRegistry=${this.colormapRegistry}
185
188
  .customEditorInterfaces=${this
186
189
  .customEditorInterfaces}
187
190
  @changed=${() => this.requestUpdate()}
@@ -202,6 +205,7 @@ export class EOxLayerControlLayerList extends LitElement {
202
205
  .globallyExclusiveLayers=${this
203
206
  .globallyExclusiveLayers}
204
207
  .toolsAutoExpand=${this.toolsAutoExpand}
208
+ .colormapRegistry=${this.colormapRegistry}
205
209
  .customEditorInterfaces=${this
206
210
  .customEditorInterfaces}
207
211
  @changed=${() => this.requestUpdate()}
@@ -39,6 +39,7 @@ export class EOxLayerControlLayerTools extends LitElement {
39
39
  type: Boolean,
40
40
  },
41
41
  embedded: { state: true },
42
+ colormapRegistry: { attribute: false, type: Object },
42
43
  customEditorInterfaces: { attribute: false, type: Array },
43
44
  };
44
45
 
@@ -126,6 +127,13 @@ export class EOxLayerControlLayerTools extends LitElement {
126
127
  * @type {Array}
127
128
  */
128
129
  this.customEditorInterfaces = [];
130
+
131
+ /**
132
+ * Optional colormap registry for dynamic legend updates
133
+ *
134
+ * @type {Record<string,string[]>}
135
+ */
136
+ this.colormapRegistry = null;
129
137
  }
130
138
 
131
139
  /**
@@ -209,6 +217,7 @@ export class EOxLayerControlLayerTools extends LitElement {
209
217
  .layer=${this.layer}
210
218
  .noShadow=${true}
211
219
  .layerConfig=${this.layer.get("layerConfig")}
220
+ .colormapRegistry=${this.colormapRegistry}
212
221
  .unstyled=${this.unstyled}
213
222
  .customEditorInterfaces=${this.customEditorInterfaces}
214
223
  @changed=${() => this.requestUpdate()}
@@ -35,6 +35,7 @@ export class EOxLayerControlLayer extends LitElement {
35
35
  attribute: "tools-auto-expand",
36
36
  type: Boolean,
37
37
  },
38
+ colormapRegistry: { attribute: false, type: Object },
38
39
  customEditorInterfaces: { attribute: false, type: Array },
39
40
  };
40
41
 
@@ -135,6 +136,13 @@ export class EOxLayerControlLayer extends LitElement {
135
136
  * @type {Array}
136
137
  */
137
138
  this.customEditorInterfaces = [];
139
+
140
+ /**
141
+ * Optional colormap registry for dynamic legend updates
142
+ *
143
+ * @type {Record<string,string[]>}
144
+ */
145
+ this.colormapRegistry = null;
138
146
  }
139
147
 
140
148
  /**
@@ -383,6 +391,7 @@ export class EOxLayerControlLayer extends LitElement {
383
391
  .unstyled=${this.unstyled}
384
392
  .toolsAsList=${this.toolsAsList}
385
393
  .toolsAutoExpand=${this.toolsAutoExpand}
394
+ .colormapRegistry=${this.colormapRegistry}
386
395
  .customEditorInterfaces=${this.customEditorInterfaces}
387
396
  ></eox-layercontrol-layer-tools>
388
397
  `,
@@ -15,4 +15,7 @@ export {
15
15
  STORIES_LAYER_CROPOMHUSC2,
16
16
  STORIES_LAYER_SEE,
17
17
  STORIES_LAYER_POLARIS,
18
+ STORIES_LAYER_ESDL_DYNAMIC,
19
+ STORIES_LAYER_JAXA_WMS,
20
+ STORIES_LAYER_COPERNICUS_WMTS,
18
21
  } from "./stories";
@@ -0,0 +1,50 @@
1
+ {
2
+ "magma": [
3
+ "#000004",
4
+ "#180f3d",
5
+ "#440f76",
6
+ "#721f81",
7
+ "#9e2f7f",
8
+ "#cd4071",
9
+ "#f1605d",
10
+ "#fd9567",
11
+ "#fec98d",
12
+ "#fcfdbf"
13
+ ],
14
+ "viridis": [
15
+ "#440154",
16
+ "#482878",
17
+ "#3e4989",
18
+ "#31688e",
19
+ "#26828e",
20
+ "#1f9e89",
21
+ "#35b779",
22
+ "#6ece58",
23
+ "#b5de2b",
24
+ "#fde725"
25
+ ],
26
+ "plasma": [
27
+ "#0d0887",
28
+ "#46039f",
29
+ "#7201a8",
30
+ "#9c179e",
31
+ "#bd3786",
32
+ "#d8576b",
33
+ "#ed7953",
34
+ "#fb9f3a",
35
+ "#fdca26",
36
+ "#f0f921"
37
+ ],
38
+ "plasma_r": [
39
+ "#f0f921",
40
+ "#fdca26",
41
+ "#fb9f3a",
42
+ "#ed7953",
43
+ "#d8576b",
44
+ "#bd3786",
45
+ "#9c179e",
46
+ "#721f81",
47
+ "#46039f",
48
+ "#0d0887"
49
+ ]
50
+ }
@@ -1,4 +1,3 @@
1
- import FEATURE_COLLECTION_LAYER_CROPOMHUSC from "./assets/cropomhusc-feature-collection.json";
2
1
  import POLARIS_STYLE from "./assets/polaris-style.json";
3
2
 
4
3
  const SENTINEL_HUB_URL =
@@ -16,7 +15,7 @@ const LAYER_EOX_CLOUDLESS = (year) => ({
16
15
  },
17
16
  });
18
17
 
19
- export const STORIES_LAYERCONTROL_STYLE = "width: 240px;";
18
+ export const STORIES_LAYERCONTROL_STYLE = "width: 350px;";
20
19
 
21
20
  export const STORIES_MAP_STYLE =
22
21
  "width: 400px; height: 300px; margin-left: 7px;";
@@ -292,10 +291,11 @@ export const STORIES_LAYER_CROPOMHUSC2 = {
292
291
  type: "Vector",
293
292
  source: {
294
293
  type: "Vector",
295
- url:
296
- "data:," +
297
- encodeURIComponent(JSON.stringify(FEATURE_COLLECTION_LAYER_CROPOMHUSC)),
298
- format: "GeoJSON",
294
+ url: "/cropomhusc.json",
295
+ format: {
296
+ type: "GeoJSON",
297
+ dataProjection: "EPSG:3035",
298
+ },
299
299
  },
300
300
  properties: {
301
301
  id: "id",
@@ -571,6 +571,122 @@ export const STORIES_LAYER_POLARIS = {
571
571
  },
572
572
  };
573
573
 
574
+ export const STORIES_LAYER_JAXA_WMS = {
575
+ type: "Tile",
576
+ properties: {
577
+ id: "jaxa-wms-smc",
578
+ title: "JAXA WMS",
579
+ layerControlToolsExpand: true,
580
+ layerConfig: {
581
+ legend: {
582
+ domain: [0, 300, 600, 750, 900, 1200, 1500],
583
+ range: [
584
+ "#9f409f",
585
+ "#2187f9",
586
+ "#76f6ff",
587
+ "#99e599",
588
+ "#f6fc81",
589
+ "#ff8a7f",
590
+ "#8b0b0b",
591
+ ],
592
+ scaleType: "continuous",
593
+ tickFormat: ".0f",
594
+ title: "mgC/m²/day",
595
+ },
596
+ schema: {
597
+ type: "object",
598
+ properties: {
599
+ TIME: {
600
+ type: "string",
601
+ title: "Time",
602
+ enum: [
603
+ "2022-01-01T00:00:00.000Z",
604
+ "2022-02-01T00:00:00.000Z",
605
+ "2022-03-01T00:00:00.000Z",
606
+ "2022-04-01T00:00:00.000Z",
607
+ "2022-05-01T00:00:00.000Z",
608
+ "2022-06-01T00:00:00.000Z",
609
+ ],
610
+ default: "2022-01-01T00:00:00.000Z",
611
+ },
612
+ },
613
+ },
614
+ },
615
+ },
616
+ source: {
617
+ type: "TileWMS",
618
+ url: "https://gpwmap.jaxa.jp/wms",
619
+ params: {
620
+ LAYERS: "EODASH:SMC-GCOMW-World-Monthly",
621
+ TIME: "2022-01-01T00:00:00.000Z",
622
+ },
623
+ },
624
+ };
625
+
626
+ export const STORIES_LAYER_COPERNICUS_WMTS = {
627
+ type: "Tile",
628
+ properties: {
629
+ id: "copernicus-wmts",
630
+ title: "Copernicus Marine WMTS",
631
+ layerControlToolsExpand: true,
632
+ layerConfig: {
633
+ schema: {
634
+ type: "object",
635
+ properties: {
636
+ cmap: {
637
+ type: "string",
638
+ title: "Colormap",
639
+ enum: ["speed", "thermal", "ice"],
640
+ default: "speed",
641
+ },
642
+ vminmax: {
643
+ type: "object",
644
+ title: "Range",
645
+ properties: {
646
+ vmin: {
647
+ type: "number",
648
+ title: "Min",
649
+ default: 0,
650
+ format: "range",
651
+ },
652
+ vmax: {
653
+ type: "number",
654
+ title: "Max",
655
+ default: 24,
656
+ format: "range",
657
+ },
658
+ },
659
+ format: "minmax",
660
+ },
661
+ style: {
662
+ type: "string",
663
+ template:
664
+ "cmap:{{cmap}},vectorStyle:solidAndVector,range:{{vminmax.vmin}}/{{vminmax.vmax}}",
665
+ watch: {
666
+ cmap: "cmap",
667
+ vminmax: "vminmax",
668
+ },
669
+ options: { hidden: true },
670
+ },
671
+ },
672
+ options: {
673
+ removeProperties: ["cmap", "vminmax"],
674
+ },
675
+ },
676
+ },
677
+ },
678
+ source: {
679
+ type: "WMTSCapabilities",
680
+ url: "https://wmts.marine.copernicus.eu/teroWmts/WIND_GLO_PHY_CLIMATE_L4_MY_012_003/cmems_obs-wind_glo_phy_my_l4_P1M_202411?request=GetCapabilities&service=WMTS",
681
+ layer:
682
+ "WIND_GLO_PHY_CLIMATE_L4_MY_012_003/cmems_obs-wind_glo_phy_my_l4_P1M_202411/wind",
683
+ dimensions: {
684
+ elevation: 0,
685
+ style: "cmap:speed,vectorStyle:solidAndVector,range:0/24",
686
+ },
687
+ },
688
+ };
689
+
574
690
  export const STORIES_LAYER_SEE = {
575
691
  type: "WebGLTile",
576
692
  style: STYLES_LAYER_SEE,
@@ -697,3 +813,60 @@ export const STORIES_LAYER_VESSEL_DENSITY_CARGO = {
697
813
  },
698
814
  },
699
815
  };
816
+
817
+ export const STORIES_LAYER_ESDL_DYNAMIC = {
818
+ type: "Tile",
819
+ properties: {
820
+ id: "esdl-dynamic",
821
+ title: "Dynamic Legends Layer",
822
+ layerControlExpand: true,
823
+ layerControlToolsExpand: true,
824
+ layerConfig: {
825
+ type: "tileUrl",
826
+ legend: {
827
+ title: "Dynamic Legend",
828
+ rangeProperty: "cbar",
829
+ domainProperties: ["vmin", "vmax"],
830
+ tickFormat: ".2f",
831
+ },
832
+ schema: {
833
+ type: "object",
834
+ properties: {
835
+ vminmax: {
836
+ title: "Range",
837
+ type: "object",
838
+ properties: {
839
+ vmin: {
840
+ type: "number",
841
+ minimum: 0,
842
+ maximum: 1,
843
+ step: 0.01,
844
+ format: "range",
845
+ default: 0,
846
+ },
847
+ vmax: {
848
+ type: "number",
849
+ minimum: 0,
850
+ maximum: 1,
851
+ step: 0.01,
852
+ format: "range",
853
+ default: 1,
854
+ },
855
+ },
856
+ format: "minmax",
857
+ },
858
+ cbar: {
859
+ title: "Colormap",
860
+ type: "string",
861
+ enum: ["magma", "viridis", "plasma", "plasma_r"],
862
+ default: "plasma_r",
863
+ },
864
+ },
865
+ },
866
+ },
867
+ },
868
+ source: {
869
+ type: "XYZ",
870
+ url: "https://api.earthsystemdatalab.net/api/tiles/hydrology/SM/{z}/{y}/{x}?crs=EPSG:3857&time=2022-06-15T00:00:00Z&vmin=0&vmax=1&cbar=plasma_r",
871
+ },
872
+ };
@@ -4,8 +4,9 @@ import { flattenObject } from "../methods/layer-config";
4
4
  *
5
5
  * @param {import("../components/layer-config").EOxLayerControlLayerConfig["layerConfig"]["legend"]} legendConfig
6
6
  * @param {Record<string,unknown>} data
7
+ * @param {Record<string,string[]>} [colormapRegistry]
7
8
  */
8
- const getLegendConfig = (legendConfig, data) => {
9
+ const getLegendConfig = (legendConfig, data, colormapRegistry) => {
9
10
  if (!legendConfig) {
10
11
  return undefined;
11
12
  }
@@ -46,20 +47,35 @@ const getLegendConfig = (legendConfig, data) => {
46
47
  }
47
48
 
48
49
  return /** @type {import("../components/layer-legend").LegendConfig[] | null} */ (
49
- activeLegends?.map((activeLegend) => {
50
- delete activeLegend.boundTo;
51
- if (!("domainProperties" in activeLegend) || "domain" in activeLegend) {
52
- return activeLegend;
53
- }
54
- return Object.keys(activeLegend)?.reduce((legend, key) => {
55
- if (key === "domainProperties") {
56
- legend["domain"] = activeLegend[key].map((k) => flatData[k]);
57
- } else {
58
- legend[key] = activeLegend[key];
50
+ activeLegends
51
+ ?.map((activeLegend) => {
52
+ delete activeLegend.boundTo;
53
+
54
+ // Dynamic colormap range lookup
55
+ if (activeLegend.rangeProperty && colormapRegistry) {
56
+ const colormapName = flatData[activeLegend.rangeProperty];
57
+ if (colormapName && colormapRegistry[colormapName]) {
58
+ activeLegend.range = colormapRegistry[colormapName];
59
+ delete activeLegend.rangeProperty;
60
+ } else if (colormapName) {
61
+ // fallback in case colormap not in registry
62
+ activeLegend.range = ["#ffffff", "#000000"];
63
+ }
64
+ }
65
+
66
+ if (!("domainProperties" in activeLegend) || "domain" in activeLegend) {
67
+ return activeLegend;
59
68
  }
60
- return legend;
61
- }, /** @type {import("../components/layer-legend").LegendConfig} */ ({}));
62
- })
69
+ return Object.keys(activeLegend)?.reduce((legend, key) => {
70
+ if (key === "domainProperties") {
71
+ legend["domain"] = activeLegend[key].map((k) => flatData[k]);
72
+ } else {
73
+ legend[key] = activeLegend[key];
74
+ }
75
+ return legend;
76
+ }, /** @type {import("../components/layer-legend").LegendConfig} */ ({}));
77
+ })
78
+ .filter(Boolean)
63
79
  );
64
80
  };
65
81