@open-pioneer/map 0.7.0 → 0.8.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 (55) hide show
  1. package/CHANGELOG.md +135 -0
  2. package/README.md +116 -12
  3. package/api/MapModel.d.ts +48 -15
  4. package/api/layers/GroupLayer.d.ts +50 -0
  5. package/api/layers/GroupLayer.js +6 -0
  6. package/api/layers/GroupLayer.js.map +1 -0
  7. package/api/layers/SimpleLayer.d.ts +1 -0
  8. package/api/layers/SimpleLayer.js.map +1 -1
  9. package/api/layers/WMSLayer.d.ts +1 -0
  10. package/api/layers/WMSLayer.js.map +1 -1
  11. package/api/layers/WMTSLayer.d.ts +1 -0
  12. package/api/layers/WMTSLayer.js.map +1 -1
  13. package/api/layers/base.d.ts +35 -14
  14. package/api/layers/base.js.map +1 -1
  15. package/api/layers/index.d.ts +1 -0
  16. package/index.js +1 -0
  17. package/index.js.map +1 -1
  18. package/model/AbstractLayer.d.ts +2 -2
  19. package/model/AbstractLayer.js +16 -23
  20. package/model/AbstractLayer.js.map +1 -1
  21. package/model/AbstractLayerBase.d.ts +19 -4
  22. package/model/AbstractLayerBase.js +48 -35
  23. package/model/AbstractLayerBase.js.map +1 -1
  24. package/model/Highlights.d.ts +2 -1
  25. package/model/Highlights.js +2 -0
  26. package/model/Highlights.js.map +1 -1
  27. package/model/LayerCollectionImpl.d.ts +5 -3
  28. package/model/LayerCollectionImpl.js +27 -29
  29. package/model/LayerCollectionImpl.js.map +1 -1
  30. package/model/MapModelImpl.d.ts +12 -2
  31. package/model/MapModelImpl.js +94 -25
  32. package/model/MapModelImpl.js.map +1 -1
  33. package/model/SublayersCollectionImpl.d.ts +6 -3
  34. package/model/SublayersCollectionImpl.js +6 -4
  35. package/model/SublayersCollectionImpl.js.map +1 -1
  36. package/model/layers/GroupLayerImpl.d.ts +39 -0
  37. package/model/layers/GroupLayerImpl.js +88 -0
  38. package/model/layers/GroupLayerImpl.js.map +1 -0
  39. package/model/layers/SimpleLayerImpl.d.ts +1 -0
  40. package/model/layers/SimpleLayerImpl.js +3 -0
  41. package/model/layers/SimpleLayerImpl.js.map +1 -1
  42. package/model/layers/WMSLayerImpl.d.ts +9 -7
  43. package/model/layers/WMSLayerImpl.js +58 -51
  44. package/model/layers/WMSLayerImpl.js.map +1 -1
  45. package/model/layers/WMTSLayerImpl.d.ts +3 -5
  46. package/model/layers/WMTSLayerImpl.js +13 -13
  47. package/model/layers/WMTSLayerImpl.js.map +1 -1
  48. package/package.json +9 -8
  49. package/ui/MapContainer.js +7 -0
  50. package/ui/MapContainer.js.map +1 -1
  51. package/ui/hooks.d.ts +10 -0
  52. package/ui/hooks.js.map +1 -1
  53. package/util/defer.d.ts +0 -18
  54. package/util/defer.js +0 -21
  55. package/util/defer.js.map +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,140 @@
1
1
  # @open-pioneer/map
2
2
 
