@open-pioneer/map 1.4.0-dev.20260625074633 → 1.4.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.
- package/CHANGELOG.md +46 -22
- package/LayerFactory.d.ts +1 -1
- package/LayerFactory.js.map +1 -1
- package/MapRegistry.js +1 -1
- package/MapRegistry.js.map +1 -1
- package/README.md +8 -14
- package/_virtual/source-info.js +8 -6
- package/_virtual/source-info.js.map +1 -1
- package/layers/AbstractLayer.d.ts +36 -3
- package/layers/AbstractLayer.js +123 -79
- package/layers/AbstractLayer.js.map +1 -1
- package/layers/AbstractLayerBase.d.ts +2 -2
- package/layers/AbstractLayerBase.js.map +1 -1
- package/layers/GroupLayer.d.ts +2 -1
- package/layers/GroupLayer.js +4 -1
- package/layers/GroupLayer.js.map +1 -1
- package/layers/SimpleLayer.d.ts +1 -1
- package/layers/SimpleLayer.js +1 -1
- package/layers/SimpleLayer.js.map +1 -1
- package/layers/WMSLayer.js +59 -11
- package/layers/WMSLayer.js.map +1 -1
- package/layers/WMTSLayer.d.ts +1 -1
- package/layers/WMTSLayer.js +11 -5
- package/layers/WMTSLayer.js.map +1 -1
- package/layers/group/GroupLayerCollection.d.ts +2 -2
- package/layers/group/GroupLayerCollection.js +1 -1
- package/layers/group/GroupLayerCollection.js.map +1 -1
- package/layers/shared/SublayerBaseType.d.ts +9 -0
- package/layers/shared/SublayersCollection.js.map +1 -1
- package/layers/shared/getRecursiveLayers.d.ts +1 -1
- package/layers/shared/getRecursiveLayers.js +12 -5
- package/layers/shared/getRecursiveLayers.js.map +1 -1
- package/layers/shared/internals.d.ts +3 -2
- package/layers/shared/internals.js +2 -1
- package/layers/shared/internals.js.map +1 -1
- package/layers/unions.js.map +1 -1
- package/layers/wms/WMSSublayer.d.ts +14 -1
- package/layers/wms/WMSSublayer.js +29 -2
- package/layers/wms/WMSSublayer.js.map +1 -1
- package/layers/wms/getAttributions.js.map +1 -1
- package/layers/wms/getLegendUrl.js +1 -1
- package/layers/wms/getLegendUrl.js.map +1 -1
- package/layers/wmts/getAttributions.js.map +1 -1
- package/layers/wmts/getLegendUrl.js +1 -1
- package/layers/wmts/getLegendUrl.js.map +1 -1
- package/model/Highlights.js.map +1 -1
- package/model/LayerCollection.js.map +1 -1
- package/model/MapAttributions.js.map +1 -1
- package/model/MapModel.d.ts +5 -5
- package/model/MapModel.js +4 -4
- package/model/MapModel.js.map +1 -1
- package/model/Overlays.d.ts +2 -2
- package/model/Overlays.js +2 -2
- package/model/Overlays.js.map +1 -1
- package/model/createMapModel.js +23 -23
- package/model/createMapModel.js.map +1 -1
- package/model/getGeometries.js.map +1 -1
- package/package.json +10 -10
- package/ui/DefaultMapProvider.js.map +1 -1
- package/ui/MapAnchor.js.map +1 -1
- package/ui/MapContainer.js +2 -2
- package/ui/MapContainer.js.map +1 -1
- package/ui/MapContainerContext.js.map +1 -1
- package/ui/OverlaysRenderer.js.map +1 -1
- package/ui/computeMapAnchorStyles.js.map +1 -1
- package/ui/hooks/useMapModel.d.ts +7 -0
- package/ui/hooks/useMapModel.js +10 -1
- package/ui/hooks/useMapModel.js.map +1 -1
- package/ui/styles.css +0 -2
- package/ui/styles.css.map +1 -1
- package/utils/fetch.js.map +1 -1
- package/utils/geometry-utils.js.map +1 -1
- package/utils/ol-test-support.js.map +1 -1
- package/utils/projections.js.map +1 -1
- package/utils/sanitize.js.map +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,15 +1,32 @@
|
|
|
1
1
|
# @open-pioneer/map
|
|
2
2
|
|
|
3
|
-
## 1.4.0
|
|
3
|
+
## 1.4.0
|
|
4
4
|
|
|
5
5
|
### Minor Changes
|
|
6
6
|
|
|
7
|
-
- c30396d: Update Chakra to 3.36.
|
|
7
|
+
- c30396d: Update Chakra to 3.36.1
|
|
8
|
+
- 690a892: A layer's loadState is now a derived from three different channels:
|
|
9
|
+
|
|
10
|
+
- source — the OpenLayers source state (undefined/loading/ready/error).
|
|
11
|
+
- health — the result of the optional healthCheck (run once on attach).
|
|
12
|
+
- metadata — the result of a layer's own capabilities request (if any).
|
|
13
|
+
|
|
14
|
+
Additionally, a new property `loadError` has been added to the layer class.
|
|
15
|
+
|
|
16
|
+
- e4b47f1: `useMapModel` now prints an error message if the map model could not be created.
|
|
17
|
+
This error was previously returned and was easy to silently ignore.
|
|
18
|
+
|
|
19
|
+
Use the option `quiet: true` to suppress this error message.
|
|
20
|
+
|
|
8
21
|
- c9b3ced: Provide reactive rotation in MapModel
|
|
22
|
+
- 690a892: WMS Layer: add validation that configured sublayers actually exist in the service's capabilities.
|
|
23
|
+
- d862003: Update to trails core-packages 4.7.0
|
|
9
24
|
|
|
10
25
|
### Patch Changes
|
|
11
26
|
|
|
27
|
+
- 078bef5: Use private JavaScript properties (#) instead of TypeScript keyword.
|
|
12
28
|
- b58a50f: Use new `shallowEqual` function to compare attribution arrays.
|
|
29
|
+
- c16a401: Migrated from eslint to oxlint and from prettier to oxfmt.
|
|
13
30
|
|
|
14
31
|
## 1.3.0
|
|
15
32
|
|
|
@@ -27,6 +44,7 @@
|
|
|
27
44
|
- 73453af: Update OpenLayers to 10.9.0
|
|
28
45
|
- fcbd505: Sanitize HTML used for layer attributions.
|
|
29
46
|
- 33ab02f: Move highlight methods to `mapModel.highlights`.
|
|
47
|
+
|
|
30
48
|
- `mapModel.highlight()` -> `mapModel.highlights.add()`
|
|
31
49
|
- `mapModel.highlightAndZoom()` -> `mapModel.highlights.addAndZoom()`
|
|
32
50
|
- `mapModel.removeHighlights()` -> `mapModel.highlights.clear()`
|
|
@@ -347,6 +365,7 @@
|
|
|
347
365
|
- 138d85b: Update core packages to 4.2.0
|
|
348
366
|
- 4f1e7bd: The internal constant `TOPMOST_LAYER_Z` has been removed.
|
|
349
367
|
To configure a layer that is always on top:
|
|
368
|
+
|
|
350
369
|
- Create a layer using the `LayerFactory`
|
|
351
370
|
- Add it to the map model and specify the `at: "topmost"` option
|
|
352
371
|
|
|
@@ -362,6 +381,7 @@
|
|
|
362
381
|
|
|
363
382
|
- 66179bc: Update to core-packages v4.0.0
|
|
364
383
|
- acd5115: **Breaking:** Remove the following hooks, which were deprecated since version 0.8.0:
|
|
384
|
+
|
|
365
385
|
- useView
|
|
366
386
|
- useProjection
|
|
367
387
|
- useResolution
|
|
@@ -614,6 +634,7 @@
|
|
|
614
634
|
`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.
|
|
615
635
|
|
|
616
636
|
- d8337a6: The following hooks are deprecated and will be removed in a future release:
|
|
637
|
+
|
|
617
638
|
- `useView`
|
|
618
639
|
- `useProjection`
|
|
619
640
|
- `useResolution`
|
|
@@ -631,6 +652,7 @@
|
|
|
631
652
|
```
|
|
632
653
|
|
|
633
654
|
- 2fa8020: Update trails core package dependencies.
|
|
655
|
+
|
|
634
656
|
- Also updates Chakra UI to the latest 2.x version and Chakra React Select to version 5.
|
|
635
657
|
- Removes any obsolete references to `@chakra-ui/system`.
|
|
636
658
|
This dependency seems to be no longer required and may lead to duplicate packages in your dependency tree.
|
|
@@ -643,34 +665,34 @@
|
|
|
643
665
|
|
|
644
666
|
```js
|
|
645
667
|
const olLayer1 = new TileLayer({
|
|
646
|
-
|
|
668
|
+
source: new OSM(),
|
|
647
669
|
});
|
|
648
670
|
const olLayer2 = new TileLayer({
|
|
649
|
-
|
|
671
|
+
source: new BkgTopPlusOpen(),
|
|
650
672
|
});
|
|
651
673
|
|
|
652
674
|
// Create group layer with nested sub group
|
|
653
675
|
const group = new GroupLayer({
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
676
|
+
id: "group",
|
|
677
|
+
title: "a group layer",
|
|
678
|
+
layers: [
|
|
679
|
+
new SimpleLayer({
|
|
680
|
+
id: "member",
|
|
681
|
+
title: "group member",
|
|
682
|
+
olLayer: olLayer1,
|
|
683
|
+
}),
|
|
684
|
+
new GroupLayer({
|
|
685
|
+
id: "subgroup",
|
|
686
|
+
title: "a nested group layer",
|
|
687
|
+
layers: [
|
|
657
688
|
new SimpleLayer({
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
689
|
+
id: "submember",
|
|
690
|
+
title: "subgroup member",
|
|
691
|
+
olLayer: olLayer2,
|
|
661
692
|
}),
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
layers: [
|
|
666
|
-
new SimpleLayer({
|
|
667
|
-
id: "submember",
|
|
668
|
-
title: "subgroup member",
|
|
669
|
-
olLayer: olLayer2
|
|
670
|
-
})
|
|
671
|
-
]
|
|
672
|
-
})
|
|
673
|
-
]
|
|
693
|
+
],
|
|
694
|
+
}),
|
|
695
|
+
],
|
|
674
696
|
});
|
|
675
697
|
|
|
676
698
|
const childLayers: GroupLayerCollection = group.layers; // Access child layers
|
|
@@ -680,6 +702,7 @@
|
|
|
680
702
|
Sublayers (e.g. `WMSSublayer`) cannot be added to a group directly.
|
|
681
703
|
|
|
682
704
|
- d8337a6: Provide new reactive properties on the `MapModel` type.
|
|
705
|
+
|
|
683
706
|
- `olView` (-> `olMap.getView()`)
|
|
684
707
|
- `projection` (-> `olMap.getView().getProjection()`)
|
|
685
708
|
- `resolution` (-> `olMap.getView().getResolution()`)
|
|
@@ -711,6 +734,7 @@
|
|
|
711
734
|
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).
|
|
712
735
|
|
|
713
736
|
The following `type` attribute values have been implemented at the layers:
|
|
737
|
+
|
|
714
738
|
- SimpleLayer: `simple`
|
|
715
739
|
- WMSLayer: `wms`
|
|
716
740
|
- WMSSubLayer: `wms-sublayer`
|
package/LayerFactory.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { HttpService } from "@open-pioneer/http";
|
|
2
2
|
import { DECLARE_SERVICE_INTERFACE, ServiceOptions } from "@open-pioneer/runtime";
|
|
3
|
-
import { LayerConfig } from "./layers/shared/LayerConfig";
|
|
4
3
|
import { LayerConstructor } from "./layers/shared/internals";
|
|
4
|
+
import { LayerConfig } from "./layers/shared/LayerConfig";
|
|
5
5
|
import { Layer } from "./layers/unions";
|
|
6
6
|
interface References {
|
|
7
7
|
httpService: HttpService;
|
package/LayerFactory.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LayerFactory.js","sources":["LayerFactory.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { HttpService } from \"@open-pioneer/http\";\nimport { DECLARE_SERVICE_INTERFACE, ServiceOptions } from \"@open-pioneer/runtime\";\nimport { AbstractLayer } from \"./layers/AbstractLayer\";\nimport {
|
|
1
|
+
{"version":3,"file":"LayerFactory.js","sources":["LayerFactory.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n\nimport { HttpService } from \"@open-pioneer/http\";\nimport { DECLARE_SERVICE_INTERFACE, ServiceOptions } from \"@open-pioneer/runtime\";\nimport { AbstractLayer } from \"./layers/AbstractLayer\";\nimport { LayerConstructor } from \"./layers/shared/internals\";\nimport { LayerConfig } from \"./layers/shared/LayerConfig\";\nimport { Layer } from \"./layers/unions\";\nimport { INTERNAL_CONSTRUCTOR_TAG } from \"./utils/InternalConstructorTag\";\n\ninterface References {\n httpService: HttpService;\n}\n\n/**\n * Options that can be passed to {@link LayerFactory.create}.\n *\n * The `type` option is mandatory and indicates the type of the layer (e.g. `WMSLayer`).\n * The other options depend on the specific layer type.\n *\n * @group Services\n */\nexport type LayerCreateOptions<LayerType extends Layer, Config extends LayerConfig> = {\n /** The layer type to construct. */\n type: LayerConstructor<Config, LayerType>;\n} & Config;\n\n/**\n * Creates instances of layer classes.\n *\n * Use the interface `\"map.LayerFactory\"` to obtain an instance of this service.\n *\n * @group Services\n */\nexport class LayerFactory {\n declare [DECLARE_SERVICE_INTERFACE]: \"map.LayerFactory\";\n\n #httpService: HttpService;\n\n constructor(options: ServiceOptions<References>) {\n this.#httpService = options.references.httpService;\n }\n\n /**\n * Creates a new instance of the given layer type.\n * The `\"type\"` option is mandatory and specifies which layer type to create.\n *\n * The other configuration options may be dependent on the specific layer type.\n *\n * Example:\n *\n * ```ts\n * import { SimpleLayer } from \"@open-pioneer/map\";\n *\n * const layerFactory = ...; // injected\n * const layer = layerFactory.create({\n * type: SimpleLayer,\n * title: \"Layer title\",\n * olLayer: new TileLayer({}),\n * // ... other options\n * });\n * ```\n */\n create<LayerType extends Layer, Config extends LayerConfig>(\n config: LayerCreateOptions<LayerType, Config>\n ): LayerType {\n const { type, ...rest } = config;\n if (!type || !(type.prototype instanceof AbstractLayer)) {\n throw new Error(\n `Invalid layer type option. Use one of the layer classes exported by this package.`\n );\n }\n return new type(\n rest as unknown as Config,\n { httpService: this.#httpService },\n INTERNAL_CONSTRUCTOR_TAG\n );\n }\n}\n"],"names":[],"mappings":";;;AAmCO,MAAM,YAAA,CAAa;AAAA,EAGtB,YAAA;AAAA,EAEA,YAAY,OAAA,EAAqC;AAC7C,IAAA,IAAA,CAAK,YAAA,GAAe,QAAQ,UAAA,CAAW,WAAA;AAAA,EAC3C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAsBA,OACI,MAAA,EACS;AACT,IAAA,MAAM,EAAE,IAAA,EAAM,GAAG,IAAA,EAAK,GAAI,MAAA;AAC1B,IAAA,IAAI,CAAC,IAAA,IAAQ,EAAE,IAAA,CAAK,qBAAqB,aAAA,CAAA,EAAgB;AACrD,MAAA,MAAM,IAAI,KAAA;AAAA,QACN,CAAA,iFAAA;AAAA,OACJ;AAAA,IACJ;AACA,IAAA,OAAO,IAAI,IAAA;AAAA,MACP,IAAA;AAAA,MACA,EAAE,WAAA,EAAa,IAAA,CAAK,YAAA,EAAa;AAAA,MACjC;AAAA,KACJ;AAAA,EACJ;AACJ;;;;"}
|
package/MapRegistry.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { batch } from '@conterra/reactivity-core';
|
|
2
2
|
import { on } from '@conterra/reactivity-events';
|
|
3
3
|
import { createLogger } from '@open-pioneer/core';
|
|
4
|
-
import { sourceId$
|
|
4
|
+
import { sourceId$11 as sourceId } from './_virtual/source-info.js';
|
|
5
5
|
import { createMapModel } from './model/createMapModel.js';
|
|
6
6
|
|
|
7
7
|
const LOG = createLogger(sourceId);
|
package/MapRegistry.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MapRegistry.js","sources":["MapRegistry.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { batch, ReadonlyReactive } from \"@conterra/reactivity-core\";\nimport { on } from \"@conterra/reactivity-events\";\nimport { createLogger, Resource } from \"@open-pioneer/core\";\nimport { HttpService } from \"@open-pioneer/http\";\nimport {\n DECLARE_SERVICE_INTERFACE,\n PackageIntl,\n Service,\n ServiceOptions\n} from \"@open-pioneer/runtime\";\nimport OlMap from \"ol/Map\";\nimport { sourceId } from \"open-pioneer:source-info\";\nimport { LayerFactory } from \"./LayerFactory\";\nimport { createMapModel } from \"./model/createMapModel\";\nimport { MapConfig } from \"./model/MapConfig\";\nimport { MapModel } from \"./model/MapModel\";\n\nconst LOG = createLogger(sourceId);\n\n/**\n * Options passed to the {@link MapConfigProvider.getMapConfig} method.\n *\n * @group Services\n */\nexport interface MapConfigProviderOptions {\n /**\n * A reference to the layer factory, for the construction of new layer instances.\n */\n layerFactory: LayerFactory;\n}\n\n/**\n * Provides an OpenLayers map configuration with a given map id.\n *\n * The implementor must also provide the interface name `\"map.MapConfigProvider\"`.\n *\n * @group Services\n */\nexport interface MapConfigProvider {\n /**\n * Unique identifier of the map.\n */\n readonly mapId: string;\n\n /**\n * Returns the map configuration for this map.\n *\n * Called by the {@link MapRegistry} when the map is requested for the first time.\n *\n * See {@link MapConfig} for supported options during map creation.\n * Use {@link MapConfigProviderOptions.layerFactory} to construct new layers.\n */\n getMapConfig(options: MapConfigProviderOptions): Promise<MapConfig>;\n}\n\ninterface References {\n providers: MapConfigProvider[];\n httpService: HttpService;\n layerFactory: LayerFactory;\n}\n\ntype ModelJobResult =\n | { kind: \"model\"; model: MapModel; listener: Resource }\n | { kind: \"error\"; error: Error };\n\n/**\n * Provides access to registered map instances.\n *\n * Maps are identified by a unique id.\n *\n * Inject an instance of this service by referencing the interface name `\"map.MapRegistry\"`.\n *\n * @group Services\n */\nexport class MapRegistry implements Service {\n declare [DECLARE_SERVICE_INTERFACE]: \"map.MapRegistry\";\n\n #currentIntl: ReadonlyReactive<PackageIntl>;\n #httpService: HttpService;\n #layerFactory: LayerFactory;\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, currentIntl }: ServiceOptions<References>) {\n this.#currentIntl = currentIntl;\n this.#httpService = references.httpService;\n this.#layerFactory = references.layerFactory;\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 batch(() => {\n LOG.debug(`Destroy map registry and all maps`);\n this.#destroyed = true;\n this.#entries.forEach((entry) => {\n if (entry.kind === \"model\") {\n entry.listener.destroy();\n entry.model.destroy();\n }\n });\n this.#entries.clear();\n this.#modelCreationJobs.clear();\n });\n }\n\n /**\n * Returns the map model associated with the given id.\n * Returns undefined if there is no such model.\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 entry = this.#entries.get(mapId);\n if (entry) {\n return unbox(entry);\n }\n\n const creationJob = this.#modelCreationJobs.get(mapId);\n if (creationJob) {\n return await waitForResult(creationJob);\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 return await this.#createMapModel(mapId, () =>\n provider.getMapConfig({\n layerFactory: this.#layerFactory\n })\n );\n }\n\n /**\n * Like {@link getMapModel}, but throws if no model exists for the given `mapId`.\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 /**\n * Creates a MapModel without the need to provide a {@link MapConfigProvider}.\n * Throws an error if a map with the given id already exists or if the map config is invalid.\n */\n async createMapModel(mapId: string, options?: MapConfig): Promise<MapModel> {\n if (this.#destroyed) {\n throw new Error(\"MapRegistry has already been destroyed.\");\n }\n if (this.#entries.has(mapId)) {\n throw new Error(`Map id '${mapId}' is not unique.`);\n }\n if (this.#modelCreationJobs.has(mapId)) {\n throw new Error(`A map with the id '${mapId}' is already under construction.`);\n }\n return await this.#createMapModel(mapId, () => Promise.resolve(options ?? {}));\n }\n\n /**\n * Given a raw OpenLayers map instance, returns the associated {@link MapModel} - or undefined\n * if the map is unknown to this registry.\n *\n * All OpenLayers maps created by this registry (e.g. via {@link MapConfigProvider} or {@link createMapModel}) have an associated map model.\n */\n getMapModelByRawInstance(olMap: OlMap): MapModel | undefined {\n return this.#modelsByOlMap.get(olMap);\n }\n\n // Wrapper method to ensure that in-progress construction of maps can be observed.\n #createMapModel(mapId: string, configProvider: () => Promise<MapConfig>): Promise<MapModel> {\n const creationJob = this.#modelCreationJobs.get(mapId);\n if (creationJob) {\n throw new Error(\"Internal error: a map model is already being created for this mapId\");\n }\n\n const modelPromise = this.#createMapModelImpl(mapId, configProvider)\n .then((mapModel) => {\n if (this.#destroyed) {\n mapModel.destroy();\n throw new Error(`MapRegistry has been destroyed.`);\n }\n\n const listener = on(\n mapModel.destroyed,\n () => {\n // Allow id reuse for dynamically created maps\n if (this.#isDynamic(mapId)) {\n const currentEntry = this.#entries.get(mapId);\n if (currentEntry === entry) {\n this.#entries.delete(mapId);\n }\n }\n },\n { dispatch: \"sync\" }\n );\n\n const entry: ModelJobResult = { kind: \"model\", model: mapModel, listener };\n this.#entries.set(mapId, entry);\n this.#modelCreationJobs.delete(mapId);\n this.#modelsByOlMap.set(mapModel.olMap, mapModel);\n return entry;\n })\n .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 if (!this.#isDynamic(mapId)) {\n // Don't store errors for dynamically created maps (the caller already got the error via promise).\n this.#entries.set(mapId, entry);\n }\n return entry;\n });\n this.#modelCreationJobs.set(mapId, modelPromise);\n return waitForResult(modelPromise);\n }\n\n async #createMapModelImpl(\n mapId: string,\n configProvider: () => Promise<MapConfig>\n ): Promise<MapModel> {\n LOG.info(`Creating map with id '${mapId}'`);\n const mapConfig = await configProvider();\n const mapModel = await createMapModel(\n mapId,\n mapConfig,\n this.#currentIntl,\n this.#httpService\n );\n return mapModel;\n }\n\n #isDynamic(mapId: string): boolean {\n return !this.#configProviders.has(mapId);\n }\n}\n\nasync function waitForResult(job: Promise<ModelJobResult>): Promise<MapModel> {\n return unbox(await job);\n}\n\nfunction unbox(entry: ModelJobResult): MapModel {\n if (entry.kind === \"error\") {\n throw entry.error;\n }\n return entry.model;\n}\n"],"names":[],"mappings":";;;;;;AAmBA,MAAM,GAAA,GAAM,aAAa,QAAQ,CAAA;AAyD1B,MAAM,WAAA,CAA+B;AAAA,EAGxC,YAAA;AAAA,EACA,YAAA;AAAA,EACA,aAAA;AAAA,EAEA,gBAAA,uBAAuB,GAAA,EAA+B;AAAA,EACtD,QAAA,uBAAe,GAAA,EAA4B;AAAA,EAC3C,kBAAA,uBAAyB,GAAA,EAAqC;AAAA,EAC9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,EAAyB,KAAK,CAAA,CAAA,CAAG,CAAA;AAC1C,IAAA,MAAM,SAAA,GAAY,MAAM,cAAA,EAAe;AACvC,IAAA,MAAM,WAAW,MAAM,cAAA;AAAA,MACnB,KAAA;AAAA,MACA,SAAA;AAAA,MACA,IAAA,CAAK,YAAA;AAAA,MACL,IAAA,CAAK;AAAA,KACT;AACA,IAAA,OAAO,QAAA;AAAA,EACX;AAAA,EAEA,WAAW,KAAA,EAAwB;AAC/B,IAAA,OAAO,CAAC,IAAA,CAAK,gBAAA,CAAiB,GAAA,CAAI,KAAK,CAAA;AAAA,EAC3C;AACJ;AAEA,eAAe,cAAc,GAAA,EAAiD;AAC1E,EAAA,OAAO,KAAA,CAAM,MAAM,GAAG,CAAA;AAC1B;AAEA,SAAS,MAAM,KAAA,EAAiC;AAC5C,EAAA,IAAI,KAAA,CAAM,SAAS,OAAA,EAAS;AACxB,IAAA,MAAM,KAAA,CAAM,KAAA;AAAA,EAChB;AACA,EAAA,OAAO,KAAA,CAAM,KAAA;AACjB;;;;"}
|
|
1
|
+
{"version":3,"file":"MapRegistry.js","sources":["MapRegistry.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n\nimport { batch, ReadonlyReactive } from \"@conterra/reactivity-core\";\nimport { on } from \"@conterra/reactivity-events\";\nimport { createLogger, Resource } from \"@open-pioneer/core\";\nimport { HttpService } from \"@open-pioneer/http\";\nimport {\n DECLARE_SERVICE_INTERFACE,\n PackageIntl,\n Service,\n ServiceOptions\n} from \"@open-pioneer/runtime\";\nimport OlMap from \"ol/Map\";\nimport { sourceId } from \"open-pioneer:source-info\";\nimport { LayerFactory } from \"./LayerFactory\";\nimport { createMapModel } from \"./model/createMapModel\";\nimport { MapConfig } from \"./model/MapConfig\";\nimport { MapModel } from \"./model/MapModel\";\n\nconst LOG = createLogger(sourceId);\n\n/**\n * Options passed to the {@link MapConfigProvider.getMapConfig} method.\n *\n * @group Services\n */\nexport interface MapConfigProviderOptions {\n /**\n * A reference to the layer factory, for the construction of new layer instances.\n */\n layerFactory: LayerFactory;\n}\n\n/**\n * Provides an OpenLayers map configuration with a given map id.\n *\n * The implementor must also provide the interface name `\"map.MapConfigProvider\"`.\n *\n * @group Services\n */\nexport interface MapConfigProvider {\n /**\n * Unique identifier of the map.\n */\n readonly mapId: string;\n\n /**\n * Returns the map configuration for this map.\n *\n * Called by the {@link MapRegistry} when the map is requested for the first time.\n *\n * See {@link MapConfig} for supported options during map creation.\n * Use {@link MapConfigProviderOptions.layerFactory} to construct new layers.\n */\n getMapConfig(options: MapConfigProviderOptions): Promise<MapConfig>;\n}\n\ninterface References {\n providers: MapConfigProvider[];\n httpService: HttpService;\n layerFactory: LayerFactory;\n}\n\ntype ModelJobResult =\n | { kind: \"model\"; model: MapModel; listener: Resource }\n | { kind: \"error\"; error: Error };\n\n/**\n * Provides access to registered map instances.\n *\n * Maps are identified by a unique id.\n *\n * Inject an instance of this service by referencing the interface name `\"map.MapRegistry\"`.\n *\n * @group Services\n */\nexport class MapRegistry implements Service {\n declare [DECLARE_SERVICE_INTERFACE]: \"map.MapRegistry\";\n\n #currentIntl: ReadonlyReactive<PackageIntl>;\n #httpService: HttpService;\n #layerFactory: LayerFactory;\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, currentIntl }: ServiceOptions<References>) {\n this.#currentIntl = currentIntl;\n this.#httpService = references.httpService;\n this.#layerFactory = references.layerFactory;\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 batch(() => {\n LOG.debug(`Destroy map registry and all maps`);\n this.#destroyed = true;\n this.#entries.forEach((entry) => {\n if (entry.kind === \"model\") {\n entry.listener.destroy();\n entry.model.destroy();\n }\n });\n this.#entries.clear();\n this.#modelCreationJobs.clear();\n });\n }\n\n /**\n * Returns the map model associated with the given id.\n * Returns undefined if there is no such model.\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 entry = this.#entries.get(mapId);\n if (entry) {\n return unbox(entry);\n }\n\n const creationJob = this.#modelCreationJobs.get(mapId);\n if (creationJob) {\n return await waitForResult(creationJob);\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 return await this.#createMapModel(mapId, () =>\n provider.getMapConfig({\n layerFactory: this.#layerFactory\n })\n );\n }\n\n /**\n * Like {@link getMapModel}, but throws if no model exists for the given `mapId`.\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 /**\n * Creates a MapModel without the need to provide a {@link MapConfigProvider}.\n * Throws an error if a map with the given id already exists or if the map config is invalid.\n */\n async createMapModel(mapId: string, options?: MapConfig): Promise<MapModel> {\n if (this.#destroyed) {\n throw new Error(\"MapRegistry has already been destroyed.\");\n }\n if (this.#entries.has(mapId)) {\n throw new Error(`Map id '${mapId}' is not unique.`);\n }\n if (this.#modelCreationJobs.has(mapId)) {\n throw new Error(`A map with the id '${mapId}' is already under construction.`);\n }\n return await this.#createMapModel(mapId, () => Promise.resolve(options ?? {}));\n }\n\n /**\n * Given a raw OpenLayers map instance, returns the associated {@link MapModel} - or undefined\n * if the map is unknown to this registry.\n *\n * All OpenLayers maps created by this registry (e.g. via {@link MapConfigProvider} or {@link createMapModel}) have an associated map model.\n */\n getMapModelByRawInstance(olMap: OlMap): MapModel | undefined {\n return this.#modelsByOlMap.get(olMap);\n }\n\n // Wrapper method to ensure that in-progress construction of maps can be observed.\n #createMapModel(mapId: string, configProvider: () => Promise<MapConfig>): Promise<MapModel> {\n const creationJob = this.#modelCreationJobs.get(mapId);\n if (creationJob) {\n throw new Error(\"Internal error: a map model is already being created for this mapId\");\n }\n\n const modelPromise = this.#createMapModelImpl(mapId, configProvider)\n .then((mapModel) => {\n if (this.#destroyed) {\n mapModel.destroy();\n throw new Error(`MapRegistry has been destroyed.`);\n }\n\n const listener = on(\n mapModel.destroyed,\n () => {\n // Allow id reuse for dynamically created maps\n if (this.#isDynamic(mapId)) {\n const currentEntry = this.#entries.get(mapId);\n if (currentEntry === entry) {\n this.#entries.delete(mapId);\n }\n }\n },\n { dispatch: \"sync\" }\n );\n\n const entry: ModelJobResult = { kind: \"model\", model: mapModel, listener };\n this.#entries.set(mapId, entry);\n this.#modelCreationJobs.delete(mapId);\n this.#modelsByOlMap.set(mapModel.olMap, mapModel);\n return entry;\n })\n .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 if (!this.#isDynamic(mapId)) {\n // Don't store errors for dynamically created maps (the caller already got the error via promise).\n this.#entries.set(mapId, entry);\n }\n return entry;\n });\n this.#modelCreationJobs.set(mapId, modelPromise);\n return waitForResult(modelPromise);\n }\n\n async #createMapModelImpl(\n mapId: string,\n configProvider: () => Promise<MapConfig>\n ): Promise<MapModel> {\n LOG.info(`Creating map with id '${mapId}'`);\n const mapConfig = await configProvider();\n const mapModel = await createMapModel(\n mapId,\n mapConfig,\n this.#currentIntl,\n this.#httpService\n );\n return mapModel;\n }\n\n #isDynamic(mapId: string): boolean {\n return !this.#configProviders.has(mapId);\n }\n}\n\nasync function waitForResult(job: Promise<ModelJobResult>): Promise<MapModel> {\n return unbox(await job);\n}\n\nfunction unbox(entry: ModelJobResult): MapModel {\n if (entry.kind === \"error\") {\n throw entry.error;\n }\n return entry.model;\n}\n"],"names":[],"mappings":";;;;;;AAoBA,MAAM,GA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,IACX,CAAC,CAAA;AACL,IAAA,IAAA,CAAK,kBAAA,CAAmB,GAAA,CAAI,KAAA,EAAO,YAAY,CAAA;AAC/C,IAAA,OAAO,cAAc,YAAY,CAAA;AAAA,EACrC;AAAA,EAEA,MAAM,mBAAA,CACF,KAAA,EACA,cAAA,EACiB;AACjB,IAAA,GAAA,CAAI,IAAA,CAAK,CAAA,sBAAA,EAAyB,KAAK,CAAA,CAAA,CAAG,CAAA;AAC1C,IAAA,MAAM,SAAA,GAAY,MAAM,cAAA,EAAe;AACvC,IAAA,MAAM,WAAW,MAAM,cAAA;AAAA,MACnB,KAAA;AAAA,MACA,SAAA;AAAA,MACA,IAAA,CAAK,YAAA;AAAA,MACL,IAAA,CAAK;AAAA,KACT;AACA,IAAA,OAAO,QAAA;AAAA,EACX;AAAA,EAEA,WAAW,KAAA,EAAwB;AAC/B,IAAA,OAAO,CAAC,IAAA,CAAK,gBAAA,CAAiB,GAAA,CAAI,KAAK,CAAA;AAAA,EAC3C;AACJ;AAEA,eAAe,cAAc,GAAA,EAAiD;AAC1E,EAAA,OAAO,KAAA,CAAM,MAAM,GAAG,CAAA;AAC1B;AAEA,SAAS,MAAM,KAAA,EAAiC;AAC5C,EAAA,IAAI,KAAA,CAAM,SAAS,OAAA,EAAS;AACxB,IAAA,MAAM,KAAA,CAAM,KAAA;AAAA,EAChB;AACA,EAAA,OAAO,KAAA,CAAM,KAAA;AACjB;;;;"}
|
package/README.md
CHANGED
|
@@ -149,13 +149,9 @@ export class AppModel implements Service {
|
|
|
149
149
|
declare [DECLARE_SERVICE_INTERFACE]: "example.AppModel";
|
|
150
150
|
constructor({ references }: ServiceOptions<References>) {
|
|
151
151
|
this._mapRegistry = references.mapRegistry;
|
|
152
|
-
this._mapRegistry
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
})
|
|
156
|
-
.then((map) => {
|
|
157
|
-
// use the map model instance
|
|
158
|
-
});
|
|
152
|
+
this._mapRegistry.createMapModel("myMapModelId", {/* map config */}).then((map) => {
|
|
153
|
+
// use the map model instance
|
|
154
|
+
});
|
|
159
155
|
}
|
|
160
156
|
}
|
|
161
157
|
```
|
|
@@ -193,9 +189,7 @@ import { MapConfig, MapConfigProvider } from "@open-pioneer/map";
|
|
|
193
189
|
|
|
194
190
|
export class MapConfigProviderImpl implements MapConfigProvider {
|
|
195
191
|
async getMapConfig(): Promise<MapConfig> {
|
|
196
|
-
return {
|
|
197
|
-
/* map config */
|
|
198
|
-
};
|
|
192
|
+
return {/* map config */};
|
|
199
193
|
}
|
|
200
194
|
}
|
|
201
195
|
```
|
|
@@ -995,19 +989,19 @@ interface References {
|
|
|
995
989
|
}
|
|
996
990
|
|
|
997
991
|
export class TestService {
|
|
998
|
-
|
|
992
|
+
#registry: MapRegistry;
|
|
999
993
|
|
|
1000
994
|
constructor(options: ServiceOptions<References>) {
|
|
1001
|
-
this
|
|
995
|
+
this.#registry = options.references.mapRegistry;
|
|
1002
996
|
}
|
|
1003
997
|
|
|
1004
998
|
async centerBerlin() {
|
|
1005
|
-
const model = await this
|
|
999
|
+
const model = await this.#registry.getMapModel(MAP_ID);
|
|
1006
1000
|
model?.olMap?.getView().fit([1489200, 6894026, 1489200, 6894026], { maxZoom: 13 });
|
|
1007
1001
|
}
|
|
1008
1002
|
|
|
1009
1003
|
async setLayerVisible() {
|
|
1010
|
-
const model = await this
|
|
1004
|
+
const model = await this.#registry.getMapModel(MAP_ID);
|
|
1011
1005
|
const layer = model?.layers.getLayerById("abe0e3f8-0ba2-409c-b6b4-9d8429c732e3");
|
|
1012
1006
|
layer?.setVisible(true);
|
|
1013
1007
|
}
|
package/_virtual/source-info.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
const sourceId$
|
|
1
|
+
const sourceId$b = "@open-pioneer/map/ui/MapContainer";
|
|
2
2
|
|
|
3
|
-
const sourceId$
|
|
3
|
+
const sourceId$a = "@open-pioneer/map/model/MapModel";
|
|
4
4
|
|
|
5
|
-
const sourceId$
|
|
5
|
+
const sourceId$9 = "@open-pioneer/map/layers/AbstractLayer";
|
|
6
6
|
|
|
7
|
-
const sourceId$
|
|
7
|
+
const sourceId$8 = "@open-pioneer/map/model/LayerCollection";
|
|
8
8
|
|
|
9
|
-
const sourceId$
|
|
9
|
+
const sourceId$7 = "@open-pioneer/map/model/Overlays";
|
|
10
|
+
|
|
11
|
+
const sourceId$6 = "@open-pioneer/map/ui/hooks/useMapModel";
|
|
10
12
|
|
|
11
13
|
const sourceId$5 = "@open-pioneer/map/layers/WMSLayer";
|
|
12
14
|
|
|
@@ -20,5 +22,5 @@ const sourceId$1 = "@open-pioneer/map/MapRegistry";
|
|
|
20
22
|
|
|
21
23
|
const sourceId = "@open-pioneer/map/model/createMapModel";
|
|
22
24
|
|
|
23
|
-
export { sourceId$
|
|
25
|
+
export { sourceId$9 as sourceId, sourceId$8 as sourceId$1, sourceId as sourceId$10, sourceId$1 as sourceId$11, sourceId$7 as sourceId$2, sourceId$a as sourceId$3, sourceId$6 as sourceId$4, sourceId$b as sourceId$5, sourceId$4 as sourceId$6, sourceId$5 as sourceId$7, sourceId$2 as sourceId$8, sourceId$3 as sourceId$9 };
|
|
24
26
|
//# sourceMappingURL=source-info.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"source-info.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"source-info.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import OlBaseLayer from "ol/layer/Base";
|
|
2
|
+
import OlSource from "ol/source/Source";
|
|
2
3
|
import { MapModel } from "../model/MapModel";
|
|
3
4
|
import { InternalConstructorTag } from "../utils/InternalConstructorTag";
|
|
4
5
|
import { AbstractLayerBase } from "./AbstractLayerBase";
|
|
5
|
-
import { ATTACH_TO_MAP, GET_DEPS, LayerDependencies, SET_VISIBLE } from "./shared/internals";
|
|
6
|
+
import { ATTACH_TO_MAP, GET_DEPS, LayerDependencies, SET_METADATA_LOAD_INFO, SET_VISIBLE } from "./shared/internals";
|
|
6
7
|
import { SimpleLayerConfig } from "./SimpleLayer";
|
|
7
8
|
import { LayerTypes } from "./unions";
|
|
8
9
|
/**
|
|
@@ -11,6 +12,15 @@ import { LayerTypes } from "./unions";
|
|
|
11
12
|
* @group Layer Utilities
|
|
12
13
|
**/
|
|
13
14
|
export type LayerLoadState = "not-loaded" | "loading" | "loaded" | "error";
|
|
15
|
+
/**
|
|
16
|
+
* Load state of a single layer, bundling the state with its error.
|
|
17
|
+
*
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
export type LayerLoadInfo = "not-loaded" | "loading" | "loaded" | {
|
|
21
|
+
kind: "error";
|
|
22
|
+
error: Error;
|
|
23
|
+
};
|
|
14
24
|
/**
|
|
15
25
|
* Represents an operational layer in the map.
|
|
16
26
|
*
|
|
@@ -23,7 +33,10 @@ export type LayerLoadState = "not-loaded" | "loading" | "loaded" | "error";
|
|
|
23
33
|
*/
|
|
24
34
|
export declare abstract class AbstractLayer extends AbstractLayerBase {
|
|
25
35
|
#private;
|
|
26
|
-
constructor(config: SimpleLayerConfig
|
|
36
|
+
constructor(config: SimpleLayerConfig & {
|
|
37
|
+
/** The initial load state (default: not-loaded). */
|
|
38
|
+
initialLoadInfo?: LayerLoadInfo;
|
|
39
|
+
}, deps?: LayerDependencies, internalTag?: InternalConstructorTag);
|
|
27
40
|
destroy(): void;
|
|
28
41
|
/**
|
|
29
42
|
* Identifies the type of this layer.
|
|
@@ -34,6 +47,10 @@ export declare abstract class AbstractLayer extends AbstractLayerBase {
|
|
|
34
47
|
* The raw OpenLayers layer.
|
|
35
48
|
*/
|
|
36
49
|
get olLayer(): OlBaseLayer;
|
|
50
|
+
/**
|
|
51
|
+
* The current source of the {@link olLayer}.
|
|
52
|
+
*/
|
|
53
|
+
get olSource(): OlSource | undefined;
|
|
37
54
|
/**
|
|
38
55
|
* True if this layer is a base layer.
|
|
39
56
|
*
|
|
@@ -41,9 +58,19 @@ export declare abstract class AbstractLayer extends AbstractLayerBase {
|
|
|
41
58
|
*/
|
|
42
59
|
get isBaseLayer(): boolean;
|
|
43
60
|
/**
|
|
44
|
-
* The load state of a layer.
|
|
61
|
+
* The combined load state of a layer.
|
|
62
|
+
*
|
|
63
|
+
* Aggregates the OpenLayers source state, health check and metadata state.
|
|
64
|
+
* Priority for the state: `error` > `loading` > `not-loaded` > `loaded`.
|
|
45
65
|
*/
|
|
46
66
|
get loadState(): LayerLoadState;
|
|
67
|
+
/**
|
|
68
|
+
* The error (if any) that prevented this layer from loading.
|
|
69
|
+
*
|
|
70
|
+
* Combines errors from the OpenLayers source, the health check and the
|
|
71
|
+
* metadata request (health > metadata > source).
|
|
72
|
+
*/
|
|
73
|
+
get loadError(): Error | undefined;
|
|
47
74
|
/**
|
|
48
75
|
* The minimum resolution (inclusive) at which this layer will be visible.
|
|
49
76
|
*/
|
|
@@ -86,6 +113,12 @@ export declare abstract class AbstractLayer extends AbstractLayerBase {
|
|
|
86
113
|
* @internal
|
|
87
114
|
*/
|
|
88
115
|
[ATTACH_TO_MAP](map: MapModel): void;
|
|
116
|
+
/**
|
|
117
|
+
* Updates the load state of the layer's metadata request.
|
|
118
|
+
*
|
|
119
|
+
* @internal
|
|
120
|
+
*/
|
|
121
|
+
[SET_METADATA_LOAD_INFO](loadInfo: LayerLoadInfo): void;
|
|
89
122
|
setVisible(newVisibility: boolean): void;
|
|
90
123
|
/** @internal */
|
|
91
124
|
[SET_VISIBLE](newVisibility: boolean): void;
|