@open-pioneer/map 0.6.1 → 0.8.0-dev.20241120115147

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 (81) hide show
  1. package/CHANGELOG.md +214 -0
  2. package/README.md +127 -12
  3. package/api/MapModel.d.ts +50 -17
  4. package/api/index.d.ts +2 -1
  5. package/api/layers/GroupLayer.d.ts +50 -0
  6. package/api/layers/GroupLayer.js +6 -0
  7. package/api/layers/GroupLayer.js.map +1 -0
  8. package/api/layers/SimpleLayer.d.ts +5 -2
  9. package/api/layers/SimpleLayer.js.map +1 -1
  10. package/api/layers/WMSLayer.d.ts +6 -3
  11. package/api/layers/WMSLayer.js.map +1 -1
  12. package/api/layers/WMTSLayer.d.ts +4 -2
  13. package/api/layers/WMTSLayer.js.map +1 -1
  14. package/api/layers/base.d.ts +77 -18
  15. package/api/layers/base.js +9 -0
  16. package/api/layers/base.js.map +1 -0
  17. package/api/layers/index.d.ts +1 -0
  18. package/index.js +3 -0
  19. package/index.js.map +1 -1
  20. package/model/AbstractLayer.d.ts +4 -3
  21. package/model/AbstractLayer.js +16 -23
  22. package/model/AbstractLayer.js.map +1 -1
  23. package/model/AbstractLayerBase.d.ts +21 -5
  24. package/model/AbstractLayerBase.js +48 -35
  25. package/model/AbstractLayerBase.js.map +1 -1
  26. package/model/Highlights.d.ts +11 -4
  27. package/model/Highlights.js +5 -1
  28. package/model/Highlights.js.map +1 -1
  29. package/model/LayerCollectionImpl.d.ts +10 -10
  30. package/model/LayerCollectionImpl.js +39 -37
  31. package/model/LayerCollectionImpl.js.map +1 -1
  32. package/model/MapModelImpl.d.ts +16 -3
  33. package/model/MapModelImpl.js +94 -25
  34. package/model/MapModelImpl.js.map +1 -1
  35. package/model/SublayersCollectionImpl.d.ts +6 -3
  36. package/model/SublayersCollectionImpl.js +6 -4
  37. package/model/SublayersCollectionImpl.js.map +1 -1
  38. package/model/layers/GroupLayerImpl.d.ts +39 -0
  39. package/model/layers/GroupLayerImpl.js +88 -0
  40. package/model/layers/GroupLayerImpl.js.map +1 -0
  41. package/model/layers/SimpleLayerImpl.d.ts +4 -1
  42. package/model/layers/SimpleLayerImpl.js +6 -0
  43. package/model/layers/SimpleLayerImpl.js.map +1 -1
  44. package/model/layers/WMSLayerImpl.d.ts +11 -7
  45. package/model/layers/WMSLayerImpl.js +64 -51
  46. package/model/layers/WMSLayerImpl.js.map +1 -1
  47. package/model/layers/WMTSLayerImpl.d.ts +4 -5
  48. package/model/layers/WMTSLayerImpl.js +16 -13
  49. package/model/layers/WMTSLayerImpl.js.map +1 -1
  50. package/package.json +11 -12
  51. package/ui/CssProps.d.ts +9 -0
  52. package/ui/CssProps.js +13 -0
  53. package/ui/CssProps.js.map +1 -0
  54. package/ui/DefaultMapProvider.d.ts +39 -0
  55. package/ui/DefaultMapProvider.js +24 -0
  56. package/ui/DefaultMapProvider.js.map +1 -0
  57. package/ui/MapAnchor.d.ts +0 -3
  58. package/ui/MapAnchor.js +5 -49
  59. package/ui/MapAnchor.js.map +1 -1
  60. package/ui/MapContainer.d.ts +3 -3
  61. package/ui/MapContainer.js +30 -25
  62. package/ui/MapContainer.js.map +1 -1
  63. package/ui/MapContainerContext.d.ts +7 -0
  64. package/ui/MapContainerContext.js +17 -0
  65. package/ui/MapContainerContext.js.map +1 -0
  66. package/ui/computeMapAnchorStyles.d.ts +3 -0
  67. package/ui/computeMapAnchorStyles.js +51 -0
  68. package/ui/computeMapAnchorStyles.js.map +1 -0
  69. package/ui/hooks.d.ts +10 -0
  70. package/ui/hooks.js.map +1 -1
  71. package/ui/styles.css +7 -0
  72. package/ui/styles.css.map +1 -1
  73. package/ui/useMapModel.d.ts +33 -6
  74. package/ui/useMapModel.js +40 -2
  75. package/ui/useMapModel.js.map +1 -1
  76. package/ui/MapContext.d.ts +0 -11
  77. package/ui/MapContext.js +0 -17
  78. package/ui/MapContext.js.map +0 -1
  79. package/util/defer.d.ts +0 -18
  80. package/util/defer.js +0 -21
  81. package/util/defer.js.map +0 -1
@@ -1,5 +1,5 @@
1
1
  import type { Options as WMSSourceOptions } from "ol/source/ImageWMS";