3
+ ## 0.8.0
4
+
5
+ ### Minor Changes
6
+
7
+ - b717121: Update from OL 9 to OL 10.
8
+ - e7978a8: **Breaking:** Remove most events from the map model and the layer interfaces.
9
+ All events that were merely used to synchronized state (e.g. `changed:title` etc.) have been removed.
10
+
11
+ The map model and related objects (layers, layer collections, etc.) are now based on the [Reactivity API](https://github.com/conterra/reactivity/blob/main/packages/reactivity-core/README.md).
12
+ This change greatly simplifies the code that is necessary to access up-to-date values and to react to changes.
13
+
14
+ For example, from inside a React component, you can now write:
15
+
16
+ ```jsx
17
+ import { useReactiveSnapshot } from "@open-pioneer/reactivity";
18
+
19
+ function YourComponent() {
20
+ // Always up to date, even if the layer's title changes.
21
+ // No more need to listen to events.
22
+ const title = useReactiveSnapshot(() => layer.title, [layer]);
23
+ return <div>{title}</div>;
24
+ }
25
+ ```
26
+
27
+ And inside a normal JavaScript function, you can watch for changes like this:
28
+
29
+ ```js
30
+ import { watch } from "@conterra/reactivity-core";
31
+
32
+ const watchHandle = watch(
33
+ () => [layer.title],
34
+ ([newTitle]) => {
35
+ console.log("The title changed to", newTitle);
36
+ }
37
+ );
38
+
39
+ // Later, cleanup:
40
+ watchHandle.destroy();
41
+ ```
42
+
43
+ For more details, check the [Reactivity API documentation](https://github.com/conterra/reactivity/blob/main/packages/reactivity-core/README.md).
44
+
45
+ - 7ae9f90: Add new `children` property to all layers.
46
+ This property makes it possible to handle any layer children in a generic fashion, regardless of the layer's actual type.
47
+
48
+ `layer.children` is either an alias of `layer.sublayers` (if the layer has sublayers), `layer.layers` (if it's a `GroupLayer`) or undefined, if the layer does not have any children.
49
+
50
+ - d8337a6: The following hooks are deprecated and will be removed in a future release:
51
+
52
+ - `useView`
53
+ - `useProjection`
54
+ - `useResolution`
55
+ - `useCenter`
56
+ - `useScale`
57
+
58
+ They can all be replaced by using the new reactive properties on the `MapModel`, for example:
59
+
60
+ ```javascript
61
+ // old:
62
+ const center = useCenter(olMap);
63
+
64
+ // new:
65
+ const center = useReactiveSnapshot(() => mapModel.center, [mapModel]);
66
+ ```
67
+
68
+ - 2fa8020: Update trails core package dependencies.
69
+
70
+ - Also updates Chakra UI to the latest 2.x version and Chakra React Select to version 5.
71
+ - Removes any obsolete references to `@chakra-ui/system`.
72
+ This dependency seems to be no longer required and may lead to duplicate packages in your dependency tree.
73
+
74
+ - 7ae9f90: Add new layer type `GroupLayer` to to the Map API.
75
+
76
+ A `GroupLayer` contains a list of `Layer` (e.g. `SimpleLayer` or `WMSLayer`). Because `GroupLayer` is a `Layer` as well nested groups are supported.
77
+ The child layers of a `GroupLayer` can be accessed with the `layers` property - `layers` is `undefined` if it is not a group.
78
+ The parent `GroupLayer` of a child layer can be accessed with the `parent` property - `parent` is `undefined` if this layer is not part of a group (or not a sublayer).
79
+
80
+ ```js
81
+ const olLayer1 = new TileLayer({
82
+ source: new OSM()
83
+ });
84
+ const olLayer2 = new TileLayer({
85
+ source: new BkgTopPlusOpen()
86
+ });
87
+
88
+ // Create group layer with nested sub group
89
+ const group = new GroupLayer({
90
+ id: "group",
91
+ title: "a group layer",
92
+ layers: [
93
+ new SimpleLayer({
94
+ id: "member",
95
+ title: "group member",
96
+ olLayer: olLayer1
97
+ }),
98
+ new GroupLayer({
99
+ id: "subgroup",
100
+ title: "a nested group layer",
101
+ layers: [
102
+ new SimpleLayer({
103
+ id: "submember",
104
+ title: "subgroup member",
105
+ olLayer: olLayer2
106
+ })
107
+ ]
108
+ })
109
+ ]
110
+ });
111
+
112
+ const childLayers: GroupLayerCollection = group.layers; // Access child layers
113
+ ```
114
+
115
+ Layers can only be added to a single group or map.
116
+ Sublayers (e.g. `WMSSublayer`) cannot be added to a group directly.
117
+
118
+ - d8337a6: Provide new reactive properties on the `MapModel` type.
119
+
120
+ - `olView` (-> `olMap.getView()`)
121
+ - `projection` (-> `olMap.getView().getProjection()`)
122
+ - `resolution` (-> `olMap.getView().getResolution()`)
123
+ - `zoomLevel` (-> `olMap.getView().getZoom()`)
124
+ - `center` (-> `olMap.getView().getCenter()`)
125
+ - `scale` (derived from center and resolution)
126
+
127
+ Most of the listed properties are already available on raw OpenLayers objects (see code in parentheses above).
128
+ However, those OpenLayers properties require manual work for synchronization, whereas the new properties are reactive (and can be watched, for example, using `useReactiveSnapshot()`).
129
+
130
+ A new method `setScale()` has also been added to the model.
131
+
132
+ ### Patch Changes
133
+
134
+ - 7a5f1e1: Fix keyboard events from map anchors after update to OpenLayers 10.
135
+ - 49f0207: Update trails core packages to version 2.4.0
136
+ - b2127df: Improve documentation of layers in README
137
+
3
138
  ## 0.7.0
4
139
 
5
140
  ### Minor Changes
package/README.md CHANGED
@@ -7,8 +7,8 @@ APIs provided by this package can be used to configure, embed and access the map
7
7
 
8
8
  To use the map in your app, follow these two steps:
9
9
 
10
- - Add a `MapContainer` component to your app (see [Map container component](#md:map-container-component)).
11
- - Implement a `MapConfigProvider` (see [Map configuration](#md:map-configuration)).
10
+ - Add a `MapContainer` component to your app (see [Map container component](#map-container-component)).
11
+ - Implement a `MapConfigProvider` (see [Map configuration](#map-configuration)).
12
12
 
13
13
  To access or manipulate the content of the map programmatically, see [Using the map model](#using-the-map-model).
14
14
 
@@ -36,7 +36,7 @@ function AppUI() {
36
36
  }
37
37
  ```
38
38
 
39
- > NOTE: There must be a `map.MapConfigProvider` that knows how to construct the map with the given ID (see [Map configuration](#md:map-configuration)).
39
+ > NOTE: There must be a `map.MapConfigProvider` that knows how to construct the map with the given ID (see [Map configuration](#map-configuration)).
40
40
 
41
41
  The component itself uses the map registry service to create the map using the provided `mapId`.
42
42
 
@@ -201,7 +201,7 @@ export class MapConfigProviderImpl implements MapConfigProvider {
201
201
 
202
202
  #### Layer configuration
203
203
 
204
- Configure your custom layer inside the [Map configuration](#md:map-configuration) by using one of the layer classes provided by this package.
204
+ Configure your custom layer inside the [Map configuration](#map-configuration) by using one of the layer classes provided by this package.
205
205
  For example, `SimpleLayer` can be used to configure an arbitrary [`OpenLayers Layer`](https://openlayers.org/en/latest/apidoc/module-ol_layer_Layer-Layer.html) as `olLayer` property.
206
206
 
207
207
  > **Layer Order**
@@ -621,6 +621,47 @@ export class MapConfigProviderImpl implements MapConfigProvider {
621
621
  }
622
622
  ```
623
623
 
624
+ ##### GroupLayer
625
+
626
+ A `GroupLayer` contains a list of layers (e.g. `SimpleLayer`, `WMSLayer` or nested `GroupLayer`).
627
+ The visibility of all layers within the group is controlled via the parent group layer(s).
628
+ The hierarchy of the layers, which results from the (nested) groups, is rendered accordingly in the table of contents.
629
+
630
+ Example: Create (nested) group layers
631
+
632
+ ```ts
633
+ // Create group layer with a nested sub group
634
+ const group = new GroupLayer({
635
+ id: "group",
636
+ title: "a group layer",
637
+ layers: [
638
+ new SimpleLayer({
639
+ id: "member",
640
+ title: "group member",
641
+ olLayer: olLayer1
642
+ }),
643
+ new GroupLayer({
644
+ id: "subgroup",
645
+ title: "a nested group layer",
646
+ layers: [
647
+ new SimpleLayer({
648
+ id: "submember",
649
+ title: "subgroup member",
650
+ olLayer: olLayer2
651
+ })
652
+ ]
653
+ })
654
+ ]
655
+ });
656
+
657
+ const childLayers = group.layers; // Access child layers
658
+ ```
659
+
660
+ > Limitations:
661
+ >
662
+ > - Do not add or remove layers directly to or from the underlying OpenLayers layer group (`group.olLayer`)! Changes are not synchronized with the `GroupLayer` instance.
663
+ > - Currently, it is not possible to manipulate (add or remove) the child layers of a `GroupLayer` during runtime.
664
+
624
665
  #### Register additional projections
625
666
 
626
667
  The map supports only the following projections by default: `EPSG:4326`, `EPSG:3857`, `EPSG:25832` and `EPSG:25833`.
@@ -693,17 +734,80 @@ In those cases, the properties or methods provided by this package should always
693
734
 
694
735
  #### Layer classes
695
736
 
696
- This package currently only provides two layer implementations:
737
+ This package currently provides five layer implementations: `SimpleLayer`, `WMSLayer`, `WMTSLayer`, `GroupLayer` and `WMSSublayer`.
738
+
739
+ The following diagram shows the inheritance structure of the corresponding layer types. The diagram is only intended to show the hierarchy of the layer types; for details on the properties and methods of the layer types, refer to the respective API documentation.
740
+
741
+ ```mermaid
742
+ ---
743
+ config:
744
+ class:
745
+ hideEmptyMembersBox: true
746
+ ---
747
+ classDiagram
748
+ class AnyLayerBaseType {
749
+ type: string
750
+ }
751
+ <<abstract>> AnyLayerBaseType
752
+
753
+ class LayerBaseType {
754
+ type: string
755
+ }
756
+ <<abstract>> LayerBaseType
757
+
758
+ class SimpleLayer {
759
+ type: "simple"
760
+ constructor(config: SimpleLayerConfig)
761
+ }
762
+
763
+ class WMSLayer {
764
+ type: "wms"
765
+ constructor(config: WMSLayerConfig)
766
+ }
767
+
768
+ class WMTSLayer {
769
+ type: "wmts"
770
+ constructor(config: WMTSLayerConfig)
771
+ }
772
+
773
+ class GroupLayer {
774
+ type: "group"
775
+ constructor(config: GroupLayerConfig)
776
+ }
697
777
 
698
- - `SimpleLayer`.
699
- Instances of this class can be used to integrate arbitrary OpenLayers `Layer` instances into the map by configuring the `olLayer` constructor option.
700
- Note that one can only achieve basic integration through this method: more advanced features such as automatic legends or sublayers will not be available.
778
+ class Layer
779
+ <<union>> Layer
701
780
 
702
- - `WMSLayer`.
703
- Represents a WMS service embedded into the map.
704
- Must be configured with the service's `url` and a set of sublayers.
781
+ class Sublayer
782
+ <<union>> Sublayer
705
783
 
706
- We expect to implement more classes in the future.
784
+ class SublayerBaseType {
785
+ type: string
786
+ }
787
+ <<abstract>> SublayerBaseType
788
+
789
+ class WMSSublayer {
790
+ type: "wms-sublayer"
791
+ constructor(config: WMSSublayerConfig)
792
+ }
793
+
794
+ AnyLayerBaseType <|-- LayerBaseType
795
+ AnyLayerBaseType <|-- SublayerBaseType
796
+
797
+ LayerBaseType <|-- SimpleLayer
798
+ LayerBaseType <|-- WMSLayer
799
+ LayerBaseType <|-- WMTSLayer
800
+ LayerBaseType <|-- GroupLayer
801
+
802
+ SublayerBaseType <|-- WMSSublayer
803
+
804
+ SimpleLayer .. Layer
805
+ WMSLayer .. Layer
806
+ WMTSLayer .. Layer
807
+ GroupLayer .. Layer
808
+
809
+ WMSSublayer .. Sublayer
810
+ ```
707
811
 
708
812
  #### Using the map model and layers in services
709
813
 
package/api/MapModel.d.ts CHANGED
@@ -1,17 +1,17 @@
1
1
  import type { EventSource, Resource } from "@open-pioneer/core";
2
2
  import type OlMap from "ol/Map";
3
+ import type OlView from "ol/View";
3
4
  import type OlBaseLayer from "ol/layer/Base";
4
5
  import type { ExtentConfig } from "./MapConfig";
5
6
  import type { AnyLayer, Layer } from "./layers";
6
7
  import type { LayerRetrievalOptions } from "./shared";
7
8
  import type { Geometry } from "ol/geom";
8
- import { BaseFeature } from "./BaseFeature";
9
- import { StyleLike } from "ol/style/Style";
9
+ import type { BaseFeature } from "./BaseFeature";
10
+ import type { StyleLike } from "ol/style/Style";
11
+ import type { Projection } from "ol/proj";
12
+ import type { Coordinate } from "ol/coordinate";
10
13
  /** Events emitted by the {@link MapModel}. */
11
14
  export interface MapModelEvents {
12
- "changed": void;
13
- "changed:container": void;
14
- "changed:initialExtent": void;
15
15
  "destroy": void;
16
16
  }
17
17
  /** Styleoptions supported when creating a new {@link Highlight}. */
@@ -70,7 +70,7 @@ export interface Highlight extends Resource {
70
70
  readonly isActive: boolean;
71
71
  }
72
72
  /**
73
- * Represents a Object
73
+ * Represents an object in the map.
74
74
  */
75
75
  export type DisplayTarget = BaseFeature | Geometry;
76
76
  /**
@@ -83,11 +83,10 @@ export interface MapModel extends EventSource<MapModelEvents> {
83
83
  readonly id: string;
84
84
  /**
85
85
  * The container in which the map is currently being rendered.
86
+ * This is the same as the target element of the underlying OpenLayers map.
86
87
  *
87
88
  * May be undefined if the map is not being rendered at the moment.
88
89
  * May change at runtime.
89
- *
90
- * The `changed:container` event is emitted when this value changes.
91
90
  */
92
91
  readonly container: HTMLElement | undefined;
93
92
  /**
@@ -95,8 +94,6 @@ export interface MapModel extends EventSource<MapModelEvents> {
95
94
  *
96
95
  * May be undefined before the map is shown.
97
96
  * This is guaranteed to be initialized if the promise returned by {@link whenDisplayed} has resolved.
98
- *
99
- * The `changed:initialExtent` event is emitted when this value changes.
100
97
  */
101
98
  readonly initialExtent: ExtentConfig | undefined;
102
99
  /**
@@ -110,6 +107,46 @@ export interface MapModel extends EventSource<MapModelEvents> {
110
107
  * The raw OpenLayers map.
111
108
  */
112
109
  readonly olMap: OlMap;
110
+ /**
111
+ * Returns the current view of the OpenLayers map.
112
+ */
113
+ readonly olView: OlView;
114
+ /**
115
+ * Returns the current zoom level of the map.
116
+ * Same as `olView.getZoom()`, but reactive.
117
+ */
118
+ readonly zoomLevel: number | undefined;
119
+ /**
120
+ * Returns the current resolution of the map.
121
+ * Same as `olView.getResolution()`, but reactive.
122
+ */
123
+ readonly resolution: number | undefined;
124
+ /**
125
+ * Returns the current center of the map.
126
+ * Same as `olView.getCenter()`, but reactive.
127
+ */
128
+ readonly center: Coordinate | undefined;
129
+ /**
130
+ * Returns the current projection of the map (reactive).
131
+ */
132
+ readonly projection: Projection;
133
+ /**
134
+ * Returns the current scale of the map.
135
+ *
136
+ * Technically, this is the _denominator_ of the current scale.
137
+ * In order to display it, use a format like `1:${scale}`.
138
+ */
139
+ readonly scale: number | undefined;
140
+ /**
141
+ * Changes the current scale of the map to the given value.
142
+ *
143
+ * Internally, this computes a new zoom level / resolution based on the scale
144
+ * and the current center.
145
+ * The new resolution is then applied to the current `olView`.
146
+ *
147
+ * See also {@link scale}.
148
+ */
149
+ setScale(newScale: number): void;
113
150
  /**
114
151
  * Returns a promise that resolves when the map has mounted in the DOM.
115
152
  */
@@ -137,14 +174,10 @@ export interface MapModel extends EventSource<MapModelEvents> {
137
174
  */
138
175
  removeHighlights(): void;
139
176
  }
140
- /** Events emitted by the {@link LayerCollection}. */
141
- export interface LayerCollectionEvents {
142
- changed: void;
143
- }
144
177
  /**
145
178
  * Contains the layers known to a {@link MapModel}.
146
179
  */
147
- export interface LayerCollection extends EventSource<LayerCollectionEvents> {
180
+ export interface LayerCollection {
148
181
  /**
149
182
  * Returns all configured base layers.
150
183
  */
@@ -0,0 +1,50 @@
1
+ import type { Group } from "ol/layer";
2
+ import type { LayerRetrievalOptions } from "../shared";
3
+ import type { ChildrenCollection, Layer, LayerBaseType, LayerConfig } from "./base";
4
+ /**
5
+ * Configuration options to construct a {@link GroupLayer}.
6
+ */
7
+ export interface GroupLayerConfig extends LayerConfig {
8
+ /**
9
+ * List of layers that belong to the new group layer.
10
+ *
11
+ * The group layer takes ownership of the given layers: they will be destroyed when the parent is destroyed.
12
+ * A layer must have a unique parent: it can only be added to the map or a single group layer.
13
+ */
14
+ layers: Layer[];
15
+ }
16
+ /**
17
+ * Represents a group of layers.
18
+ *
19
+ * A group layer contains a collection of {@link Layer} children.
20
+ * Groups can be nested to form a hierarchy.
21
+ */
22
+ export interface GroupLayer extends LayerBaseType {
23
+ readonly type: "group";
24
+ /**
25
+ * Layers contained in this group.
26
+ */
27
+ readonly layers: GroupLayerCollection;
28
+ /**
29
+ * Raw OpenLayers group instance.
30
+ *
31
+ * **Warning:** Do not manipulate the collection of layers in this group directly, changes are not synchronized!
32
+ */
33
+ readonly olLayer: Group;
34
+ readonly sublayers: undefined;
35
+ }
36
+ /**
37
+ * Contains {@link Layer} instances that belong to a {@link GroupLayer}
38
+ */
39
+ export interface GroupLayerCollection extends ChildrenCollection<Layer> {
40
+ /**
41
+ * Returns all layers in this collection
42
+ */
43
+ getLayers(options?: LayerRetrievalOptions): Layer[];
44
+ }
45
+ export interface GroupLayerConstructor {
46
+ prototype: GroupLayer;
47
+ /** Creates a new {@link GroupLayer}. */
48
+ new (config: GroupLayerConfig): GroupLayer;
49
+ }
50
+ export declare const GroupLayer: GroupLayerConstructor;
@@ -0,0 +1,6 @@
1
+ import { GroupLayerImpl } from '../../model/layers/GroupLayerImpl.js';
2
+
3
+ const GroupLayer = GroupLayerImpl;
4
+
5
+ export { GroupLayer };
6
+ //# sourceMappingURL=GroupLayer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GroupLayer.js","sources":["GroupLayer.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport type { Group } from \"ol/layer\";\nimport { GroupLayerImpl } from \"../../model/layers/GroupLayerImpl\";\nimport type { LayerRetrievalOptions } from \"../shared\";\nimport type { ChildrenCollection, Layer, LayerBaseType, LayerConfig } from \"./base\";\n\n/**\n * Configuration options to construct a {@link GroupLayer}.\n */\nexport interface GroupLayerConfig extends LayerConfig {\n /**\n * List of layers that belong to the new group layer.\n *\n * The group layer takes ownership of the given layers: they will be destroyed when the parent is destroyed.\n * A layer must have a unique parent: it can only be added to the map or a single group layer.\n */\n layers: Layer[];\n}\n\n/**\n * Represents a group of layers.\n *\n * A group layer contains a collection of {@link Layer} children.\n * Groups can be nested to form a hierarchy.\n */\nexport interface GroupLayer extends LayerBaseType {\n readonly type: \"group\";\n\n /**\n * Layers contained in this group.\n */\n readonly layers: GroupLayerCollection;\n\n /**\n * Raw OpenLayers group instance.\n *\n * **Warning:** Do not manipulate the collection of layers in this group directly, changes are not synchronized!\n */\n readonly olLayer: Group;\n\n readonly sublayers: undefined;\n}\n\n/**\n * Contains {@link Layer} instances that belong to a {@link GroupLayer}\n */\nexport interface GroupLayerCollection extends ChildrenCollection<Layer> {\n /**\n * Returns all layers in this collection\n */\n getLayers(options?: LayerRetrievalOptions): Layer[];\n}\n\nexport interface GroupLayerConstructor {\n prototype: GroupLayer;\n\n /** Creates a new {@link GroupLayer}. */\n new (config: GroupLayerConfig): GroupLayer;\n}\n\nexport const GroupLayer: GroupLayerConstructor = GroupLayerImpl;\n"],"names":[],"mappings":";;AA6DO,MAAM,UAAoC,GAAA;;;;"}
@@ -22,5 +22,6 @@ export interface SimpleLayerConstructor {
22
22
  */
23
23
  export interface SimpleLayer extends LayerBaseType {
24
24
  readonly type: "simple";
25
+ readonly layers: undefined;
25
26
  }
26
27
  export declare const SimpleLayer: SimpleLayerConstructor;
@@ -1 +1 @@
1
- {"version":3,"file":"SimpleLayer.js","sources":["SimpleLayer.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport type OlBaseLayer from \"ol/layer/Base\";\nimport { LayerConfig, LayerBaseType } from \"./base\";\nimport { SimpleLayerImpl } from \"../../model/layers/SimpleLayerImpl\";\n\n/**\n * Options to construct a simple layer.\n *\n * Simple layers are wrappers around a custom OpenLayers layer.\n */\nexport interface SimpleLayerConfig extends LayerConfig {\n /**\n * The raw OpenLayers instance.\n */\n olLayer: OlBaseLayer;\n}\n\n/** Constructor for {@link SimpleLayer}. */\nexport interface SimpleLayerConstructor {\n prototype: SimpleLayer;\n\n /** Creates a new {@link SimpleLayer}. */\n new (config: SimpleLayerConfig): SimpleLayer;\n}\n\n/**\n * A simple layer type wrapping an OpenLayers layer.\n */\nexport interface SimpleLayer extends LayerBaseType {\n readonly type: \"simple\";\n}\n\nexport const SimpleLayer: SimpleLayerConstructor = SimpleLayerImpl;\n"],"names":[],"mappings":";;AAiCO,MAAM,WAAsC,GAAA;;;;"}
1
+ {"version":3,"file":"SimpleLayer.js","sources":["SimpleLayer.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport type OlBaseLayer from \"ol/layer/Base\";\nimport { LayerConfig, LayerBaseType } from \"./base\";\nimport { SimpleLayerImpl } from \"../../model/layers/SimpleLayerImpl\";\n\n/**\n * Options to construct a simple layer.\n *\n * Simple layers are wrappers around a custom OpenLayers layer.\n */\nexport interface SimpleLayerConfig extends LayerConfig {\n /**\n * The raw OpenLayers instance.\n */\n olLayer: OlBaseLayer;\n}\n\n/** Constructor for {@link SimpleLayer}. */\nexport interface SimpleLayerConstructor {\n prototype: SimpleLayer;\n\n /** Creates a new {@link SimpleLayer}. */\n new (config: SimpleLayerConfig): SimpleLayer;\n}\n\n/**\n * A simple layer type wrapping an OpenLayers layer.\n */\nexport interface SimpleLayer extends LayerBaseType {\n readonly type: \"simple\";\n\n readonly layers: undefined;\n}\n\nexport const SimpleLayer: SimpleLayerConstructor = SimpleLayerImpl;\n"],"names":[],"mappings":";;AAmCO,MAAM,WAAsC,GAAA;;;;"}
@@ -32,6 +32,7 @@ export interface WMSSublayerConfig extends LayerBaseConfig {
32
32
  export interface WMSLayer extends LayerBaseType {
33
33
  readonly type: "wms";
34
34
  readonly sublayers: SublayersCollection<WMSSublayer>;
35
+ readonly layers: undefined;
35
36
  /** The URL of the WMS service that was used during layer construction. */
36
37
  readonly url: string;
37
38
  }
@@ -1 +1 @@
1
- {"version":3,"file":"WMSLayer.js","sources":["WMSLayer.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 { WMSLayerImpl } from \"../../model/layers/WMSLayerImpl\";\nimport type {\n LayerBaseConfig,\n SublayersCollection,\n LayerConfig,\n LayerBaseType,\n SublayerBaseType\n} from \"./base\";\n\n/**\n * Configuration options to construct a WMS layer.\n */\nexport interface WMSLayerConfig extends LayerConfig {\n /** URL of the WMS service. */\n url: string;\n\n /** Configures the layer's sublayers. */\n sublayers?: WMSSublayerConfig[];\n\n /**\n * Additional source options for the layer's WMS source.\n *\n * NOTE: These options are intended for advanced configuration:\n * the WMS Layer manages some of the OpenLayers source options itself.\n */\n sourceOptions?: Partial<WMSSourceOptions>;\n}\n\n/**\n * Configuration options to construct the sublayers of a WMS layer.\n */\nexport interface WMSSublayerConfig extends LayerBaseConfig {\n /**\n * The name of the WMS sublayer in the service's capabilities.\n * Not mandatory, e.g. for WMS group layer. See [WMS spec](https://www.ogc.org/standard/wms/).\n */\n name?: string;\n\n /** Configuration for nested sublayers. */\n sublayers?: WMSSublayerConfig[];\n}\n\n/** Represents a WMS layer. */\nexport interface WMSLayer extends LayerBaseType {\n readonly type: \"wms\";\n\n readonly sublayers: SublayersCollection<WMSSublayer>;\n\n /** The URL of the WMS service that was used during layer construction. */\n readonly url: string;\n}\n\n/** Represents a WMS sublayer */\nexport interface WMSSublayer extends SublayerBaseType {\n readonly type: \"wms-sublayer\";\n /**\n * The name of the WMS sublayer in the service's capabilities.\n *\n * Is optional as a WMS group layer in a WMS service does not need to have a name.\n */\n readonly name: string | undefined;\n}\n\n/**\n * Constructor for {@link WMSLayer}.\n */\nexport interface WMSLayerConstructor {\n prototype: WMSLayer;\n\n /** Creates a new {@link WMSLayer}. */\n new (config: WMSLayerConfig): WMSLayer;\n}\n\nexport const WMSLayer: WMSLayerConstructor = WMSLayerImpl;\n"],"names":[],"mappings":";;AA4EO,MAAM,QAAgC,GAAA;;;;"}
1
+ {"version":3,"file":"WMSLayer.js","sources":["WMSLayer.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 { WMSLayerImpl } from \"../../model/layers/WMSLayerImpl\";\nimport type {\n LayerBaseConfig,\n SublayersCollection,\n LayerConfig,\n LayerBaseType,\n SublayerBaseType\n} from \"./base\";\n\n/**\n * Configuration options to construct a WMS layer.\n */\nexport interface WMSLayerConfig extends LayerConfig {\n /** URL of the WMS service. */\n url: string;\n\n /** Configures the layer's sublayers. */\n sublayers?: WMSSublayerConfig[];\n\n /**\n * Additional source options for the layer's WMS source.\n *\n * NOTE: These options are intended for advanced configuration:\n * the WMS Layer manages some of the OpenLayers source options itself.\n */\n sourceOptions?: Partial<WMSSourceOptions>;\n}\n\n/**\n * Configuration options to construct the sublayers of a WMS layer.\n */\nexport interface WMSSublayerConfig extends LayerBaseConfig {\n /**\n * The name of the WMS sublayer in the service's capabilities.\n * Not mandatory, e.g. for WMS group layer. See [WMS spec](https://www.ogc.org/standard/wms/).\n */\n name?: string;\n\n /** Configuration for nested sublayers. */\n sublayers?: WMSSublayerConfig[];\n}\n\n/** Represents a WMS layer. */\nexport interface WMSLayer extends LayerBaseType {\n readonly type: \"wms\";\n\n readonly sublayers: SublayersCollection<WMSSublayer>;\n readonly layers: undefined;\n\n /** The URL of the WMS service that was used during layer construction. */\n readonly url: string;\n}\n\n/** Represents a WMS sublayer */\nexport interface WMSSublayer extends SublayerBaseType {\n readonly type: \"wms-sublayer\";\n /**\n * The name of the WMS sublayer in the service's capabilities.\n *\n * Is optional as a WMS group layer in a WMS service does not need to have a name.\n */\n readonly name: string | undefined;\n}\n\n/**\n * Constructor for {@link WMSLayer}.\n */\nexport interface WMSLayerConstructor {\n prototype: WMSLayer;\n\n /** Creates a new {@link WMSLayer}. */\n new (config: WMSLayerConfig): WMSLayer;\n}\n\nexport const WMSLayer: WMSLayerConstructor = WMSLayerImpl;\n"],"names":[],"mappings":";;AA6EO,MAAM,QAAgC,GAAA;;;;"}
@@ -23,6 +23,7 @@ export interface WMTSLayer extends LayerBaseType {
23
23
  readonly name: string;
24
24
  /** The name of the tile matrix set in the service's capabilities. */
25
25
  readonly matrixSet: string;
26
+ readonly layers: undefined;
26
27
  }
27
28
  export interface WMTSLayerConstructor {
28
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 { LayerBaseType, 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 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}\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":";;AA0CO,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;;;;"}
@@ -4,16 +4,10 @@ import type { MapModel } from "../MapModel";
4
4
  import type { LayerRetrievalOptions } from "../shared";
5
5
  import type { SimpleLayer } from "./SimpleLayer";
6
6
  import type { WMSLayer, WMSSublayer } from "./WMSLayer";
7
- import { WMTSLayer } from "./WMTSLayer";
7
+ import type { WMTSLayer } from "./WMTSLayer";
8
+ import type { GroupLayer, GroupLayerCollection } from "./GroupLayer";
8
9
  /** Events emitted by the {@link Layer} and other layer types. */
9
10
  export interface LayerBaseEvents {
10
- "changed": void;
11
- "changed:title": void;
12
- "changed:legend": void;
13
- "changed:description": void;
14
- "changed:visible": void;
15
- "changed:attributes": void;
16
- "changed:loadState": void;
17
11
  "destroy": void;
18
12
  }
19
13
  /** The load state of a layer. */
@@ -62,6 +56,12 @@ export interface AnyLayerBaseType<AdditionalEvents = {}> extends EventSource<Lay
62
56
  readonly type: AnyLayerTypes;
63
57
  /** The map this layer belongs to. */
64
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;
65
65
  /**
66
66
  * The unique id of this layer within its map model.
67
67
  *
@@ -85,9 +85,27 @@ export interface AnyLayerBaseType<AdditionalEvents = {}> extends EventSource<Lay
85
85
  */
86
86
  readonly legend: string | undefined;
87
87
  /**
88
- * 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.
89
105
  *
90
106
  * Layers that can never have any sublayers may not have a `sublayers` collection.
107
+ *
108
+ * The properties `layers` and `sublayers` are mutually exclusive.
91
109
  */
92
110
  readonly sublayers: SublayersCollection | undefined;
93
111
  /**
@@ -182,15 +200,18 @@ export interface SublayerBaseType extends AnyLayerBaseType {
182
200
  readonly parentLayer: Layer;
183
201
  }
184
202
  /**
185
- * Events emitted by the {@link SublayersCollection}.
203
+ * Contains the children of a layer.
186
204
  */
187
- export interface SublayersCollectionEvents {
188
- changed: void;
205
+ export interface ChildrenCollection<LayerType> {
206
+ /**
207
+ * Returns the items in this collection.
208
+ */
209
+ getItems(options?: LayerRetrievalOptions): LayerType[];
189
210
  }
190
211
  /**
191
212
  * Contains the sublayers that belong to a {@link Layer} or {@link Sublayer}.
192
213
  */
193
- export interface SublayersCollection<SublayerType = Sublayer> extends EventSource<SublayersCollectionEvents> {
214
+ export interface SublayersCollection<SublayerType = Sublayer> extends ChildrenCollection<SublayerType> {
194
215
  /**
195
216
  * Returns the child sublayers in this collection.
196
217
  */
@@ -199,7 +220,7 @@ export interface SublayersCollection<SublayerType = Sublayer> extends EventSourc
199
220
  /**
200
221
  * Union type for all layers (extending {@link LayerBaseType})
201
222
  */
202
- export type Layer = SimpleLayer | WMSLayer | WMTSLayer;
223
+ export type Layer = SimpleLayer | WMSLayer | WMTSLayer | GroupLayer;
203
224
  export type LayerTypes = Layer["type"];
204
225
  /**
205
226
  * Union type for all sublayers (extending {@link SublayerBaseType}