@open-pioneer/map 0.11.0 → 0.12.0-dev.20250905090001
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +101 -5
- package/MapRegistryImpl.js.map +1 -1
- package/README.md +32 -20
- package/api/MapModel.d.ts +5 -0
- package/api/index.d.ts +1 -1
- package/api/layers/GroupLayer.js.map +1 -1
- package/api/layers/SimpleLayer.js.map +1 -1
- package/api/layers/WMSLayer.js.map +1 -1
- package/api/layers/WMTSLayer.js.map +1 -1
- package/api/layers/base.d.ts +17 -0
- package/api/layers/base.js.map +1 -1
- package/api/shared.d.ts +6 -4
- package/index.js +1 -1
- package/model/AbstractLayer.js.map +1 -1
- package/model/AbstractLayerBase.d.ts +3 -0
- package/model/AbstractLayerBase.js +8 -0
- package/model/AbstractLayerBase.js.map +1 -1
- package/model/Highlights.js +9 -1
- package/model/Highlights.js.map +1 -1
- package/model/LayerCollectionImpl.js +52 -24
- package/model/LayerCollectionImpl.js.map +1 -1
- package/model/MapModelImpl.js.map +1 -1
- package/model/SublayersCollectionImpl.js.map +1 -1
- package/model/createMapModel.js.map +1 -1
- package/model/getRecursiveLayers.js.map +1 -1
- package/model/layers/GroupLayerImpl.js.map +1 -1
- package/model/layers/SimpleLayerImpl.js.map +1 -1
- package/model/layers/WMSLayerImpl.js.map +1 -1
- package/model/layers/WMTSLayerImpl.js.map +1 -1
- package/package.json +6 -7
- package/projections.d.ts +3 -1
- package/projections.js.map +1 -1
- package/ui/DefaultMapProvider.d.ts +3 -2
- package/ui/DefaultMapProvider.js +7 -13
- package/ui/DefaultMapProvider.js.map +1 -1
- package/ui/MapAnchor.js.map +1 -1
- package/ui/MapContainer.d.ts +2 -0
- package/ui/MapContainer.js +4 -16
- package/ui/MapContainer.js.map +1 -1
- package/ui/MapContainerContext.js.map +1 -1
- package/ui/computeMapAnchorStyles.js.map +1 -1
- package/ui/useMapModel.d.ts +28 -22
- package/ui/useMapModel.js +31 -29
- package/ui/useMapModel.js.map +1 -1
- package/util/capabilities-utils.js.map +1 -1
- package/util/geometry-utils.js.map +1 -1
- package/util/ol-test-support.js.map +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,12 +1,112 @@
|
|
|
1
1
|
# @open-pioneer/map
|
|
2
2
|
|
|
3
|
+
## 0.12.0-dev.20250905090001
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 2702df4: Introduce `internal` property for all layer types (including sublayers). If `internal` is `true` (default: `false`) the layer is not considered by any UI widget (e.g. legend and Toc). The `internal` state of a layer is not to be confused with the layer's visibility on the map which is determined by the `visible` property.
|
|
8
|
+
|
|
9
|
+
```typescript
|
|
10
|
+
//internal layer is visible on the map but hidden in UI elements like legend and Toc
|
|
11
|
+
const internalLayer = new SimpleLayer({
|
|
12
|
+
id: "layer1",
|
|
13
|
+
title: "layer 1",
|
|
14
|
+
olLayer: myOlLayer,
|
|
15
|
+
visible: true,
|
|
16
|
+
internal: true
|
|
17
|
+
});
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
- 5df900f: Add a new hook `useMapModelValue(props?)`.
|
|
21
|
+
The hook returns either the directly configured `map` (via props) or the default map from a parent `DefaultMapProvider`.
|
|
22
|
+
If neither is present, an error will be thrown.
|
|
23
|
+
|
|
24
|
+
This hook is used in all components that work with the map.
|
|
25
|
+
The typical usage works like this:
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
import { MapModelProps, useMapModelValue } from "@open-pioneer/map";
|
|
29
|
+
|
|
30
|
+
// optional `map` property inherited from `MapModelProps`
|
|
31
|
+
export interface MyComponentProps extends MapModelProps {
|
|
32
|
+
// ... other properties
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function MyComponent(props) {
|
|
36
|
+
const map = useMapModelValue(props); // looks up the map
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
You can also call this hook without any arguments:
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
// Map model from DefaultMapProvider or an error.
|
|
44
|
+
const mapModel = useMapModelValue();
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
This hook should replace _most_ usages `useMapModel`, which can't return the map model directly since it may not have finished construction yet.
|
|
48
|
+
|
|
49
|
+
- aeb9000: Add new `"topmost"` option to add layers that are always displayed on the top (above all other layers).
|
|
50
|
+
|
|
51
|
+
A new layers can be added at `topmost` to ensure that this layer will always be displayed on top of the other layers.
|
|
52
|
+
This can be used, for example, to implement highlights or to draw graphics.
|
|
53
|
+
Layers added at `"topmost"` will always be shown above layers at `"top"`.
|
|
54
|
+
|
|
55
|
+
When using the `"above"` or `"below"` options with a `"topmost"` reference layer, that layer becomes `"topmost"` as well.
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
import { MapModel, SimpleLayer } from "@open-pioneer/map";
|
|
59
|
+
|
|
60
|
+
const highlightLayer = new SimpleLayer({
|
|
61
|
+
title: "highlights",
|
|
62
|
+
olLayer: myOlLayer
|
|
63
|
+
});
|
|
64
|
+
//always displayed at the top
|
|
65
|
+
myMapModel.layers.addLayer(highlightLayer, { at: "topmost" });
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
- 5df900f: Deprecate the parameter-less signature of `useMapModel()`:
|
|
69
|
+
|
|
70
|
+
```ts
|
|
71
|
+
// Returns the DefaultMapProvider's map, but wrapped in a result value (loading/resolved/rejected)
|
|
72
|
+
const result = useMapModel();
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Use `useMapModelValue()` instead:
|
|
76
|
+
|
|
77
|
+
```ts
|
|
78
|
+
// Returns the map model directly.
|
|
79
|
+
const mapModel = useMapModelValue();
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
All other signatures of `useMapModel()` are still fully supported.
|
|
83
|
+
|
|
84
|
+
### Patch Changes
|
|
85
|
+
|
|
86
|
+
- 29a10df: Support buffer for zoom geometries.
|
|
87
|
+
|
|
88
|
+
For example:
|
|
89
|
+
|
|
90
|
+
```ts
|
|
91
|
+
const map: MapModel = ...;
|
|
92
|
+
const highlight = map.highlightAndZoom(someGeometries, {
|
|
93
|
+
// Grows extent by 10%
|
|
94
|
+
buffer: 0.1
|
|
95
|
+
});
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
- 10d2fe7: Update dependencies
|
|
99
|
+
- 12561fe: The default value of the `role` prop on the `MapContainer` was changed to `application` to allow map keyboard navigation while using NVDA screen reader.
|
|
100
|
+
- 8986b3b: Remove obsolete dependency @types/proj4
|
|
101
|
+
- f1f69f2: Update to OpenLayers 10.6.1
|
|
102
|
+
- da6a410: Update dependencies
|
|
103
|
+
|
|
3
104
|
## 0.11.0
|
|
4
105
|
|
|
5
106
|
### Minor Changes
|
|
6
107
|
|
|
7
108
|
- 66179bc: Update to core-packages v4.0.0
|
|
8
109
|
- acd5115: **Breaking:** Remove the following hooks, which were deprecated since version 0.8.0:
|
|
9
|
-
|
|
10
110
|
- useView
|
|
11
111
|
- useProjection
|
|
12
112
|
- useResolution
|
|
@@ -259,7 +359,6 @@
|
|
|
259
359
|
`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.
|
|
260
360
|
|
|
261
361
|
- d8337a6: The following hooks are deprecated and will be removed in a future release:
|
|
262
|
-
|
|
263
362
|
- `useView`
|
|
264
363
|
- `useProjection`
|
|
265
364
|
- `useResolution`
|
|
@@ -277,7 +376,6 @@
|
|
|
277
376
|
```
|
|
278
377
|
|
|
279
378
|
- 2fa8020: Update trails core package dependencies.
|
|
280
|
-
|
|
281
379
|
- Also updates Chakra UI to the latest 2.x version and Chakra React Select to version 5.
|
|
282
380
|
- Removes any obsolete references to `@chakra-ui/system`.
|
|
283
381
|
This dependency seems to be no longer required and may lead to duplicate packages in your dependency tree.
|
|
@@ -327,7 +425,6 @@
|
|
|
327
425
|
Sublayers (e.g. `WMSSublayer`) cannot be added to a group directly.
|
|
328
426
|
|
|
329
427
|
- d8337a6: Provide new reactive properties on the `MapModel` type.
|
|
330
|
-
|
|
331
428
|
- `olView` (-> `olMap.getView()`)
|
|
332
429
|
- `projection` (-> `olMap.getView().getProjection()`)
|
|
333
430
|
- `resolution` (-> `olMap.getView().getResolution()`)
|
|
@@ -359,7 +456,6 @@
|
|
|
359
456
|
Two type guards have been implemented that allow to check if a layer instance is a `Layer` or `Sublayer`: `isLayer()`and `isSublayer()` (see example below).
|
|
360
457
|
|
|
361
458
|
The following `type` attribute values have been implemented at the layers:
|
|
362
|
-
|
|
363
459
|
- SimpleLayer: `simple`
|
|
364
460
|
- WMSLayer: `wms`
|
|
365
461
|
- WMSSubLayer: `wms-sublayer`
|
package/MapRegistryImpl.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MapRegistryImpl.js","sources":["MapRegistryImpl.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { createLogger } from \"@open-pioneer/core\";\nimport { HttpService } from \"@open-pioneer/http\";\nimport { PackageIntl, Service, ServiceOptions } from \"@open-pioneer/runtime\";\nimport OlMap from \"ol/Map\";\nimport { MapConfigProvider, MapModel, MapRegistry } from \"./api\";\nimport { createMapModel } from \"./model/createMapModel\";\nimport { MapModelImpl } from \"./model/MapModelImpl\";\n\nconst LOG = createLogger(\"map:MapRegistry\");\n\ninterface References {\n providers: MapConfigProvider[];\n httpService: HttpService;\n}\n\ntype ModelJobResult = { kind: \"model\"; model: MapModelImpl } | { kind: \"error\"; error: Error };\n\nexport class MapRegistryImpl implements Service, MapRegistry {\n #intl: PackageIntl;\n #httpService: HttpService;\n\n #configProviders = new Map<string, MapConfigProvider>();\n #entries = new Map<string, ModelJobResult>();\n #modelCreationJobs = new Map<string, Promise<ModelJobResult>>();\n #modelsByOlMap = new WeakMap<OlMap, MapModel>();\n #destroyed = false;\n\n constructor({ references, intl }: ServiceOptions<References>) {\n this.#intl = intl;\n this.#httpService = references.httpService;\n\n const providers = references.providers;\n for (const provider of providers) {\n this.#configProviders.set(provider.mapId, provider);\n }\n }\n\n destroy(): void {\n if (this.#destroyed) {\n return;\n }\n\n LOG.info(`Destroy map registry and all maps`);\n this.#destroyed = true;\n this.#entries.forEach((model) => {\n model.kind === \"model\" && model.model.destroy();\n });\n this.#entries.clear();\n this.#modelCreationJobs.clear();\n }\n\n async getMapModel(mapId: string): Promise<MapModel | undefined> {\n if (this.#destroyed) {\n throw new Error(\"MapRegistry has already been destroyed.\");\n }\n\n const creationJob = this.#modelCreationJobs.get(mapId);\n if (creationJob) {\n return unbox(await creationJob);\n }\n\n const entry = this.#entries.get(mapId);\n if (entry) {\n return unbox(entry);\n }\n\n const provider = this.#configProviders.get(mapId);\n if (!provider) {\n LOG.debug(`Failed to find a config provider for map id '${mapId}'.`);\n return undefined;\n }\n\n const modelPromise = this.#createModel(mapId, provider).catch((cause) => {\n const error = new Error(`Failed to construct map '${mapId}'`, { cause });\n const entry: ModelJobResult = { kind: \"error\", error };\n this.#modelCreationJobs.delete(mapId);\n this.#entries.set(mapId, entry);\n return entry;\n });\n this.#modelCreationJobs.set(mapId, modelPromise);\n return unbox(await modelPromise);\n }\n\n async expectMapModel(mapId: string): Promise<MapModel> {\n const model = await this.getMapModel(mapId);\n if (!model) {\n throw new Error(`No configuration available for map with id '${mapId}'.`);\n }\n return model;\n }\n\n getMapModelByRawInstance(olMap: OlMap): MapModel | undefined {\n return this.#modelsByOlMap.get(olMap);\n }\n\n async #createModel(mapId: string, provider: MapConfigProvider): Promise<ModelJobResult> {\n LOG.info(`Creating map with id '${mapId}'`);\n const mapConfig = await provider.getMapConfig();\n const mapModel = await createMapModel(mapId, mapConfig, this.#intl, this.#httpService);\n\n if (this.#destroyed) {\n mapModel.destroy();\n throw new Error(`MapRegistry has been destroyed.`);\n }\n\n const entry: ModelJobResult = { kind: \"model\", model: mapModel };\n this.#entries.set(mapId, entry);\n this.#modelCreationJobs.delete(mapId);\n this.#modelsByOlMap.set(mapModel.olMap, mapModel);\n return entry;\n }\n}\n\nfunction unbox(entry: ModelJobResult): MapModelImpl {\n if (entry.kind === \"error\") {\n throw entry.error;\n }\n return entry.model;\n}\n"],"names":["entry"],"mappings":";;;AAUA,MAAM,GAAA,GAAM,aAAa,iBAAiB,CAAA;AASnC,MAAM,
|
|
1
|
+
{"version":3,"file":"MapRegistryImpl.js","sources":["MapRegistryImpl.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { createLogger } from \"@open-pioneer/core\";\nimport { HttpService } from \"@open-pioneer/http\";\nimport { PackageIntl, Service, ServiceOptions } from \"@open-pioneer/runtime\";\nimport OlMap from \"ol/Map\";\nimport { MapConfigProvider, MapModel, MapRegistry } from \"./api\";\nimport { createMapModel } from \"./model/createMapModel\";\nimport { MapModelImpl } from \"./model/MapModelImpl\";\n\nconst LOG = createLogger(\"map:MapRegistry\");\n\ninterface References {\n providers: MapConfigProvider[];\n httpService: HttpService;\n}\n\ntype ModelJobResult = { kind: \"model\"; model: MapModelImpl } | { kind: \"error\"; error: Error };\n\nexport class MapRegistryImpl implements Service, MapRegistry {\n #intl: PackageIntl;\n #httpService: HttpService;\n\n #configProviders = new Map<string, MapConfigProvider>();\n #entries = new Map<string, ModelJobResult>();\n #modelCreationJobs = new Map<string, Promise<ModelJobResult>>();\n #modelsByOlMap = new WeakMap<OlMap, MapModel>();\n #destroyed = false;\n\n constructor({ references, intl }: ServiceOptions<References>) {\n this.#intl = intl;\n this.#httpService = references.httpService;\n\n const providers = references.providers;\n for (const provider of providers) {\n this.#configProviders.set(provider.mapId, provider);\n }\n }\n\n destroy(): void {\n if (this.#destroyed) {\n return;\n }\n\n LOG.info(`Destroy map registry and all maps`);\n this.#destroyed = true;\n this.#entries.forEach((model) => {\n model.kind === \"model\" && model.model.destroy();\n });\n this.#entries.clear();\n this.#modelCreationJobs.clear();\n }\n\n async getMapModel(mapId: string): Promise<MapModel | undefined> {\n if (this.#destroyed) {\n throw new Error(\"MapRegistry has already been destroyed.\");\n }\n\n const creationJob = this.#modelCreationJobs.get(mapId);\n if (creationJob) {\n return unbox(await creationJob);\n }\n\n const entry = this.#entries.get(mapId);\n if (entry) {\n return unbox(entry);\n }\n\n const provider = this.#configProviders.get(mapId);\n if (!provider) {\n LOG.debug(`Failed to find a config provider for map id '${mapId}'.`);\n return undefined;\n }\n\n const modelPromise = this.#createModel(mapId, provider).catch((cause) => {\n const error = new Error(`Failed to construct map '${mapId}'`, { cause });\n const entry: ModelJobResult = { kind: \"error\", error };\n this.#modelCreationJobs.delete(mapId);\n this.#entries.set(mapId, entry);\n return entry;\n });\n this.#modelCreationJobs.set(mapId, modelPromise);\n return unbox(await modelPromise);\n }\n\n async expectMapModel(mapId: string): Promise<MapModel> {\n const model = await this.getMapModel(mapId);\n if (!model) {\n throw new Error(`No configuration available for map with id '${mapId}'.`);\n }\n return model;\n }\n\n getMapModelByRawInstance(olMap: OlMap): MapModel | undefined {\n return this.#modelsByOlMap.get(olMap);\n }\n\n async #createModel(mapId: string, provider: MapConfigProvider): Promise<ModelJobResult> {\n LOG.info(`Creating map with id '${mapId}'`);\n const mapConfig = await provider.getMapConfig();\n const mapModel = await createMapModel(mapId, mapConfig, this.#intl, this.#httpService);\n\n if (this.#destroyed) {\n mapModel.destroy();\n throw new Error(`MapRegistry has been destroyed.`);\n }\n\n const entry: ModelJobResult = { kind: \"model\", model: mapModel };\n this.#entries.set(mapId, entry);\n this.#modelCreationJobs.delete(mapId);\n this.#modelsByOlMap.set(mapModel.olMap, mapModel);\n return entry;\n }\n}\n\nfunction unbox(entry: ModelJobResult): MapModelImpl {\n if (entry.kind === \"error\") {\n throw entry.error;\n }\n return entry.model;\n}\n"],"names":["entry"],"mappings":";;;AAUA,MAAM,GAAA,GAAM,aAAa,iBAAiB,CAAA;AASnC,MAAM,eAAA,CAAgD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,KAAA;AACjB;;;;"}
|
package/README.md
CHANGED
|
@@ -280,9 +280,9 @@ Based on the example above, you can set different properties using the layer API
|
|
|
280
280
|
Example: How to set different properties.
|
|
281
281
|
|
|
282
282
|
```js
|
|
283
|
-
import {
|
|
283
|
+
import { useMapModelValue } from "@open-pioneer/map";
|
|
284
284
|
|
|
285
|
-
const
|
|
285
|
+
const map = useMapModelValue();
|
|
286
286
|
const layer = map.layers.getLayerById("abe0e3f8-0ba2-409c-b6b4-9d8429c732e3");
|
|
287
287
|
|
|
288
288
|
layer.setDescription("new description");
|
|
@@ -726,7 +726,7 @@ The most important API items are as follows:
|
|
|
726
726
|
- The `MapRegistry` service (inject via `"map.MapRegistry"`).
|
|
727
727
|
This service is used to obtain a reference to the `MapModel` via `registry.getMapModel(mapId)`.
|
|
728
728
|
|
|
729
|
-
> NOTE: From inside a React component you can also use the hook `useMapModel(mapId)` (or `
|
|
729
|
+
> NOTE: From inside a React component you can also use the hook `useMapModel(mapId)` (or `useMapModelValue()` if using the DefaultMapProvider).
|
|
730
730
|
|
|
731
731
|
- The `MapModel` represents a map in an application.
|
|
732
732
|
Through the `MapModel` one can obtain the map's base layers, operational layers and so on.
|
|
@@ -869,27 +869,39 @@ export class TestService {
|
|
|
869
869
|
|
|
870
870
|
#### Using the map model in React components
|
|
871
871
|
|
|
872
|
-
To access the map model instance, use the React
|
|
872
|
+
To access the map model instance, use the React hooks `useMapModel` or `useMapModelValue`.
|
|
873
873
|
|
|
874
|
-
|
|
874
|
+
- `useMapModelValue` returns the map model specified by a `DefaultMapProvider` parent.
|
|
875
|
+
This is a convenient API to avoid passing the map model as a prop everywhere:
|
|
875
876
|
|
|
876
|
-
```
|
|
877
|
-
|
|
878
|
-
|
|
877
|
+
```tsx
|
|
878
|
+
function YourComponent() {
|
|
879
|
+
const map = useMapModelValue(); // requires a <DefaultMapProvider /> parent somewhere in the React tree
|
|
880
|
+
}
|
|
881
|
+
```
|
|
879
882
|
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
// the object may may also be in an "error" state.
|
|
883
|
-
const mapState = useMapModel(MAP_ID);
|
|
883
|
+
- `useMapModel` takes a `mapId` and returns a result.
|
|
884
|
+
The result will ultimately resolve to either a map model or an error (if initialization of the map failed).
|
|
884
885
|
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
886
|
+
Example: Center map to given coordinates using the map model.
|
|
887
|
+
|
|
888
|
+
```js
|
|
889
|
+
import { useMapModel } from "@open-pioneer/map";
|
|
890
|
+
import { MAP_ID } from "./MapConfigProviderImpl";
|
|
891
|
+
|
|
892
|
+
export function AppUI() {
|
|
893
|
+
// mapState.map may be undefined initially, if the map is still configuring.
|
|
894
|
+
// the object may may also be in an "error" state.
|
|
895
|
+
const mapState = useMapModel(MAP_ID);
|
|
896
|
+
|
|
897
|
+
const centerBerlin = () => {
|
|
898
|
+
const olMap = mapState.map?.olMap;
|
|
899
|
+
if (olMap) {
|
|
900
|
+
olMap?.getView().fit([1489200, 6894026, 1489200, 6894026], { maxZoom: 13 });
|
|
901
|
+
}
|
|
902
|
+
};
|
|
903
|
+
}
|
|
904
|
+
```
|
|
893
905
|
|
|
894
906
|
## License
|
|
895
907
|
|
package/api/MapModel.d.ts
CHANGED
|
@@ -35,6 +35,11 @@ export interface ZoomOptions {
|
|
|
35
35
|
* The view padding to make all features visible.
|
|
36
36
|
*/
|
|
37
37
|
viewPadding?: MapPadding;
|
|
38
|
+
/**
|
|
39
|
+
* The buffer factor around the extent of the zoomed features. E.g. a value of 0.1 will add 10%
|
|
40
|
+
* of the extent's width and height to the extent.
|
|
41
|
+
*/
|
|
42
|
+
buffer?: number;
|
|
38
43
|
}
|
|
39
44
|
/** Options supported by the map model's {@link MapModel.highlightAndZoom | zoom | highlightAndZoom} method. */
|
|
40
45
|
export interface HighlightZoomOptions extends HighlightOptions, ZoomOptions {
|
package/api/index.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export * from "./shared";
|
|
|
7
7
|
export { getProjection, registerProjections, type ProjectionDefinition } from "../projections";
|
|
8
8
|
export { MapAnchor, type MapAnchorProps, type MapAnchorPosition } from "../ui/MapAnchor";
|
|
9
9
|
export { MapContainer, type MapContainerProps } from "../ui/MapContainer";
|
|
10
|
-
export { useMapModel, type UseMapModelResult, type UseMapModelLoading, type UseMapModelResolved, type UseMapModelRejected, type MapModelProps } from "../ui/useMapModel";
|
|
10
|
+
export { useMapModel, useMapModelValue, type UseMapModelResult, type UseMapModelLoading, type UseMapModelResolved, type UseMapModelRejected, type MapModelProps } from "../ui/useMapModel";
|
|
11
11
|
export { DefaultMapProvider } from "../ui/DefaultMapProvider";
|
|
12
12
|
export { calculateBufferedExtent } from "../util/geometry-utils";
|
|
13
13
|
export { TOPMOST_LAYER_Z } from "../model/LayerCollectionImpl";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GroupLayer.js","sources":["GroupLayer.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 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, RecursiveRetrievalOptions } from \"../shared\";\nimport type { AnyLayer, 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 /**\n * Returns a list of all layers in the collection, including all children (recursively).\n *\n * > Note: This includes base layers by default (see `options.filter`).\n * > Use the `\"base\"` or `\"operational\"` short hand values to filter by base layer or operational layers.\n * >\n * > If the group contains many, deeply nested sub groups, this function could potentially be expensive.\n */\n getRecursiveLayers(options?: RecursiveRetrievalOptions): AnyLayer[];\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":";;AAuEO,MAAM,
|
|
1
|
+
{"version":3,"file":"GroupLayer.js","sources":["GroupLayer.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 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, RecursiveRetrievalOptions } from \"../shared\";\nimport type { AnyLayer, 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 /**\n * Returns a list of all layers in the collection, including all children (recursively).\n *\n * > Note: This includes base layers by default (see `options.filter`).\n * > Use the `\"base\"` or `\"operational\"` short hand values to filter by base layer or operational layers.\n * >\n * > If the group contains many, deeply nested sub groups, this function could potentially be expensive.\n */\n getRecursiveLayers(options?: RecursiveRetrievalOptions): AnyLayer[];\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":";;AAuEO,MAAM,UAAA,GAAoC;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SimpleLayer.js","sources":["SimpleLayer.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 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,
|
|
1
|
+
{"version":3,"file":"SimpleLayer.js","sources":["SimpleLayer.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 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,WAAA,GAAsC;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WMSLayer.js","sources":["WMSLayer.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 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 * Whether to automatically fetch capabilities from the service when needed (default: `true`).\n *\n * Setting this to `false` can be useful as a performance optimization when capabilities are not really required by the application.\n * Note that this will disable some features of the WMS layer: for example, the legend URL will not be available.\n */\n fetchCapabilities?: boolean;\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":";;AAqFO,MAAM,
|
|
1
|
+
{"version":3,"file":"WMSLayer.js","sources":["WMSLayer.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 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 * Whether to automatically fetch capabilities from the service when needed (default: `true`).\n *\n * Setting this to `false` can be useful as a performance optimization when capabilities are not really required by the application.\n * Note that this will disable some features of the WMS layer: for example, the legend URL will not be available.\n */\n fetchCapabilities?: boolean;\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":";;AAqFO,MAAM,QAAA,GAAgC;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WMTSLayer.js","sources":["WMTSLayer.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 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,
|
|
1
|
+
{"version":3,"file":"WMTSLayer.js","sources":["WMTSLayer.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 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,SAAA,GAAkC;;;;"}
|
package/api/layers/base.d.ts
CHANGED
|
@@ -42,6 +42,11 @@ export interface LayerBaseConfig {
|
|
|
42
42
|
* These can be arbitrary values.
|
|
43
43
|
*/
|
|
44
44
|
attributes?: Record<string | symbol, unknown>;
|
|
45
|
+
/**
|
|
46
|
+
* Layers marked as internal are not considered by any UI widget (e.g. Toc or Legend)
|
|
47
|
+
* Defaults to `false`
|
|
48
|
+
*/
|
|
49
|
+
internal?: boolean;
|
|
45
50
|
}
|
|
46
51
|
/**
|
|
47
52
|
* Interface shared by all layer types (operational layers and sublayers).
|
|
@@ -110,6 +115,13 @@ export interface AnyLayerBaseType<AdditionalEvents = {}> extends EventSource<Lay
|
|
|
110
115
|
* The properties `layers` and `sublayers` are mutually exclusive.
|
|
111
116
|
*/
|
|
112
117
|
readonly sublayers: SublayersCollection | undefined;
|
|
118
|
+
/**
|
|
119
|
+
* Property that specifies if the layer is an "internal" layer. Internal layers are not considered by any UI widget (e.g. Toc or Legend).
|
|
120
|
+
* The internal state is independent of the layer's visibility which is determined by {@link visible}
|
|
121
|
+
*
|
|
122
|
+
* NOTE: Some UI widgets might use component specific attributes or props that have precedence over the internal property.
|
|
123
|
+
*/
|
|
124
|
+
readonly internal: boolean;
|
|
113
125
|
/**
|
|
114
126
|
* Additional attributes associated with this layer.
|
|
115
127
|
*/
|
|
@@ -129,6 +141,11 @@ export interface AnyLayerBaseType<AdditionalEvents = {}> extends EventSource<Lay
|
|
|
129
141
|
* Call {@link LayerCollection.activateBaseLayer} instead.
|
|
130
142
|
*/
|
|
131
143
|
setVisible(newVisibility: boolean): void;
|
|
144
|
+
/**
|
|
145
|
+
* Updates the internal property of this layer to the new value.
|
|
146
|
+
* @param newIsInternal
|
|
147
|
+
*/
|
|
148
|
+
setInternal(newIsInternal: boolean): void;
|
|
132
149
|
/**
|
|
133
150
|
* Updates the attributes of this layer.
|
|
134
151
|
* Values in `newAttributes` are merged into the existing ones (i.e. via `Object.assign`).
|
package/api/layers/base.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.js","sources":["base.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 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, RecursiveRetrievalOptions } from \"../shared\";\nimport type { GroupLayer, GroupLayerCollection } from \"./GroupLayer\";\nimport type { SimpleLayer } from \"./SimpleLayer\";\nimport type { WMSLayer, WMSSublayer } from \"./WMSLayer\";\nimport type { WMTSLayer } from \"./WMTSLayer\";\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 * Legend URL from the service capabilities, if available.\n *\n * Note: this property may be expanded upon in the future, e.g. to support more variants than just image URLs.\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 * Returns a list of all layers in the collection, including all children (recursively).\n *\n * > Note: This includes base layers by default (see `options.filter`).\n * > Use the `\"base\"` or `\"operational\"` short hand values to filter by base layer or operational layers.\n * >\n * > If the collection contains many, deeply nested sublayers, this function could potentially be expensive.\n */\n getRecursiveLayers(options?: RecursiveRetrievalOptions): Sublayer[];\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":"AAqSO,SAAS,WAAW,KAAoC,EAAA;AAC3D,EAAA,OAAO,aAAiB,IAAA,KAAA;AAC5B;AAKO,SAAS,QAAQ,KAAiC,EAAA;AACrD,EAAA,OAAO,SAAa,IAAA,KAAA;AACxB;;;;"}
|
|
1
|
+
{"version":3,"file":"base.js","sources":["base.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 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, RecursiveRetrievalOptions } from \"../shared\";\nimport type { GroupLayer, GroupLayerCollection } from \"./GroupLayer\";\nimport type { SimpleLayer } from \"./SimpleLayer\";\nimport type { WMSLayer, WMSSublayer } from \"./WMSLayer\";\nimport type { WMTSLayer } from \"./WMTSLayer\";\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 * Layers marked as internal are not considered by any UI widget (e.g. Toc or Legend)\n * Defaults to `false`\n */\n internal?: boolean;\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 * Legend URL from the service capabilities, if available.\n *\n * Note: this property may be expanded upon in the future, e.g. to support more variants than just image URLs.\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 * Property that specifies if the layer is an \"internal\" layer. Internal layers are not considered by any UI widget (e.g. Toc or Legend).\n * The internal state is independent of the layer's visibility which is determined by {@link visible}\n *\n * NOTE: Some UI widgets might use component specific attributes or props that have precedence over the internal property.\n */\n readonly internal: boolean;\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 internal property of this layer to the new value.\n * @param newIsInternal\n */\n setInternal(newIsInternal: 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 * Returns a list of all layers in the collection, including all children (recursively).\n *\n * > Note: This includes base layers by default (see `options.filter`).\n * > Use the `\"base\"` or `\"operational\"` short hand values to filter by base layer or operational layers.\n * >\n * > If the collection contains many, deeply nested sublayers, this function could potentially be expensive.\n */\n getRecursiveLayers(options?: RecursiveRetrievalOptions): Sublayer[];\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":"AAyTO,SAAS,WAAW,KAAA,EAAoC;AAC3D,EAAA,OAAO,aAAA,IAAiB,KAAA;AAC5B;AAKO,SAAS,QAAQ,KAAA,EAAiC;AACrD,EAAA,OAAO,SAAA,IAAa,KAAA;AACxB;;;;"}
|
package/api/shared.d.ts
CHANGED
|
@@ -25,15 +25,16 @@ export interface AddLayerOptionsBase {
|
|
|
25
25
|
*
|
|
26
26
|
* Default: "top"
|
|
27
27
|
*
|
|
28
|
-
* - "top": Insert the new layer _above_ all other operational layers.
|
|
28
|
+
* - "top": Insert the new layer _above_ all other *normal* operational layers (note: still below `"topmost"` layers).
|
|
29
29
|
* - "bottom": Insert the new layer _below_ all other operational layers.
|
|
30
30
|
* - "above": Insert the new layer _above_ the specified `reference` layer.
|
|
31
31
|
* - "below": Insert the new layer _below_ the specified `reference` layer.
|
|
32
|
+
* - "topmost": Insert a new layer that is always displayed on top of all layers that were added at `top` (e.g. a highlight layer).
|
|
32
33
|
*/
|
|
33
|
-
at: "top" | "bottom" | "above" | "below";
|
|
34
|
+
at: "top" | "bottom" | "above" | "below" | "topmost";
|
|
34
35
|
}
|
|
35
36
|
export interface AddLayerOptionsTopBottom extends AddLayerOptionsBase {
|
|
36
|
-
at: "top" | "bottom";
|
|
37
|
+
at: "top" | "bottom" | "topmost";
|
|
37
38
|
}
|
|
38
39
|
export interface AddLayerOptionsAboveBelow extends AddLayerOptionsBase {
|
|
39
40
|
at: "above" | "below";
|
|
@@ -42,7 +43,8 @@ export interface AddLayerOptionsAboveBelow extends AddLayerOptionsBase {
|
|
|
42
43
|
*
|
|
43
44
|
* Can be specified either as a layer object or an `id`.
|
|
44
45
|
*
|
|
45
|
-
* The reference must be a
|
|
46
|
+
* The reference must be a top level operational layer in the layer collection.
|
|
47
|
+
* Otherwise an error will be thrown.
|
|
46
48
|
*/
|
|
47
49
|
reference: Layer | string;
|
|
48
50
|
}
|
package/index.js
CHANGED
|
@@ -6,7 +6,7 @@ export { GroupLayer } from './api/layers/GroupLayer.js';
|
|
|
6
6
|
export { getProjection, registerProjections } from './projections.js';
|
|
7
7
|
export { MapAnchor } from './ui/MapAnchor.js';
|
|
8
8
|
export { MapContainer } from './ui/MapContainer.js';
|
|
9
|
-
export { useMapModel } from './ui/useMapModel.js';
|
|
9
|
+
export { useMapModel, useMapModelValue } from './ui/useMapModel.js';
|
|
10
10
|
export { DefaultMapProvider } from './ui/DefaultMapProvider.js';
|
|
11
11
|
export { calculateBufferedExtent } from './util/geometry-utils.js';
|
|
12
12
|
export { TOPMOST_LAYER_Z } from './model/LayerCollectionImpl.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AbstractLayer.js","sources":["AbstractLayer.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 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;AAOrC,MAAe,sBACV,iBAEZ,CAAA;AAAA,EACI,QAAA;AAAA,EACA,YAAA;AAAA,EACA,YAAA;AAAA,EAEA,QAAA;AAAA,EACA,UAAA;AAAA,EAEA,mBAAA;AAAA,EACA,mBAAA;AAAA,EAEA,YAAY,MAA2B,EAAA;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C,EAAA;AACpD,EAAM,MAAA,KAAA,GAAQ,UAAU,QAAS,EAAA;AACjC,EAAA,QAAQ,KAAO;AAAA,IACX,KAAK,MAAA;AACD,MAAO,OAAA,QAAA;AAAA,IACX,KAAK,WAAA;AACD,MAAO,OAAA,YAAA;AAAA,IACX,KAAK,SAAA;AACD,MAAO,OAAA,SAAA;AAAA,IACX,KAAK,OAAA;AACD,MAAO,OAAA,QAAA;AAAA,IACX,KAAK,OAAA;AACD,MAAO,OAAA,OAAA;AAAA;AAEnB;;;;"}
|
|
1
|
+
{"version":3,"file":"AbstractLayer.js","sources":["AbstractLayer.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 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;AAOrC,MAAe,sBACV,iBAAA,CAEZ;AAAA,EACI,QAAA;AAAA,EACA,YAAA;AAAA,EACA,YAAA;AAAA,EAEA,QAAA;AAAA,EACA,UAAA;AAAA,EAEA,mBAAA;AAAA,EACA,mBAAA;AAAA,EAEA,YAAY,MAAA,EAA2B;AACnC,IAAA,KAAA,CAAM,MAAM,CAAA;AACZ,IAAA,IAAA,CAAK,WAAW,MAAA,CAAO,OAAA;AACvB,IAAA,IAAA,CAAK,YAAA,GAAe,OAAO,WAAA,IAAe,KAAA;AAC1C,IAAA,IAAA,CAAK,eAAe,MAAA,CAAO,WAAA;AAE3B,IAAA,IAAA,CAAK,WAAW,QAAA,CAAS,MAAM,IAAA,CAAK,QAAA,CAAS,YAAY,CAAA;AACzD,IAAA,IAAA,CAAK,sBAAsB,IAAA,CAAK,QAAA,CAAS,GAAG,gBAAA,EAAkB,IAAA,CAAK,SAAS,OAAO,CAAA;AAEnF,IAAA,IAAA,CAAK,aAAa,QAAA,CAAS,cAAA,CAAe,UAAU,IAAA,CAAK,QAAQ,CAAC,CAAC,CAAA;AACnE,IAAA,IAAA,CAAK,YAAA,CAAa,MAAA,CAAO,OAAA,IAAW,IAAI,CAAA;AAAA,EAC5C;AA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9
9
|
title: string;
|
|
10
10
|
description?: string;
|
|
11
11
|
attributes?: Record<string, unknown>;
|
|
12
|
+
internal?: boolean;
|
|
12
13
|
}
|
|
13
14
|
/**
|
|
14
15
|
* Base class for "normal" layers and sublayers alike to implement common properties
|
|
@@ -17,6 +18,8 @@ export interface AbstractLayerBaseOptions {
|
|
|
17
18
|
export declare abstract class AbstractLayerBase<AdditionalEvents = {}> extends EventEmitter<LayerBaseEvents & AdditionalEvents> implements AnyLayerBaseType {
|
|
18
19
|
#private;
|
|
19
20
|
constructor(config: AbstractLayerBaseOptions);
|
|
21
|
+
get internal(): boolean;
|
|
22
|
+
setInternal(newIsInternal: boolean): void;
|
|
20
23
|
protected get __destroyed(): boolean;
|
|
21
24
|
get map(): MapModelImpl;
|
|
22
25
|
get id(): string;
|
|
@@ -12,6 +12,7 @@ class AbstractLayerBase extends EventEmitter {
|
|
|
12
12
|
#attributesMap = reactiveMap();
|
|
13
13
|
#attributes;
|
|
14
14
|
#destroyed = false;
|
|
15
|
+
#internal;
|
|
15
16
|
constructor(config) {
|
|
16
17
|
super();
|
|
17
18
|
this.#id = config.id ?? v4();
|
|
@@ -20,10 +21,17 @@ class AbstractLayerBase extends EventEmitter {
|
|
|
20
21
|
});
|
|
21
22
|
this.#title = reactive(config.title);
|
|
22
23
|
this.#description = reactive(config.description ?? "");
|
|
24
|
+
this.#internal = reactive(config.internal ?? false);
|
|
23
25
|
if (config.attributes) {
|
|
24
26
|
this.updateAttributes(config.attributes);
|
|
25
27
|
}
|
|
26
28
|
}
|
|
29
|
+
get internal() {
|
|
30
|
+
return this.#internal.value;
|
|
31
|
+
}
|
|
32
|
+
setInternal(newIsInternal) {
|
|
33
|
+
this.#internal.value = newIsInternal;
|
|
34
|
+
}
|
|
27
35
|
get __destroyed() {
|
|
28
36
|
return this.#destroyed;
|
|
29
37
|
}
|