2
- import { Layer, LayerConfig } from "./base";
2
+ import { LayerBaseType, LayerConfig } from "./base";
3
3
  export interface WMTSLayerConfig extends LayerConfig {
4
4
  /** URL of the WMTS service. */
5
5
  url: string;
@@ -15,13 +15,15 @@ export interface WMTSLayerConfig extends LayerConfig {
15
15
  */
16
16
  sourceOptions?: Partial<WMSSourceOptions>;
17
17
  }
18
- export interface WMTSLayer extends Layer {
18
+ export interface WMTSLayer extends LayerBaseType {
19
+ readonly type: "wmts";
19
20
  /** URL of the WMTS service. */
20
21
  readonly url: string;
21
22
  /** The name of the WMTS layer in the service's capabilities. */
22
23
  readonly name: string;
23
24
  /** The name of the tile matrix set in the service's capabilities. */
24
25
  readonly matrixSet: string;
26
+ readonly layers: undefined;
25
27
  }
26
28
  export interface WMTSLayerConstructor {
27
29
  prototype: WMTSLayer;
@@ -1 +1 @@
1
- {"version":3,"file":"WMTSLayer.js","sources":["WMTSLayer.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport type { Options as WMSSourceOptions } from \"ol/source/ImageWMS\";\nimport { Layer, LayerConfig } from \"./base\";\nimport { WMTSLayerImpl } from \"../../model/layers/WMTSLayerImpl\";\nexport interface WMTSLayerConfig extends LayerConfig {\n /** URL of the WMTS service. */\n url: string;\n\n /** The name of the WMTS layer in the service's capabilities. */\n name: string;\n\n /** The name of the tile matrix set in the service's capabilities. */\n matrixSet: string;\n\n /**\n * Additional source options for the layer's WMTS source.\n *\n * NOTE: These options are intended for advanced configuration:\n * the WMTS Layer manages some of the OpenLayers source options itself.\n */\n sourceOptions?: Partial<WMSSourceOptions>;\n}\nexport interface WMTSLayer extends Layer {\n /** URL of the WMTS service. */\n readonly url: string;\n\n /** The name of the WMTS layer in the service's capabilities. */\n readonly name: string;\n\n /** The name of the tile matrix set in the service's capabilities. */\n readonly matrixSet: string;\n}\nexport interface WMTSLayerConstructor {\n prototype: WMTSLayer;\n\n /** Creates a new {@link WMTSLayer}. */\n new (config: WMTSLayerConfig): WMTSLayer;\n}\n\nexport const WMTSLayer: WMTSLayerConstructor = WMTSLayerImpl;\n"],"names":[],"mappings":";;AAwCO,MAAM,SAAkC,GAAA;;;;"}
1
+ {"version":3,"file":"WMTSLayer.js","sources":["WMTSLayer.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport type { Options as WMSSourceOptions } from \"ol/source/ImageWMS\";\nimport { LayerBaseType, LayerConfig } from \"./base\";\nimport { WMTSLayerImpl } from \"../../model/layers/WMTSLayerImpl\";\n\nexport interface WMTSLayerConfig extends LayerConfig {\n /** URL of the WMTS service. */\n url: string;\n\n /** The name of the WMTS layer in the service's capabilities. */\n name: string;\n\n /** The name of the tile matrix set in the service's capabilities. */\n matrixSet: string;\n\n /**\n * Additional source options for the layer's WMTS source.\n *\n * NOTE: These options are intended for advanced configuration:\n * the WMTS Layer manages some of the OpenLayers source options itself.\n */\n sourceOptions?: Partial<WMSSourceOptions>;\n}\n\nexport interface WMTSLayer extends LayerBaseType {\n readonly type: \"wmts\";\n\n /** URL of the WMTS service. */\n readonly url: string;\n\n /** The name of the WMTS layer in the service's capabilities. */\n readonly name: string;\n\n /** The name of the tile matrix set in the service's capabilities. */\n readonly matrixSet: string;\n\n readonly layers: undefined;\n}\n\nexport interface WMTSLayerConstructor {\n prototype: WMTSLayer;\n\n /** Creates a new {@link WMTSLayer}. */\n new (config: WMTSLayerConfig): WMTSLayer;\n}\n\nexport const WMTSLayer: WMTSLayerConstructor = WMTSLayerImpl;\n"],"names":[],"mappings":";;AA+CO,MAAM,SAAkC,GAAA;;;;"}
@@ -2,21 +2,18 @@ import type { EventSource } from "@open-pioneer/core";
2
2
  import type OlBaseLayer from "ol/layer/Base";
3
3
  import type { MapModel } from "../MapModel";
4
4
  import type { LayerRetrievalOptions } from "../shared";
5
+ import type { SimpleLayer } from "./SimpleLayer";
6
+ import type { WMSLayer, WMSSublayer } from "./WMSLayer";
7
+ import type { WMTSLayer } from "./WMTSLayer";
8
+ import type { GroupLayer, GroupLayerCollection } from "./GroupLayer";
5
9
  /** Events emitted by the {@link Layer} and other layer types. */
6
10
  export interface LayerBaseEvents {
7
- "changed": void;
8
- "changed:title": void;
9
- "changed:legend": void;
10
- "changed:description": void;
11
- "changed:visible": void;
12
- "changed:attributes": void;
13
- "changed:loadState": void;
14
11
  "destroy": void;
15
12
  }
16
13
  /** The load state of a layer. */
17
14
  export type LayerLoadState = "not-loaded" | "loading" | "loaded" | "error";
18
15
  /** Custom function to check the state of a layer and returning a "loaded" or "error". */
19
- export type HealthCheckFunction = (layer: LayerBase) => Promise<"loaded" | "error">;
16
+ export type HealthCheckFunction = (layer: Layer) => Promise<"loaded" | "error">;
20
17
  /**
21
18
  * Configuration options supported by all layer types (layers and sublayers).
22
19
  */
@@ -52,9 +49,19 @@ export interface LayerBaseConfig {
52
49
  * Instances of this interface cannot be constructed directly; use a real layer
53
50
  * class such as {@link SimpleLayer} instead.
54
51
  */
55
- export interface LayerBase<AdditionalEvents = {}> extends EventSource<LayerBaseEvents & AdditionalEvents> {
52
+ export interface AnyLayerBaseType<AdditionalEvents = {}> extends EventSource<LayerBaseEvents & AdditionalEvents> {
53
+ /**
54
+ * Identifies the type of this layer.
55
+ */
56
+ readonly type: AnyLayerTypes;
56
57
  /** The map this layer belongs to. */
57
58
  readonly map: MapModel;
59
+ /**
60
+ * The direct parent of this layer instance, used for sublayers or for layers in a group layer.
61
+ *
62
+ * The property shall be undefined if the layer is not a sublayer or member of a group layer.
63
+ */
64
+ readonly parent: AnyLayer | undefined;
58
65
  /**
59
66
  * The unique id of this layer within its map model.
60
67
  *
@@ -74,13 +81,31 @@ export interface LayerBase<AdditionalEvents = {}> extends EventSource<LayerBaseE
74
81
  */
75
82
  readonly visible: boolean;
76
83
  /**
77
- * LegendURL from the service capabilties, if available
84
+ * LegendURL from the service capabilities, if available.
78
85
  */
79
86
  readonly legend: string | undefined;
80
87
  /**
81
- * The collection of child sublayers for this layer.
88
+ * The direct children of this layer.
89
+ *
90
+ * The children may either be a set of operational layers (e.g. for a group layer) or a set of sublayers, or `undefined`.
91
+ *
92
+ * See also {@link layers} and {@link sublayers}.
93
+ */
94
+ readonly children: ChildrenCollection<AnyLayer> | undefined;
95
+ /**
96
+ * If this layer is a group layer this property contains a collection of all layers that a members to the group.
97
+ *
98
+ * The property shall be `undefined` if it is not a group layer.
99
+ *
100
+ * The properties `layers` and `sublayers` are mutually exclusive.
101
+ */
102
+ readonly layers: GroupLayerCollection | undefined;
103
+ /**
104
+ * The collection of child sublayers for this layer. Sublayers are layers that cannot exist without an appropriate parent layer.
82
105
  *
83
106
  * Layers that can never have any sublayers may not have a `sublayers` collection.
107
+ *
108
+ * The properties `layers` and `sublayers` are mutually exclusive.
84
109
  */
85
110
  readonly sublayers: SublayersCollection | undefined;
86
111
  /**
@@ -136,7 +161,11 @@ export interface LayerConfig extends LayerBaseConfig {
136
161
  * Instances of this interface cannot be constructed directly; use a real layer
137
162
  * class such as {@link SimpleLayer} instead.
138
163
  */
139
- export interface Layer<AdditionalEvents = {}> extends LayerBase<AdditionalEvents> {
164
+ export interface LayerBaseType<AdditionalEvents = {}> extends AnyLayerBaseType<AdditionalEvents> {
165
+ /**
166
+ * Identifies the type of this layer.
167
+ */
168
+ readonly type: LayerTypes;
140
169
  /**
141
170
  * The load state of a layer.
142
171
  */
@@ -155,29 +184,59 @@ export interface Layer<AdditionalEvents = {}> extends LayerBase<AdditionalEvents
155
184
  /**
156
185
  * Represents a sublayer of another layer.
157
186
  */
158
- export interface Sublayer extends LayerBase {
187
+ export interface SublayerBaseType extends AnyLayerBaseType {
188
+ /**
189
+ * Identifies the type of this sublayer.
190
+ */
191
+ readonly type: SublayerTypes;
159
192
  /**
160
193
  * The direct parent of this layer instance.
161
194
  * This can either be the parent layer or another sublayer.
162
195
  */
163
- readonly parent: Layer | Sublayer;
196
+ readonly parent: AnyLayer;
164
197
  /**
165
198
  * The parent layer that owns this sublayer.
166
199
  */
167
200
  readonly parentLayer: Layer;
168
201
  }
169
202
  /**
170
- * Events emitted by the {@link SublayersCollection}.
203
+ * Contains the children of a layer.
171
204
  */
172
- export interface SublayersCollectionEvents {
173
- changed: void;
205
+ export interface ChildrenCollection<LayerType> {
206
+ /**
207
+ * Returns the items in this collection.
208
+ */
209
+ getItems(options?: LayerRetrievalOptions): LayerType[];
174
210
  }
175
211
  /**
176
212
  * Contains the sublayers that belong to a {@link Layer} or {@link Sublayer}.
177
213
  */
178
- export interface SublayersCollection<SublayerType = Sublayer> extends EventSource<SublayersCollectionEvents> {
214
+ export interface SublayersCollection<SublayerType = Sublayer> extends ChildrenCollection<SublayerType> {
179
215
  /**
180
216
  * Returns the child sublayers in this collection.
181
217
  */
182
218
  getSublayers(options?: LayerRetrievalOptions): SublayerType[];
183
219
  }
220
+ /**
221
+ * Union type for all layers (extending {@link LayerBaseType})
222
+ */
223
+ export type Layer = SimpleLayer | WMSLayer | WMTSLayer | GroupLayer;
224
+ export type LayerTypes = Layer["type"];
225
+ /**
226
+ * Union type for all sublayers (extending {@link SublayerBaseType}
227
+ */
228
+ export type Sublayer = WMSSublayer;
229
+ export type SublayerTypes = Sublayer["type"];
230
+ /**
231
+ * Union for all types of layers
232
+ */
233
+ export type AnyLayer = Layer | Sublayer;
234
+ export type AnyLayerTypes = AnyLayer["type"];
235
+ /**
236
+ * Type guard for checking if the layer is a {@link Sublayer}.
237
+ */
238
+ export declare function isSublayer(layer: AnyLayer): layer is Sublayer;
239
+ /**
240
+ * Type guard for checking if the layer is a {@link Layer} (and not a {@link Sublayer}).
241
+ */
242
+ export declare function isLayer(layer: AnyLayer): layer is Layer;
@@ -0,0 +1,9 @@
1
+ function isSublayer(layer) {
2
+ return "parentLayer" in layer;
3
+ }
4
+ function isLayer(layer) {
5
+ return "olLayer" in layer;
6
+ }
7
+
8
+ export { isLayer, isSublayer };
9
+ //# sourceMappingURL=base.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base.js","sources":["base.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport type { EventSource } from \"@open-pioneer/core\";\nimport type OlBaseLayer from \"ol/layer/Base\";\nimport type { MapModel } from \"../MapModel\";\nimport type { LayerRetrievalOptions } from \"../shared\";\nimport type { SimpleLayer } from \"./SimpleLayer\";\nimport type { WMSLayer, WMSSublayer } from \"./WMSLayer\";\nimport type { WMTSLayer } from \"./WMTSLayer\";\nimport type { GroupLayer, GroupLayerCollection } from \"./GroupLayer\";\n\n/** Events emitted by the {@link Layer} and other layer types. */\nexport interface LayerBaseEvents {\n \"destroy\": void;\n}\n\n/** The load state of a layer. */\nexport type LayerLoadState = \"not-loaded\" | \"loading\" | \"loaded\" | \"error\";\n\n/** Custom function to check the state of a layer and returning a \"loaded\" or \"error\". */\nexport type HealthCheckFunction = (layer: Layer) => Promise<\"loaded\" | \"error\">;\n\n/**\n * Configuration options supported by all layer types (layers and sublayers).\n */\nexport interface LayerBaseConfig {\n /**\n * The unique id of this layer.\n * Defaults to a generated id.\n */\n id?: string;\n\n /**\n * The human-readable title of this layer.\n */\n title: string;\n\n /**\n * The human-readable description of this layer.\n * Defaults to an empty string.\n */\n description?: string;\n\n /**\n * Whether this layer should initially be visible.\n * Defaults to `true`.\n */\n visible?: boolean;\n\n /**\n * Additional attributes for this layer.\n * These can be arbitrary values.\n */\n attributes?: Record<string | symbol, unknown>;\n}\n\n/**\n * Interface shared by all layer types (operational layers and sublayers).\n *\n * Instances of this interface cannot be constructed directly; use a real layer\n * class such as {@link SimpleLayer} instead.\n */\nexport interface AnyLayerBaseType<AdditionalEvents = {}>\n extends EventSource<LayerBaseEvents & AdditionalEvents> {\n /**\n * Identifies the type of this layer.\n */\n readonly type: AnyLayerTypes;\n\n /** The map this layer belongs to. */\n readonly map: MapModel;\n\n /**\n * The direct parent of this layer instance, used for sublayers or for layers in a group layer.\n *\n * The property shall be undefined if the layer is not a sublayer or member of a group layer.\n */\n readonly parent: AnyLayer | undefined;\n\n /**\n * The unique id of this layer within its map model.\n *\n * NOTE: layer ids may not be globally unique: layers that belong\n * to different map models may have the same id.\n */\n readonly id: string;\n\n /** The human-readable title of this layer. */\n readonly title: string;\n\n /** The human-readable description of this layer. May be empty. */\n readonly description: string;\n\n /**\n * Whether the layer is visible or not.\n *\n * NOTE: The model's visible state may do more than influence the raw OpenLayers's visibility property.\n * Future versions may completely remove invisible layers from the OpenLayer's map under some circumstances.\n */\n readonly visible: boolean;\n\n /**\n * LegendURL from the service capabilities, if available.\n */\n readonly legend: string | undefined;\n\n /**\n * The direct children of this layer.\n *\n * The children may either be a set of operational layers (e.g. for a group layer) or a set of sublayers, or `undefined`.\n *\n * See also {@link layers} and {@link sublayers}.\n */\n readonly children: ChildrenCollection<AnyLayer> | undefined;\n\n /**\n * If this layer is a group layer this property contains a collection of all layers that a members to the group.\n *\n * The property shall be `undefined` if it is not a group layer.\n *\n * The properties `layers` and `sublayers` are mutually exclusive.\n */\n readonly layers: GroupLayerCollection | undefined;\n\n /**\n * The collection of child sublayers for this layer. Sublayers are layers that cannot exist without an appropriate parent layer.\n *\n * Layers that can never have any sublayers may not have a `sublayers` collection.\n *\n * The properties `layers` and `sublayers` are mutually exclusive.\n */\n readonly sublayers: SublayersCollection | undefined;\n\n /**\n * Additional attributes associated with this layer.\n */\n readonly attributes: Readonly<Record<string | symbol, unknown>>;\n\n /**\n * Updates the title of this layer.\n */\n setTitle(newTitle: string): void;\n\n /**\n * Updates the description of this layer.\n */\n setDescription(newDescription: string): void;\n\n /**\n * Updates the visibility of this layer to the new value.\n *\n * NOTE: The visibility of base layers cannot be changed through this method.\n * Call {@link LayerCollection.activateBaseLayer} instead.\n */\n setVisible(newVisibility: boolean): void;\n\n /**\n * Updates the attributes of this layer.\n * Values in `newAttributes` are merged into the existing ones (i.e. via `Object.assign`).\n */\n updateAttributes(newAttributes: Record<string | symbol, unknown>): void;\n\n /**\n * Deletes the attribute of this layer.\n */\n deleteAttribute(deleteAttribute: string | symbol): void;\n}\n\n/**\n * Configuration options supported by all operational layer types.\n */\nexport interface LayerConfig extends LayerBaseConfig {\n /**\n * Whether this layer is a base layer or not.\n * Only one base layer can be active at a time.\n *\n * Defaults to `false`.\n */\n isBaseLayer?: boolean;\n\n /**\n * Optional property to check the availability of the layer.\n * It is possible to provide either a URL which indicates the state of the service (2xx response meaning \"ok\")\n * or a {@link HealthCheckFunction} performing a custom check and returning the state.\n */\n healthCheck?: string | HealthCheckFunction;\n}\n\n/**\n * Represents an operational layer in the map.\n *\n * Instances of this interface cannot be constructed directly; use a real layer\n * class such as {@link SimpleLayer} instead.\n */\nexport interface LayerBaseType<AdditionalEvents = {}> extends AnyLayerBaseType<AdditionalEvents> {\n /**\n * Identifies the type of this layer.\n */\n readonly type: LayerTypes;\n\n /**\n * The load state of a layer.\n */\n readonly loadState: LayerLoadState;\n\n /**\n * The raw OpenLayers layer.\n */\n readonly olLayer: OlBaseLayer;\n\n /**\n * True if this layer is a base layer.\n *\n * Only one base layer can be visible at a time.\n */\n readonly isBaseLayer: boolean;\n}\n\n/**\n * Represents a sublayer of another layer.\n */\nexport interface SublayerBaseType extends AnyLayerBaseType {\n /**\n * Identifies the type of this sublayer.\n */\n readonly type: SublayerTypes;\n\n /**\n * The direct parent of this layer instance.\n * This can either be the parent layer or another sublayer.\n */\n readonly parent: AnyLayer;\n\n /**\n * The parent layer that owns this sublayer.\n */\n readonly parentLayer: Layer;\n}\n\n/**\n * Contains the children of a layer.\n */\nexport interface ChildrenCollection<LayerType> {\n /**\n * Returns the items in this collection.\n */\n getItems(options?: LayerRetrievalOptions): LayerType[];\n}\n\n/**\n * Contains the sublayers that belong to a {@link Layer} or {@link Sublayer}.\n */\nexport interface SublayersCollection<SublayerType = Sublayer>\n extends ChildrenCollection<SublayerType> {\n /**\n * Returns the child sublayers in this collection.\n */\n getSublayers(options?: LayerRetrievalOptions): SublayerType[];\n}\n\n/**\n * Union type for all layers (extending {@link LayerBaseType})\n */\nexport type Layer = SimpleLayer | WMSLayer | WMTSLayer | GroupLayer;\nexport type LayerTypes = Layer[\"type\"];\n\n/**\n * Union type for all sublayers (extending {@link SublayerBaseType}\n */\nexport type Sublayer = WMSSublayer;\nexport type SublayerTypes = Sublayer[\"type\"];\n\n/**\n * Union for all types of layers\n */\nexport type AnyLayer = Layer | Sublayer;\nexport type AnyLayerTypes = AnyLayer[\"type\"];\n\n/**\n * Type guard for checking if the layer is a {@link Sublayer}.\n */\nexport function isSublayer(layer: AnyLayer): layer is Sublayer {\n return \"parentLayer\" in layer;\n}\n\n/**\n * Type guard for checking if the layer is a {@link Layer} (and not a {@link Sublayer}).\n */\nexport function isLayer(layer: AnyLayer): layer is Layer {\n return \"olLayer\" in layer;\n}\n"],"names":[],"mappings":"AAyRO,SAAS,WAAW,KAAoC,EAAA;AAC3D,EAAA,OAAO,aAAiB,IAAA,KAAA,CAAA;AAC5B,CAAA;AAKO,SAAS,QAAQ,KAAiC,EAAA;AACrD,EAAA,OAAO,SAAa,IAAA,KAAA,CAAA;AACxB;;;;"}
@@ -2,3 +2,4 @@ export * from "./base";
2
2
  export * from "./SimpleLayer";
3
3
  export * from "./WMSLayer";
4
4
  export * from "./WMTSLayer";
5
+ export * from "./GroupLayer";
package/index.js CHANGED
@@ -1,12 +1,15 @@
1
+ export { isLayer, isSublayer } from './api/layers/base.js';
1
2
  export { SimpleLayer } from './api/layers/SimpleLayer.js';
2
3
  export { WMSLayer } from './api/layers/WMSLayer.js';
3
4
  export { WMTSLayer } from './api/layers/WMTSLayer.js';
5
+ export { GroupLayer } from './api/layers/GroupLayer.js';
4
6
  export { getProjection, registerProjections } from './projections.js';
5
7
  export { BkgTopPlusOpen } from './layers/BkgTopPlusOpen.js';
6
8
  export { useCenter, useProjection, useResolution, useScale, useView } from './ui/hooks.js';
7
9
  export { MapAnchor } from './ui/MapAnchor.js';
8
10
  export { MapContainer } from './ui/MapContainer.js';
9
11
  export { useMapModel } from './ui/useMapModel.js';
12
+ export { DefaultMapProvider } from './ui/DefaultMapProvider.js';
10
13
  export { calculateBufferedExtent } from './util/geometry-utils.js';
11
14
  export { TOPMOST_LAYER_Z } from './model/LayerCollectionImpl.js';
12
15
  //# sourceMappingURL=index.js.map
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;"}
@@ -1,5 +1,5 @@
1
1
  import OlBaseLayer from "ol/layer/Base";
2
- import { Layer, LayerLoadState, SimpleLayerConfig } from "../api";
2
+ import { LayerBaseType, LayerLoadState, SimpleLayerConfig } from "../api";
3
3
  import { AbstractLayerBase } from "./AbstractLayerBase";
4
4
  import { MapModelImpl } from "./MapModelImpl";
5
5
  /**
@@ -7,7 +7,7 @@ import { MapModelImpl } from "./MapModelImpl";
7
7
  *
8
8
  * These layers always have an associated OpenLayers layer.
9
9
  */
10
- export declare abstract class AbstractLayer<AdditionalEvents = {}> extends AbstractLayerBase<AdditionalEvents> implements Layer {
10
+ export declare abstract class AbstractLayer<AdditionalEvents = {}> extends AbstractLayerBase<AdditionalEvents> implements LayerBaseType {
11
11
  #private;
12
12
  constructor(config: SimpleLayerConfig);
13
13
  get visible(): boolean;
@@ -18,7 +18,8 @@ export declare abstract class AbstractLayer<AdditionalEvents = {}> extends Abstr
18
18
  /**
19
19
  * Called by the map model when the layer is added to the map.
20
20
  */
21
- __attach(map: MapModelImpl): void;
21
+ __attachToMap(map: MapModelImpl): void;
22
22
  setVisible(newVisibility: boolean): void;
23
23
  __setVisible(newVisibility: boolean): void;
24
+ abstract readonly type: "simple" | "wms" | "wmts" | "group";
24
25
  }
@@ -1,4 +1,5 @@
1
- import { createLogger } from '@open-pioneer/core';
1
+ import { external, reactive } from '@conterra/reactivity-core';
2
+ import { createLogger, destroyResource } from '@open-pioneer/core';
2
3
  import { unByKey } from 'ol/Observable.js';
3
4
  import OlLayer from 'ol/layer/Layer.js';
4
5
  import { AbstractLayerBase } from './AbstractLayerBase.js';
@@ -10,18 +11,20 @@ class AbstractLayer extends AbstractLayerBase {
10
11
  #healthCheck;
11
12
  #visible;
12
13
  #loadState;
14
+ #visibilityWatchKey;
13
15
  #stateWatchResource;
14
16
  constructor(config) {
15
17
  super(config);
16
18
  this.#olLayer = config.olLayer;
17
19
  this.#isBaseLayer = config.isBaseLayer ?? false;
18
20
  this.#healthCheck = config.healthCheck;
19
- this.#visible = config.visible ?? true;
20
- this.#loadState = getSourceState(getSource(this.#olLayer));
21
- this.__setVisible(this.#visible);
21
+ this.#visible = external(() => this.#olLayer.getVisible());
22
+ this.#visibilityWatchKey = this.#olLayer.on("change:visible", this.#visible.trigger);
23
+ this.#loadState = reactive(getSourceState(getSource(this.#olLayer)));
24
+ this.__setVisible(config.visible ?? true);
22
25
  }
23
26
  get visible() {
24
- return this.#visible;
27
+ return this.#visible.value;
25
28
  }
26
29
  get olLayer() {
27
30
  return this.#olLayer;
@@ -30,30 +33,32 @@ class AbstractLayer extends AbstractLayerBase {
30
33
  return this.#isBaseLayer;
31
34
  }
32
35
  get loadState() {
33
- return this.#loadState;
36
+ return this.#loadState.value;
34
37
  }
35
38
  destroy() {
36
39
  if (this.__destroyed) {
37
40
  return;
38
41
  }
39
- this.#stateWatchResource?.destroy();
42
+ this.#stateWatchResource = destroyResource(this.#stateWatchResource);
43
+ this.#visibilityWatchKey && unByKey(this.#visibilityWatchKey);
44
+ this.#visibilityWatchKey = void 0;
40
45
  this.olLayer.dispose();
41
46
  super.destroy();
42
47
  }
43
48
  /**
44
49
  * Called by the map model when the layer is added to the map.
45
50
  */
46
- __attach(map) {
51
+ __attachToMap(map) {
47
52
  super.__attachToMap(map);
48
53
  const { initial: initialState, resource: stateWatchResource } = watchLoadState(
49
54
  this,
50
55
  this.#healthCheck,
51
56
  (state) => {
52
- this.#setLoadState(state);
57
+ this.#loadState.value = state;
53
58
  }
54
59
  );
55
60
  this.#stateWatchResource = stateWatchResource;
56
- this.#setLoadState(initialState);
61
+ this.#loadState.value = initialState;
57
62
  }
58
63
  setVisible(newVisibility) {
59
64
  if (this.isBaseLayer) {
@@ -65,21 +70,9 @@ class AbstractLayer extends AbstractLayerBase {
65
70
  this.__setVisible(newVisibility);
66
71
  }
67
72
  __setVisible(newVisibility) {
68
- let changed = false;
69
- if (this.#visible !== newVisibility) {
70
- this.#visible = newVisibility;
71
- changed = true;
72
- }
73
- if (this.#olLayer.getVisible() != this.#visible) {
73
+ if (this.#olLayer.getVisible() !== newVisibility) {
74
74
  this.#olLayer.setVisible(newVisibility);
75
75
  }
76
- changed && this.__emitChangeEvent("changed:visible");
77
- }
78
- #setLoadState(loadState) {
79
- if (loadState !== this.#loadState) {
80
- this.#loadState = loadState;
81
- this.__emitChangeEvent("changed:loadState");
82
- }
83
76
  }
84
77
  }
85
78
  function watchLoadState(layer, healthCheck, onChange) {
@@ -1 +1 @@
1
- {"version":3,"file":"AbstractLayer.js","sources":["AbstractLayer.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { Resource, createLogger } from \"@open-pioneer/core\";\nimport { unByKey } from \"ol/Observable\";\nimport { EventsKey } from \"ol/events\";\nimport OlBaseLayer from \"ol/layer/Base\";\nimport OlLayer from \"ol/layer/Layer\";\nimport OlSource from \"ol/source/Source\";\nimport { HealthCheckFunction, Layer, LayerConfig, LayerLoadState, SimpleLayerConfig } from \"../api\";\nimport { AbstractLayerBase } from \"./AbstractLayerBase\";\nimport { MapModelImpl } from \"./MapModelImpl\";\n\nconst LOG = createLogger(\"map:AbstractLayer\");\n\n/**\n * Base class for normal layer types.\n *\n * These layers always have an associated OpenLayers layer.\n */\nexport abstract class AbstractLayer<AdditionalEvents = {}>\n extends AbstractLayerBase<AdditionalEvents>\n implements Layer\n{\n #olLayer: OlBaseLayer;\n #isBaseLayer: boolean;\n #healthCheck?: string | HealthCheckFunction;\n #visible: boolean;\n\n #loadState: LayerLoadState;\n #stateWatchResource: Resource | undefined;\n\n constructor(config: SimpleLayerConfig) {\n super(config);\n this.#olLayer = config.olLayer;\n this.#isBaseLayer = config.isBaseLayer ?? false;\n this.#healthCheck = config.healthCheck;\n\n this.#visible = config.visible ?? true;\n this.#loadState = getSourceState(getSource(this.#olLayer));\n\n this.__setVisible(this.#visible); // apply initial visibility\n }\n\n get visible(): boolean {\n return this.#visible;\n }\n\n get olLayer(): OlBaseLayer {\n return this.#olLayer;\n }\n\n get isBaseLayer(): boolean {\n return this.#isBaseLayer;\n }\n\n get loadState(): LayerLoadState {\n return this.#loadState;\n }\n\n destroy() {\n if (this.__destroyed) {\n return;\n }\n\n this.#stateWatchResource?.destroy();\n this.olLayer.dispose();\n super.destroy();\n }\n\n /**\n * Called by the map model when the layer is added to the map.\n */\n __attach(map: MapModelImpl): void {\n super.__attachToMap(map);\n\n const { initial: initialState, resource: stateWatchResource } = watchLoadState(\n this,\n this.#healthCheck,\n (state) => {\n this.#setLoadState(state);\n }\n );\n this.#stateWatchResource = stateWatchResource;\n this.#setLoadState(initialState);\n }\n\n setVisible(newVisibility: boolean): void {\n if (this.isBaseLayer) {\n LOG.warn(\n `Cannot change visibility of base layer '${this.id}': use activateBaseLayer() on the map's LayerCollection instead.`\n );\n return;\n }\n\n this.__setVisible(newVisibility);\n }\n\n __setVisible(newVisibility: boolean): void {\n let changed = false;\n if (this.#visible !== newVisibility) {\n this.#visible = newVisibility;\n changed = true;\n }\n\n // Improvement: actual map sync?\n if (this.#olLayer.getVisible() != this.#visible) {\n this.#olLayer.setVisible(newVisibility);\n }\n changed && this.__emitChangeEvent(\"changed:visible\");\n }\n\n #setLoadState(loadState: LayerLoadState) {\n if (loadState !== this.#loadState) {\n this.#loadState = loadState;\n this.__emitChangeEvent(\"changed:loadState\");\n }\n }\n}\n\nfunction watchLoadState(\n layer: AbstractLayer,\n healthCheck: LayerConfig[\"healthCheck\"],\n onChange: (newState: LayerLoadState) => void\n): { initial: LayerLoadState; resource: Resource } {\n const olLayer = layer.olLayer;\n\n if (!(olLayer instanceof OlLayer)) {\n // Some layers don't have a source (such as group)\n return {\n initial: \"loaded\",\n resource: {\n destroy() {\n void 0;\n }\n }\n };\n }\n\n let currentSource = getSource(olLayer);\n const currentOlLayerState = getSourceState(currentSource);\n\n let currentLoadState: LayerLoadState = currentOlLayerState;\n let currentHealthState = \"loading\"; // initial state loading until health check finished\n\n // custom health check not needed when OpenLayers already returning an error state\n if (currentOlLayerState !== \"error\") {\n // health check only once during initialization\n doHealthCheck(layer, healthCheck).then((state: LayerLoadState) => {\n currentHealthState = state;\n updateState();\n });\n }\n\n const updateState = () => {\n const olLayerState = getSourceState(currentSource);\n const nextLoadState: LayerLoadState =\n currentHealthState === \"error\" ? \"error\" : olLayerState;\n\n if (currentLoadState !== nextLoadState) {\n currentLoadState = nextLoadState;\n onChange(currentLoadState);\n }\n };\n\n let stateHandle: EventsKey | undefined;\n stateHandle = currentSource?.on(\"change\", () => {\n updateState();\n });\n\n const sourceHandle = olLayer.on(\"change:source\", () => {\n // unsubscribe from old source\n stateHandle && unByKey(stateHandle);\n stateHandle = undefined;\n\n // subscribe to new source and update state\n currentSource = getSource(olLayer);\n stateHandle = currentSource?.on(\"change\", () => {\n updateState();\n });\n updateState();\n });\n return {\n initial: currentLoadState,\n resource: {\n destroy() {\n stateHandle && unByKey(stateHandle);\n unByKey(sourceHandle);\n }\n }\n };\n}\n\nasync function doHealthCheck(\n layer: AbstractLayer,\n healthCheck: LayerConfig[\"healthCheck\"]\n): Promise<LayerLoadState> {\n if (healthCheck == null) {\n return \"loaded\";\n }\n\n let healthCheckFn: HealthCheckFunction;\n if (typeof healthCheck === \"function\") {\n healthCheckFn = healthCheck;\n } else if (typeof healthCheck === \"string\") {\n healthCheckFn = async () => {\n const httpService = layer.map.__sharedDependencies.httpService;\n const response = await httpService.fetch(healthCheck);\n if (response.ok) {\n return \"loaded\";\n }\n LOG.warn(\n `Health check failed for layer '${layer.id}' (http status ${response.status})`\n );\n return \"error\";\n };\n } else {\n LOG.error(\n `Unexpected object for 'healthCheck' parameter of layer '${layer.id}'`,\n healthCheck\n );\n return \"error\";\n }\n\n try {\n return await healthCheckFn(layer);\n } catch (e) {\n LOG.warn(`Health check failed for layer '${layer.id}'`, e);\n return \"error\";\n }\n}\n\nfunction getSource(olLayer: OlLayer | OlBaseLayer) {\n if (!(olLayer instanceof OlLayer)) {\n return undefined;\n }\n return (olLayer?.getSource() as OlSource | null) ?? undefined;\n}\n\nfunction getSourceState(olSource: OlSource | undefined) {\n const state = olSource?.getState();\n switch (state) {\n case undefined:\n return \"loaded\";\n case \"undefined\":\n return \"not-loaded\";\n case \"loading\":\n return \"loading\";\n case \"ready\":\n return \"loaded\";\n case \"error\":\n return \"error\";\n }\n}\n"],"names":[],"mappings":";;;;;AAYA,MAAM,GAAA,GAAM,aAAa,mBAAmB,CAAA,CAAA;AAOrC,MAAe,sBACV,iBAEZ,CAAA;AAAA,EACI,QAAA,CAAA;AAAA,EACA,YAAA,CAAA;AAAA,EACA,YAAA,CAAA;AAAA,EACA,QAAA,CAAA;AAAA,EAEA,UAAA,CAAA;AAAA,EACA,mBAAA,CAAA;AAAA,EAEA,YAAY,MAA2B,EAAA;AACnC,IAAA,KAAA,CAAM,MAAM,CAAA,CAAA;AACZ,IAAA,IAAA,CAAK,WAAW,MAAO,CAAA,OAAA,CAAA;AACvB,IAAK,IAAA,CAAA,YAAA,GAAe,OAAO,WAAe,IAAA,KAAA,CAAA;AAC1C,IAAA,IAAA,CAAK,eAAe,MAAO,CAAA,WAAA,CAAA;AAE3B,IAAK,IAAA,CAAA,QAAA,GAAW,OAAO,OAAW,IAAA,IAAA,CAA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OAAA,MAAM,cAAc,KAAK,CAAA,CAAA;AAAA,WAC3B,CAAG,EAAA;AACR,IAAA,GAAA,CAAI,IAAK,CAAA,CAAA,+BAAA,EAAkC,KAAM,CAAA,EAAE,KAAK,CAAC,CAAA,CAAA;AACzD,IAAO,OAAA,OAAA,CAAA;AAAA,GACX;AACJ,CAAA;AAEA,SAAS,UAAU,OAAgC,EAAA;AAC/C,EAAI,IAAA,EAAE,mBAAmB,OAAU,CAAA,EAAA;AAC/B,IAAO,OAAA,KAAA,CAAA,CAAA;AAAA,GACX;AACA,EAAQ,OAAA,OAAA,EAAS,WAAmC,IAAA,KAAA,CAAA,CAAA;AACxD,CAAA;AAEA,SAAS,eAAe,QAAgC,EAAA;AACpD,EAAM,MAAA,KAAA,GAAQ,UAAU,QAAS,EAAA,CAAA;AACjC,EAAA,QAAQ,KAAO;AAAA,IACX,KAAK,KAAA,CAAA;AACD,MAAO,OAAA,QAAA,CAAA;AAAA,IACX,KAAK,WAAA;AACD,MAAO,OAAA,YAAA,CAAA;AAAA,IACX,KAAK,SAAA;AACD,MAAO,OAAA,SAAA,CAAA;AAAA,IACX,KAAK,OAAA;AACD,MAAO,OAAA,QAAA,CAAA;AAAA,IACX,KAAK,OAAA;AACD,MAAO,OAAA,OAAA,CAAA;AAAA,GACf;AACJ;;;;"}
1
+ {"version":3,"file":"AbstractLayer.js","sources":["AbstractLayer.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { ExternalReactive, reactive, external, Reactive } from \"@conterra/reactivity-core\";\nimport { createLogger, destroyResource, Resource } from \"@open-pioneer/core\";\nimport { unByKey } from \"ol/Observable\";\nimport { EventsKey } from \"ol/events\";\nimport OlBaseLayer from \"ol/layer/Base\";\nimport OlLayer from \"ol/layer/Layer\";\nimport OlSource from \"ol/source/Source\";\nimport {\n HealthCheckFunction,\n Layer,\n LayerBaseType,\n LayerConfig,\n LayerLoadState,\n SimpleLayerConfig\n} from \"../api\";\nimport { AbstractLayerBase } from \"./AbstractLayerBase\";\nimport { MapModelImpl } from \"./MapModelImpl\";\n\nconst LOG = createLogger(\"map:AbstractLayer\");\n\n/**\n * Base class for normal layer types.\n *\n * These layers always have an associated OpenLayers layer.\n */\nexport abstract class AbstractLayer<AdditionalEvents = {}>\n extends AbstractLayerBase<AdditionalEvents>\n implements LayerBaseType\n{\n #olLayer: OlBaseLayer;\n #isBaseLayer: boolean;\n #healthCheck?: string | HealthCheckFunction;\n\n #visible: ExternalReactive<boolean>;\n #loadState: Reactive<LayerLoadState>;\n\n #visibilityWatchKey: EventsKey | undefined;\n #stateWatchResource: Resource | undefined;\n\n constructor(config: SimpleLayerConfig) {\n super(config);\n this.#olLayer = config.olLayer;\n this.#isBaseLayer = config.isBaseLayer ?? false;\n this.#healthCheck = config.healthCheck;\n\n this.#visible = external(() => this.#olLayer.getVisible());\n this.#visibilityWatchKey = this.#olLayer.on(\"change:visible\", this.#visible.trigger);\n\n this.#loadState = reactive(getSourceState(getSource(this.#olLayer)));\n this.__setVisible(config.visible ?? true); // apply initial visibility\n }\n\n get visible(): boolean {\n return this.#visible.value;\n }\n\n get olLayer(): OlBaseLayer {\n return this.#olLayer;\n }\n\n get isBaseLayer(): boolean {\n return this.#isBaseLayer;\n }\n\n get loadState(): LayerLoadState {\n return this.#loadState.value;\n }\n\n destroy() {\n if (this.__destroyed) {\n return;\n }\n\n this.#stateWatchResource = destroyResource(this.#stateWatchResource);\n this.#visibilityWatchKey && unByKey(this.#visibilityWatchKey);\n this.#visibilityWatchKey = undefined;\n this.olLayer.dispose();\n super.destroy();\n }\n\n /**\n * Called by the map model when the layer is added to the map.\n */\n __attachToMap(map: MapModelImpl): void {\n super.__attachToMap(map);\n\n const { initial: initialState, resource: stateWatchResource } = watchLoadState(\n this,\n this.#healthCheck,\n (state) => {\n this.#loadState.value = state;\n }\n );\n this.#stateWatchResource = stateWatchResource;\n this.#loadState.value = initialState;\n }\n\n setVisible(newVisibility: boolean): void {\n if (this.isBaseLayer) {\n LOG.warn(\n `Cannot change visibility of base layer '${this.id}': use activateBaseLayer() on the map's LayerCollection instead.`\n );\n return;\n }\n\n this.__setVisible(newVisibility);\n }\n\n __setVisible(newVisibility: boolean): void {\n if (this.#olLayer.getVisible() !== newVisibility) {\n this.#olLayer.setVisible(newVisibility);\n }\n }\n\n abstract readonly type: \"simple\" | \"wms\" | \"wmts\" | \"group\";\n}\n\nfunction watchLoadState(\n layer: AbstractLayer,\n healthCheck: LayerConfig[\"healthCheck\"],\n onChange: (newState: LayerLoadState) => void\n): { initial: LayerLoadState; resource: Resource } {\n const olLayer = layer.olLayer;\n\n if (!(olLayer instanceof OlLayer)) {\n // Some layers don't have a source (such as group)\n return {\n initial: \"loaded\",\n resource: {\n destroy() {\n void 0;\n }\n }\n };\n }\n\n let currentSource = getSource(olLayer);\n const currentOlLayerState = getSourceState(currentSource);\n\n let currentLoadState: LayerLoadState = currentOlLayerState;\n let currentHealthState = \"loading\"; // initial state loading until health check finished\n\n // custom health check not needed when OpenLayers already returning an error state\n if (currentOlLayerState !== \"error\") {\n // health check only once during initialization\n doHealthCheck(layer, healthCheck).then((state: LayerLoadState) => {\n currentHealthState = state;\n updateState();\n });\n }\n\n const updateState = () => {\n const olLayerState = getSourceState(currentSource);\n const nextLoadState: LayerLoadState =\n currentHealthState === \"error\" ? \"error\" : olLayerState;\n\n if (currentLoadState !== nextLoadState) {\n currentLoadState = nextLoadState;\n onChange(currentLoadState);\n }\n };\n\n let stateHandle: EventsKey | undefined;\n stateHandle = currentSource?.on(\"change\", () => {\n updateState();\n });\n\n const sourceHandle = olLayer.on(\"change:source\", () => {\n // unsubscribe from old source\n stateHandle && unByKey(stateHandle);\n stateHandle = undefined;\n\n // subscribe to new source and update state\n currentSource = getSource(olLayer);\n stateHandle = currentSource?.on(\"change\", () => {\n updateState();\n });\n updateState();\n });\n return {\n initial: currentLoadState,\n resource: {\n destroy() {\n stateHandle && unByKey(stateHandle);\n unByKey(sourceHandle);\n }\n }\n };\n}\n\nasync function doHealthCheck(\n layer: AbstractLayer,\n healthCheck: LayerConfig[\"healthCheck\"]\n): Promise<LayerLoadState> {\n if (healthCheck == null) {\n return \"loaded\";\n }\n\n let healthCheckFn: HealthCheckFunction;\n if (typeof healthCheck === \"function\") {\n healthCheckFn = healthCheck;\n } else if (typeof healthCheck === \"string\") {\n healthCheckFn = async () => {\n const httpService = layer.map.__sharedDependencies.httpService;\n const response = await httpService.fetch(healthCheck);\n if (response.ok) {\n return \"loaded\";\n }\n LOG.warn(\n `Health check failed for layer '${layer.id}' (http status ${response.status})`\n );\n return \"error\";\n };\n } else {\n LOG.error(\n `Unexpected object for 'healthCheck' parameter of layer '${layer.id}'`,\n healthCheck\n );\n return \"error\";\n }\n\n try {\n return await healthCheckFn(layer as Layer);\n } catch (e) {\n LOG.warn(`Health check failed for layer '${layer.id}'`, e);\n return \"error\";\n }\n}\n\nfunction getSource(olLayer: OlLayer | OlBaseLayer) {\n if (!(olLayer instanceof OlLayer)) {\n return undefined;\n }\n return (olLayer?.getSource() as OlSource | null) ?? undefined;\n}\n\nfunction getSourceState(olSource: OlSource | undefined) {\n const state = olSource?.getState();\n switch (state) {\n case undefined:\n return \"loaded\";\n case \"undefined\":\n return \"not-loaded\";\n case \"loading\":\n return \"loading\";\n case \"ready\":\n return \"loaded\";\n case \"error\":\n return \"error\";\n }\n}\n"],"names":[],"mappings":";;;;;;AAoBA,MAAM,GAAA,GAAM,aAAa,mBAAmB,CAAA,CAAA;AAOrC,MAAe,sBACV,iBAEZ,CAAA;AAAA,EACI,QAAA,CAAA;AAAA,EACA,YAAA,CAAA;AAAA,EACA,YAAA,CAAA;AAAA,EAEA,QAAA,CAAA;AAAA,EACA,UAAA,CAAA;AAAA,EAEA,mBAAA,CAAA;AAAA,EACA,mBAAA,CAAA;AAAA,EAEA,YAAY,MAA2B,EAAA;AACnC,IAAA,KAAA,CAAM,MAAM,CAAA,CAAA;AACZ,IA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D,MAAM,EAAE,CAAA,CAAA,CAAA;AAAA,MACnE,WAAA;AAAA,KACJ,CAAA;AACA,IAAO,OAAA,OAAA,CAAA;AAAA,GACX;AAEA,EAAI,IAAA;AACA,IAAO,OAAA,MAAM,cAAc,KAAc,CAAA,CAAA;AAAA,WACpC,CAAG,EAAA;AACR,IAAA,GAAA,CAAI,IAAK,CAAA,CAAA,+BAAA,EAAkC,KAAM,CAAA,EAAE,KAAK,CAAC,CAAA,CAAA;AACzD,IAAO,OAAA,OAAA,CAAA;AAAA,GACX;AACJ,CAAA;AAEA,SAAS,UAAU,OAAgC,EAAA;AAC/C,EAAI,IAAA,EAAE,mBAAmB,OAAU,CAAA,EAAA;AAC/B,IAAO,OAAA,KAAA,CAAA,CAAA;AAAA,GACX;AACA,EAAQ,OAAA,OAAA,EAAS,WAAmC,IAAA,KAAA,CAAA,CAAA;AACxD,CAAA;AAEA,SAAS,eAAe,QAAgC,EAAA;AACpD,EAAM,MAAA,KAAA,GAAQ,UAAU,QAAS,EAAA,CAAA;AACjC,EAAA,QAAQ,KAAO;AAAA,IACX,KAAK,KAAA,CAAA;AACD,MAAO,OAAA,QAAA,CAAA;AAAA,IACX,KAAK,WAAA;AACD,MAAO,OAAA,YAAA,CAAA;AAAA,IACX,KAAK,SAAA;AACD,MAAO,OAAA,SAAA,CAAA;AAAA,IACX,KAAK,OAAA;AACD,MAAO,OAAA,QAAA,CAAA;AAAA,IACX,KAAK,OAAA;AACD,MAAO,OAAA,OAAA,CAAA;AAAA,GACf;AACJ;;;;"}
@@ -1,5 +1,7 @@
1
- import { EventEmitter, EventNames } from "@open-pioneer/core";
2
- import { LayerBase, LayerBaseEvents, Sublayer } from "../api";
1
+ import { EventEmitter } from "@open-pioneer/core";
2
+ import { AnyLayer, AnyLayerBaseType, AnyLayerTypes, ChildrenCollection, LayerBaseEvents, Sublayer } from "../api";
3
+ import { GroupLayer } from "../api/layers/GroupLayer";
4
+ import { GroupLayerCollectionImpl } from "./layers/GroupLayerImpl";
3
5
  import { MapModelImpl } from "./MapModelImpl";
4
6
  import { SublayersCollectionImpl } from "./SublayersCollectionImpl";
5
7
  export interface AbstractLayerBaseOptions {
@@ -12,7 +14,7 @@ export interface AbstractLayerBaseOptions {
12
14
  * Base class for "normal" layers and sublayers alike to implement common properties
13
15
  * such as id, title and attributes.
14
16
  */
15
- export declare abstract class AbstractLayerBase<AdditionalEvents = {}> extends EventEmitter<LayerBaseEvents & AdditionalEvents> implements LayerBase {
17
+ export declare abstract class AbstractLayerBase<AdditionalEvents = {}> extends EventEmitter<LayerBaseEvents & AdditionalEvents> implements AnyLayerBaseType {
16
18
  #private;
17
19
  constructor(config: AbstractLayerBaseOptions);
18
20
  protected get __destroyed(): boolean;
@@ -21,18 +23,32 @@ export declare abstract class AbstractLayerBase<AdditionalEvents = {}> extends E
21
23
  get title(): string;
22
24
  get description(): string;
23
25
  get attributes(): Record<string | symbol, unknown>;
26
+ get parent(): AnyLayer | undefined;
27
+ get children(): ChildrenCollection<AnyLayer & AbstractLayerBase> | undefined;
28
+ abstract get type(): AnyLayerTypes;
24
29
  abstract get visible(): boolean;
30
+ abstract get layers(): GroupLayerCollectionImpl | undefined;
25
31
  abstract get sublayers(): SublayersCollectionImpl<Sublayer & AbstractLayerBase> | undefined;
26
32
  abstract get legend(): string | undefined;
27
33
  destroy(): void;
28
34
  /**
29
35
  * Attaches the layer to its owning map.
30
36
  */
31
- protected __attachToMap(map: MapModelImpl): void;
37
+ __attachToMap(map: MapModelImpl): void;
38
+ /**
39
+ * Attach group layers to its parent group layer.
40
+ * Called by the parent layer.
41
+ */
42
+ __attachToGroup(parent: GroupLayer): void;
43
+ /**
44
+ * Detach layer from parent group layer.
45
+ *
46
+ * Called by the parent group layer when destroyed or the layer gets removed.
47
+ */
48
+ __detachFromGroup(): void;
32
49
  setTitle(newTitle: string): void;
33
50
  setDescription(newDescription: string): void;
34
51
  updateAttributes(newAttributes: Record<string | symbol, unknown>): void;
35
52
  deleteAttribute(deleteAttribute: string | symbol): void;
36
53
  abstract setVisible(newVisibility: boolean): void;
37
- protected __emitChangeEvent<Name extends EventNames<LayerBaseEvents & AdditionalEvents>>(event: Name): void;
38
54
  }
@@ -1,20 +1,28 @@
1
+ import { reactiveMap, computed, reactive, batch } from '@conterra/reactivity-core';
1
2
  import { createLogger, EventEmitter } from '@open-pioneer/core';
2
3
  import { v4 } from 'uuid';
3
4
 
4
5
  const LOG = createLogger("map:AbstractLayerModel");
5
6
  class AbstractLayerBase extends EventEmitter {
6
7
  #map;
8
+ #parent;
7
9
  #id;
8
10
  #title;
9
11
  #description;
12
+ #attributesMap = reactiveMap();
10
13
  #attributes;
11
14
  #destroyed = false;
12
15
  constructor(config) {
13
16
  super();
14
17
  this.#id = config.id ?? v4();
15
- this.#attributes = config.attributes ?? {};
16
- this.#title = config.title;
17
- this.#description = config.description ?? "";
18
+ this.#attributes = computed(() => {
19
+ return Object.fromEntries(this.#attributesMap.entries());
20
+ });
21
+ this.#title = reactive(config.title);
22
+ this.#description = reactive(config.description ?? "");
23
+ if (config.attributes) {
24
+ this.updateAttributes(config.attributes);
25
+ }
18
26
  }
19
27
  get __destroyed() {
20
28
  return this.#destroyed;
@@ -30,13 +38,19 @@ class AbstractLayerBase extends EventEmitter {
30
38
  return this.#id;
31
39
  }
32
40
  get title() {
33
- return this.#title;
41
+ return this.#title.value;
34
42
  }
35
43
  get description() {
36
- return this.#description;
44
+ return this.#description.value;
37
45
  }
38
46
  get attributes() {
39
- return this.#attributes;
47
+ return this.#attributes.value;
48
+ }
49
+ get parent() {
50
+ return this.#parent;
51
+ }
52
+ get children() {
53
+ return this.layers ?? this.sublayers ?? void 0;
40
54
  }
41
55
  destroy() {
42
56
  if (this.#destroyed) {
@@ -44,6 +58,7 @@ class AbstractLayerBase extends EventEmitter {
44
58
  }
45
59
  this.#destroyed = true;
46
60
  this.sublayers?.destroy();
61
+ this.layers?.destroy();
47
62
  try {
48
63
  this.emit("destroy");
49
64
  } catch (e) {
@@ -61,44 +76,42 @@ class AbstractLayerBase extends EventEmitter {
61
76
  }
62
77
  this.#map = map;
63
78
  }
64
- setTitle(newTitle) {
65
- if (newTitle !== this.#title) {
66
- this.#title = newTitle;
67
- this.__emitChangeEvent("changed:title");
79
+ /**
80
+ * Attach group layers to its parent group layer.
81
+ * Called by the parent layer.
82
+ */
83
+ __attachToGroup(parent) {
84
+ if (this.#parent) {
85
+ throw new Error(
86
+ `Layer '${this.id}' has already been attached to the group layer '${this.#parent.id}'`
87
+ );
68
88
  }
89
+ this.#parent = parent;
90
+ }
91
+ /**
92
+ * Detach layer from parent group layer.
93
+ *
94
+ * Called by the parent group layer when destroyed or the layer gets removed.
95
+ */
96
+ __detachFromGroup() {
97
+ this.#parent = void 0;
98
+ }
99
+ setTitle(newTitle) {
100
+ this.#title.value = newTitle;
69
101
  }
70
102
  setDescription(newDescription) {
71
- if (newDescription !== this.#description) {
72
- this.#description = newDescription;
73
- this.__emitChangeEvent("changed:description");
74
- }
103
+ this.#description.value = newDescription;
75
104
  }
76
105
  updateAttributes(newAttributes) {
77
- const attributes = this.#attributes;
78
106
  const keys = Reflect.ownKeys(newAttributes);
79
- let changed = false;
80
- for (const key of keys) {
81
- const existing = attributes[key];
82
- const value = newAttributes[key];
83
- if (existing !== value) {
84
- attributes[key] = value;
85
- changed = true;
107
+ batch(() => {
108
+ for (const key of keys) {
109
+ this.#attributesMap.set(key, newAttributes[key]);
86
110
  }
87
- }
88
- if (changed) {
89
- this.__emitChangeEvent("changed:attributes");
90
- }
111
+ });
91
112
  }
92
113
  deleteAttribute(deleteAttribute) {
93
- const attributes = this.#attributes;
94
- if (attributes[deleteAttribute]) {
95
- delete attributes[deleteAttribute];
96
- this.__emitChangeEvent("changed:attributes");
97
- }
98
- }
99
- __emitChangeEvent(event) {
100
- this.emit(event);
101
- this.emit("changed");
114
+ this.#attributesMap.delete(deleteAttribute);
102
115
  }
103
116
  }
104
117