@open-pioneer/map 0.0.0-dev-20241120114910

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) hide show
  1. package/CHANGELOG.md +354 -0
  2. package/LICENSE +202 -0
  3. package/MapRegistryImpl.d.ts +17 -0
  4. package/MapRegistryImpl.js +91 -0
  5. package/MapRegistryImpl.js.map +1 -0
  6. package/README.md +871 -0
  7. package/_virtual/_virtual-pioneer-module_react-hooks.js +7 -0
  8. package/_virtual/_virtual-pioneer-module_react-hooks.js.map +1 -0
  9. package/api/BaseFeature.d.ts +31 -0
  10. package/api/MapConfig.d.ts +111 -0
  11. package/api/MapModel.d.ts +229 -0
  12. package/api/MapRegistry.d.ts +48 -0
  13. package/api/index.d.ts +15 -0
  14. package/api/layers/GroupLayer.d.ts +50 -0
  15. package/api/layers/GroupLayer.js +6 -0
  16. package/api/layers/GroupLayer.js.map +1 -0
  17. package/api/layers/SimpleLayer.d.ts +27 -0
  18. package/api/layers/SimpleLayer.js +6 -0
  19. package/api/layers/SimpleLayer.js.map +1 -0
  20. package/api/layers/WMSLayer.d.ts +57 -0
  21. package/api/layers/WMSLayer.js +6 -0
  22. package/api/layers/WMSLayer.js.map +1 -0
  23. package/api/layers/WMTSLayer.d.ts +33 -0
  24. package/api/layers/WMTSLayer.js +6 -0
  25. package/api/layers/WMTSLayer.js.map +1 -0
  26. package/api/layers/base.d.ts +242 -0
  27. package/api/layers/base.js +9 -0
  28. package/api/layers/base.js.map +1 -0
  29. package/api/layers/index.d.ts +5 -0
  30. package/api/shared.d.ts +10 -0
  31. package/assets/images/mapMarker.png +0 -0
  32. package/index.d.ts +1 -0
  33. package/index.js +15 -0
  34. package/index.js.map +1 -0
  35. package/internalTestSupport.d.ts +8 -0
  36. package/internalTestSupport.js +2 -0
  37. package/internalTestSupport.js.map +1 -0
  38. package/layers/BkgTopPlusOpen.d.ts +21 -0
  39. package/layers/BkgTopPlusOpen.js +61 -0
  40. package/layers/BkgTopPlusOpen.js.map +1 -0
  41. package/model/AbstractLayer.d.ts +25 -0
  42. package/model/AbstractLayer.js +186 -0
  43. package/model/AbstractLayer.js.map +1 -0
  44. package/model/AbstractLayerBase.d.ts +54 -0
  45. package/model/AbstractLayerBase.js +119 -0
  46. package/model/AbstractLayerBase.js.map +1 -0
  47. package/model/Highlights.d.ts +42 -0
  48. package/model/Highlights.js +272 -0
  49. package/model/Highlights.js.map +1 -0
  50. package/model/LayerCollectionImpl.d.ts +27 -0
  51. package/model/LayerCollectionImpl.js +228 -0
  52. package/model/LayerCollectionImpl.js.map +1 -0
  53. package/model/MapModelImpl.d.ts +46 -0
  54. package/model/MapModelImpl.js +271 -0
  55. package/model/MapModelImpl.js.map +1 -0
  56. package/model/SublayersCollectionImpl.d.ts +18 -0
  57. package/model/SublayersCollectionImpl.js +31 -0
  58. package/model/SublayersCollectionImpl.js.map +1 -0
  59. package/model/createMapModel.d.ts +4 -0
  60. package/model/createMapModel.js +157 -0
  61. package/model/createMapModel.js.map +1 -0
  62. package/model/layers/GroupLayerImpl.d.ts +39 -0
  63. package/model/layers/GroupLayerImpl.js +88 -0
  64. package/model/layers/GroupLayerImpl.js.map +1 -0
  65. package/model/layers/SimpleLayerImpl.d.ts +13 -0
  66. package/model/layers/SimpleLayerImpl.js +19 -0
  67. package/model/layers/SimpleLayerImpl.js.map +1 -0
  68. package/model/layers/WMSLayerImpl.d.ts +41 -0
  69. package/model/layers/WMSLayerImpl.js +297 -0
  70. package/model/layers/WMSLayerImpl.js.map +1 -0
  71. package/model/layers/WMTSLayerImpl.d.ts +17 -0
  72. package/model/layers/WMTSLayerImpl.js +156 -0
  73. package/model/layers/WMTSLayerImpl.js.map +1 -0
  74. package/package.json +86 -0
  75. package/projections.d.ts +27 -0
  76. package/projections.js +15 -0
  77. package/projections.js.map +1 -0
  78. package/services.d.ts +1 -0
  79. package/services.js +2 -0
  80. package/services.js.map +1 -0
  81. package/ui/CssProps.d.ts +9 -0
  82. package/ui/CssProps.js +13 -0
  83. package/ui/CssProps.js.map +1 -0
  84. package/ui/DefaultMapProvider.d.ts +39 -0
  85. package/ui/DefaultMapProvider.js +24 -0
  86. package/ui/DefaultMapProvider.js.map +1 -0
  87. package/ui/MapAnchor.d.ts +36 -0
  88. package/ui/MapAnchor.js +28 -0
  89. package/ui/MapAnchor.js.map +1 -0
  90. package/ui/MapContainer.d.ts +50 -0
  91. package/ui/MapContainer.js +191 -0
  92. package/ui/MapContainer.js.map +1 -0
  93. package/ui/MapContainerContext.d.ts +7 -0
  94. package/ui/MapContainerContext.js +17 -0
  95. package/ui/MapContainerContext.js.map +1 -0
  96. package/ui/computeMapAnchorStyles.d.ts +3 -0
  97. package/ui/computeMapAnchorStyles.js +51 -0
  98. package/ui/computeMapAnchorStyles.js.map +1 -0
  99. package/ui/hooks.d.ts +34 -0
  100. package/ui/hooks.js +73 -0
  101. package/ui/hooks.js.map +1 -0
  102. package/ui/styles.css +10 -0
  103. package/ui/styles.css.map +1 -0
  104. package/ui/useMapModel.d.ts +58 -0
  105. package/ui/useMapModel.js +59 -0
  106. package/ui/useMapModel.js.map +1 -0
  107. package/util/capabilities-utils.d.ts +2 -0
  108. package/util/capabilities-utils.js +11 -0
  109. package/util/capabilities-utils.js.map +1 -0
  110. package/util/geometry-utils.d.ts +7 -0
  111. package/util/geometry-utils.js +25 -0
  112. package/util/geometry-utils.js.map +1 -0
  113. package/util/ol-test-support.d.ts +2 -0
  114. package/util/ol-test-support.js +24 -0
  115. package/util/ol-test-support.js.map +1 -0
package/README.md ADDED
@@ -0,0 +1,871 @@
1
+ # @open-pioneer/map
2
+
3
+ This package integrates [OpenLayers](https://openlayers.org/) maps into an Open Pioneer Trails application.
4
+ APIs provided by this package can be used to configure, embed and access the map and its contents.
5
+
6
+ ## Usage
7
+
8
+ To use the map in your app, follow these two steps:
9
+
10
+ - Add a `MapContainer` component to your app (see [Map container component](#map-container-component)).
11
+ - Implement a `MapConfigProvider` (see [Map configuration](#map-configuration)).
12
+
13
+ To access or manipulate the content of the map programmatically, see [Using the map model](#using-the-map-model).
14
+
15
+ ### Map container component
16
+
17
+ To integrate a `MapContainer` in an app, add the component to your React component, where you want the map to appear.
18
+ On the component specify the `mapId` of the map that you want to add.
19
+
20
+ Make sure that the parent component has an appropriate width and height (for example `100%`).
21
+ The `MapContainer` fills the entire available space.
22
+
23
+ Example: Integration of a map container with a given map ID:
24
+
25
+ ```jsx
26
+ import { Box } from "@open-pioneer/chakra-integration";
27
+ import { MapContainer } from "@open-pioneer/map";
28
+
29
+ // ...
30
+ function AppUI() {
31
+ return (
32
+ <Box height="100%" overflow="hidden">
33
+ <MapContainer mapId="..." />
34
+ </Box>
35
+ );
36
+ }
37
+ ```
38
+
39
+ > NOTE: There must be a `map.MapConfigProvider` that knows how to construct the map with the given ID (see [Map configuration](#map-configuration)).
40
+
41
+ The component itself uses the map registry service to create the map using the provided `mapId`.
42
+
43
+ #### Changing the map view's padding
44
+
45
+ The MapContainer provides a prop `viewPadding` that allows to set the map's view padding
46
+ (see [padding property on OL View](https://openlayers.org/en/latest/apidoc/module-ol_View-View.html#padding)).
47
+ This prop musst be used to set the views padding instead of directly setting the padding on the
48
+ OL map's view to ensure that map anchor are positioned correctly.
49
+
50
+ Additionally, using the prop `viewPaddingChangeBehavior` it is possible to specify how the map behaves when the view padding changes.
51
+ Possible values are `none` (no nothing), `preserve-center`(ensures that the center point remains the same
52
+ by animating the view) and `preserve-extent` ´(ensures that the extent remains the same by zooming).
53
+
54
+ ### Map anchor component
55
+
56
+ To pass custom React components onto the map, the following anchor-points are provided:
57
+
58
+ - `top-left`
59
+ - `top-right`
60
+ - `bottom-left`
61
+ - `bottom-right`
62
+
63
+ Example: Integration of a map anchor component into the map container with position `bottom-right` and optional horizontal and vertical gap:
64
+
65
+ ```jsx
66
+ <MapContainer mapId="...">
67
+ <MapAnchor position="bottom-right" horizontalGap={25} verticalGap={25}>
68
+ ... {/** add map anchor content like other React components */}
69
+ </MapAnchor>
70
+ </MapContainer>
71
+ ```
72
+
73
+ The component itself calculates the `maxHeight` and `maxWidth` according to the map view padding and optional `horizontalGap`and `verticalGap` to avoid content overflow.
74
+ In this case, the CSS property `overflow` is set to `hidden` to the map anchor component.
75
+ If no `verticalGap` is configured, a default vertical gap of `30px` is used.
76
+
77
+ > NOTE: To get the correct tab order, add the container anchor-points before other components.
78
+
79
+ By default, certain pointer events from map anchor children (such as `pointer-down`) are stopped from bubbling up towards the map.
80
+ This is done to "hide" those events from map interactions (such as drawing): this makes it possible to click into text or controls within a map anchor without interacting with the map.
81
+ This behavior can be disabled by setting the `stopEvents` property to `false`:
82
+
83
+ ```jsx
84
+ <MapAnchor position="top-right" stopEvents={false}>
85
+ {/* Click events etc. will be seen by the map. This could be appropriate for non-interactive text-only overlays, for example. */}
86
+ </MapAnchor>
87
+ ```
88
+
89
+ ### Map configuration
90
+
91
+ Register a service providing `map.MapConfigProvider` to configure the contents of a map.
92
+ Such a provider is typically located in an app.
93
+
94
+ Example: Configuration to register a service providing `map.MapConfigProvider`.
95
+
96
+ ```js
97
+ // build.config.mjs
98
+ import { defineBuildConfig } from "@open-pioneer/build-support";
99
+
100
+ export default defineBuildConfig({
101
+ services: {
102
+ MapConfigProviderImpl: {
103
+ // Registers the service as a config provider
104
+ provides: ["map.MapConfigProvider"]
105
+ }
106
+ },
107
+ ui: {
108
+ references: ["map.MapRegistry"]
109
+ }
110
+ });
111
+ ```
112
+
113
+ The service itself needs to implement the `MapConfigProvider` interface.
114
+ The following map options are supported:
115
+
116
+ - `initialView`,
117
+ - `projection`,
118
+ - `layers` (see [Layer configuration](#layer-configuration)),
119
+ - `advanced`
120
+
121
+ Always use the provided map model to access the map initially.
122
+ Use `.olMap` only, when the raw instance is required.
123
+
124
+ If an advanced configuration (fully constructed `OlView` instance) is used, some options (such as `initialView` or `projection`) cannot be applied anymore.
125
+
126
+ Example: Implementation of the service with `initialView.kind = position`.
127
+
128
+ ```ts
129
+ // YOUR-APP/MapConfigProviderImpl.ts
130
+ import { MapConfig, MapConfigProvider } from "@open-pioneer/map";
131
+
132
+ export class MapConfigProviderImpl implements MapConfigProvider {
133
+ async getMapConfig(): Promise<MapConfig> {
134
+ return {
135
+ initialView: {
136
+ kind: "position",
137
+ center: { x: 847541, y: 6793584 },
138
+ zoom: 14
139
+ },
140
+ projection: "EPSG:3857",
141
+ layers: [
142
+ // ...
143
+ ]
144
+ };
145
+ }
146
+ }
147
+ ```
148
+
149
+ Example: Implementation of the service with `initialView.kind = extent`.
150
+
151
+ ```ts
152
+ // YOUR-APP/MapConfigProviderImpl.ts
153
+ import { MapConfig, MapConfigProvider } from "@open-pioneer/map";
154
+
155
+ export class MapConfigProviderImpl implements MapConfigProvider {
156
+ async getMapConfig(): Promise<MapConfig> {
157
+ return {
158
+ initialView: {
159
+ kind: "extent",
160
+ extent: {
161
+ xMin: 577252,
162
+ yMin: 6026906,
163
+ xMax: 1790460,
164
+ yMax: 7318386
165
+ }
166
+ },
167
+ projection: "EPSG:3857",
168
+ layers: [
169
+ // ...
170
+ ]
171
+ };
172
+ }
173
+ }
174
+ ```
175
+
176
+ Example: Implementation of the service with an advanced configuration.
177
+
178
+ ```ts
179
+ // YOUR-APP/MapConfigProviderImpl.ts
180
+ import { MapConfig, MapConfigProvider } from "@open-pioneer/map";
181
+
182
+ export class MapConfigProviderImpl implements MapConfigProvider {
183
+ async getMapConfig(): Promise<MapConfig> {
184
+ return {
185
+ advanced: {
186
+ view: new View({
187
+ center: [405948.17, 5757572.85],
188
+ zoom: 5
189
+ })
190
+ },
191
+ layers: [
192
+ // ...
193
+ ]
194
+ };
195
+ }
196
+ }
197
+ ```
198
+
199
+ > IMPORTANT: Not all OpenLayers [View](https://openlayers.org/en/latest/apidoc/module-ol_View-View.html) properties are supported.
200
+ > For example, you cannot set the target because the target is controlled by the `<MapContainer />`.
201
+
202
+ #### Layer configuration
203
+
204
+ Configure your custom layer inside the [Map configuration](#map-configuration) by using one of the layer classes provided by this package.
205
+ For example, `SimpleLayer` can be used to configure an arbitrary [`OpenLayers Layer`](https://openlayers.org/en/latest/apidoc/module-ol_layer_Layer-Layer.html) as `olLayer` property.
206
+
207
+ > **Layer Order**
208
+ >
209
+ > By default, layers are displayed in the order in which they are defined in the `layers` array.
210
+ > The later a layer is listed in the array, the higher up it is displayed in the map.
211
+ >
212
+ > Base layers are excluded from this rule: they are always displayed below all operational layers.
213
+
214
+ Example: Implementation of a layer configuration.
215
+
216
+ ```ts
217
+ // YOUR-APP/MapConfigProviderImpl.ts
218
+ import { MapConfig, MapConfigProvider, SimpleLayer } from "@open-pioneer/map";
219
+ import TileLayer from "ol/layer/Tile";
220
+ import OSM from "ol/source/OSM";
221
+
222
+ export class MapConfigProviderImpl implements MapConfigProvider {
223
+ async getMapConfig(): Promise<MapConfig> {
224
+ return {
225
+ layers: [
226
+ new SimpleLayer({
227
+ // minimal layer configuration
228
+ title: "OSM",
229
+ olLayer: new TileLayer({
230
+ source: new OSM()
231
+ })
232
+ }),
233
+ new SimpleLayer({
234
+ // layer configuration with optional properties
235
+ id: "abe0e3f8-0ba2-409c-b6b4-9d8429c732e3",
236
+ title: "OSM with UUID",
237
+ olLayer: new TileLayer({
238
+ source: new OSM()
239
+ }),
240
+ attributes: {
241
+ foo: "bar"
242
+ },
243
+ description: "additional description",
244
+ isBaseLayer: false,
245
+ visible: false
246
+ })
247
+ ]
248
+ };
249
+ }
250
+ }
251
+ ```
252
+
253
+ Based on the example above, you can set different properties using the layer API (such as setting visibility, update custom metadata (`attributes`)).
254
+
255
+ Example: How to set different properties.
256
+
257
+ ```js
258
+ import { useMapModel } from "@open-pioneer/map";
259
+
260
+ const { map } = useMapModel(mapId);
261
+ const layer = map.layers.getLayerById("abe0e3f8-0ba2-409c-b6b4-9d8429c732e3");
262
+
263
+ layer.setDescription("new description");
264
+ layer.setTitle("new title");
265
+ layer.setVisible(true);
266
+ layer.updateAttributes({
267
+ foo: "bar"
268
+ });
269
+ layer.deleteAttribute("foo");
270
+ ```
271
+
272
+ An optional property `healthCheck` allows to determine the availability status of a layer (e.g. map service down). The health check is performed asynchronous.
273
+
274
+ It is possible to provide
275
+
276
+ - either a URL to perform a test request check the returned HTTP status
277
+ - or a `HealthCheckFunction` performing a custom check and returning the state
278
+
279
+ **Important**: The availability of a layer is only checked once during initialization to reduce the load on server side. If a service becomes available again later, the application will need to be reloaded in order to update the availability status.
280
+
281
+ The availability status of a layer can be accessed with the property `loadState`. Its value depends on the result of the health check and the OpenLayers `Source` of the layer. If at least one of both checks returns the state `error`, the `loadState` will be set to `error`.
282
+
283
+ Example: Check of layer availability ("health check")
284
+
285
+ ```ts
286
+ // YOUR-APP/MapConfigProviderImpl.ts
287
+ import { MapConfig, MapConfigProvider, SimpleLayer } from "@open-pioneer/map";
288
+ import TileLayer from "ol/layer/Tile";
289
+ import OSM from "ol/source/OSM";
290
+
291
+ export class MapConfigProviderImpl implements MapConfigProvider {
292
+ async getMapConfig(): Promise<MapConfig> {
293
+ return {
294
+ layers: [
295
+ new SimpleLayer({
296
+ id: "1",
297
+ title: "Layer 1",
298
+ olLayer: new TileLayer({
299
+ source: new OSM()
300
+ }),
301
+ // check layer availability by requesting the provided URL
302
+ healthCheck:
303
+ "https://sgx.geodatenzentrum.de/wmts_topplus_open/1.0.0/WMTSCapabilities.xml",
304
+ isBaseLayer: false,
305
+ visible: true
306
+ }),
307
+ new SimpleLayer({
308
+ id: "2",
309
+ title: "Layer 2",
310
+ olLayer: new TileLayer({
311
+ source: new OSM()
312
+ }),
313
+ // check layer availability by providing a custom health check function
314
+ healthCheck: async () => {
315
+ function wait(milliseconds: number): Promise<void> {
316
+ return new Promise((resolve) => setTimeout(resolve, milliseconds));
317
+ }
318
+
319
+ await wait(3000);
320
+ return "error";
321
+ },
322
+ isBaseLayer: false,
323
+ visible: false
324
+ })
325
+ ]
326
+ };
327
+ }
328
+ }
329
+ ```
330
+
331
+ > NOTE: The visibility of base layers cannot be changed through the method `setVisible`.
332
+ > Call `activateBaseLayer` instead.
333
+
334
+ ##### OGC API Features
335
+
336
+ To create an OGC API Features layer, use the `ogc-features` package.
337
+ Details about the necessary steps are described in the package's [README](../ogc-features/README.md) file.
338
+
339
+ ###### Mapbox / MapLibre styles
340
+
341
+ To use layers of a Mapbox / MapLibre style document, use the class `MapboxVectorLayer` from the package `ol-mapbox-style` as in the following sample:
342
+
343
+ ```ts
344
+ // YOUR-APP/MapConfigProviderImpl.ts
345
+ import { MapboxVectorLayer } from "ol-mapbox-style";
346
+
347
+ export const MAP_ID = "main";
348
+
349
+ export class MapConfigProviderImpl implements MapConfigProvider {
350
+ mapId = MAP_ID;
351
+
352
+ async getMapConfig(): Promise<MapConfig> {
353
+ return {
354
+ projection: "EPSG:3857",
355
+ initialView: {
356
+ kind: "position",
357
+ center: {
358
+ x: 848890,
359
+ y: 6793350
360
+ },
361
+ zoom: 13
362
+ },
363
+ layers: [
364
+ new SimpleLayer({
365
+ title: "Abschnitte/Äste mit Unfällen (Mapbox Style)",
366
+ olLayer: new MapboxVectorLayer({
367
+ styleUrl:
368
+ "https://sgx.geodatenzentrum.de/gdz_basemapde_vektor/styles/bm_web_top.json"
369
+ })
370
+ })
371
+ ]
372
+ };
373
+ }
374
+ }
375
+ ```
376
+
377
+ Because of the changed license of Mapbox as of version 2.0, we recommend to override the implementation with the code of MapLibre (see the main package.json of this repository for a sample).
378
+
379
+ ##### OGC API Tiles
380
+
381
+ OpenLayers supports OGC API Tiles (vector tiles) by default (see [OpenLayers API](https://openlayers.org/en/latest/apidoc/module-ol_source_OGCVectorTile-OGCVectorTile.html)).
382
+
383
+ > IMPORTANT: The configured vector tile layer must have the same projection like the map. Otherwise OGC API Tiles cannot be displayed correctly in a map.
384
+
385
+ Example: How to configure a vector tile layer:
386
+
387
+ ```ts
388
+ // YOUR-APP/MapConfigProviderImpl.ts
389
+ export class MapConfigProviderImpl implements MapConfigProvider {
390
+ async getMapConfig(): Promise<MapConfig> {
391
+ return {
392
+ projection: "EPSG:3857",
393
+ initialView: {
394
+ kind: "position",
395
+ center: {
396
+ x: 848890,
397
+ y: 6793350
398
+ },
399
+ zoom: 13
400
+ },
401
+ layers: [
402
+ new SimpleLayer({
403
+ title: "Pendleratlas",
404
+ visible: true,
405
+ olLayer: new VectorTileLayer({
406
+ source: new VectorTileSource({
407
+ url: "https://pendleratlas.statistikportal.de/_vector_tiles/2022/vg250/{z}/{x}/{y}.pbf",
408
+ format: new MVT(),
409
+ projection: "EPSG:3857"
410
+ }),
411
+ style: new Style({
412
+ fill: new Fill({
413
+ color: "rgba(173, 209, 158, 0.6)"
414
+ }),
415
+ stroke: new Stroke({
416
+ color: "#2d7d9f",
417
+ width: 3
418
+ })
419
+ })
420
+ })
421
+ })
422
+ ]
423
+ };
424
+ }
425
+ }
426
+ ```
427
+
428
+ ##### OGC Web Map Tile Service (WMTS)
429
+
430
+ To create a layer configuration for a WMTS, use one of the following configuration approaches:
431
+
432
+ 1. Predefine options
433
+ 2. Request options from the services capabilities (see [OpenLayers API](https://openlayers.org/en/latest/apidoc/module-ol_source_WMTS.html#.optionsFromCapabilities))
434
+
435
+ Predefining the options results in faster startup of your application and prevents the startup process from being interrupted when a service is temporarily unavailable.
436
+ Requesting the options from the capabilities has the advantage that you do not have to track and adjust changes in the services' metadata and can integrate a service with less code.
437
+
438
+ Example: How to predefine all necessary options for a WMTS layer:
439
+
440
+ ```ts
441
+ // YOUR-APP/MapConfigProviderImpl.ts
442
+ export const MAP_ID = "main";
443
+
444
+ /**
445
+ * Register custom projection to the global proj4js definitions.
446
+ */
447
+ registerProjections({
448
+ "EPSG:31466":
449
+ "+proj=tmerc +lat_0=0 +lon_0=6 +k=1 +x_0=2500000 +y_0=0 +ellps=bessel +nadgrids=BETA2007.gsb +units=m +no_defs +type=crs"
450
+ });
451
+
452
+ export class MapConfigProviderImpl implements MapConfigProvider {
453
+ mapId = MAP_ID;
454
+
455
+ async getMapConfig(): Promise<MapConfig> {
456
+ return {
457
+ initialView: {
458
+ kind: "position",
459
+ center: { x: 404747, y: 5757920 },
460
+ zoom: 14
461
+ },
462
+ projection: "EPSG:31466",
463
+ layers: [
464
+ new SimpleLayer({
465
+ id: "topplus_open",
466
+ title: "TopPlus Open",
467
+ isBaseLayer: true,
468
+ visible: true,
469
+ layer: new TileLayer({
470
+ source: createWMTSSource("web")
471
+ })
472
+ })
473
+ ]
474
+ };
475
+ }
476
+ }
477
+
478
+ function createWMTSSource(layer: "web" | "web_grau" | "web_light") {
479
+ const topLeftCorner = [-3803165.98427299, 8805908.08284866];
480
+
481
+ /**
482
+ * Resolutions taken from AdV WMTS-Profil
483
+ * @see https://www.adv-online.de/AdV-Produkte/Standards-und-Produktblaetter/AdV-Profile/
484
+ */
485
+ const resolutions = [
486
+ 4891.96981025128, // AdV-Level 0 (1:17471320.7508974)
487
+ 2445.98490512564, // AdV-Level 1 (1:8735660.37544872)
488
+ 1222.99245256282, // AdV-Level 2 (1:4367830.18772436)
489
+ 611.49622628141, // AdV-Level 3 (1:2183915.09386218)
490
+ 305.748113140705, // AdV-Level 4 (1:1091957.54693109)
491
+ 152.874056570353, // AdV-Level 5 (1:545978.773465545)
492
+ 76.4370282851763, // AdV-Level 6 (1:272989,386732772)
493
+ 38.2185141425881, // AdV-Level 7 (1:136494,693366386)
494
+ 19.1092570712941, // AdV-Level 8 (1:68247,3466831931)
495
+ 9.55462853564703, // AdV-Level 9 (1:34123,6733415966)
496
+ 4.77731426782352, // AdV-Level 10 (1:17061,8366707983)
497
+ 2.38865713391176, // AdV-Level 11 (1:8530,91833539914)
498
+ 1.19432856695588, // AdV-Level 12 (1:4265,45916769957)
499
+ 0.59716428347794 // AdV-Level 13 (1:2132,72958384978)
500
+ ];
501
+
502
+ /**
503
+ * The length of matrixIds needs to match the length of the resolutions array
504
+ * @see https://openlayers.org/en/latest/apidoc/module-ol_tilegrid_WMTS-WMTSTileGrid.html
505
+ */
506
+ const matrixIds = new Array(resolutions.length);
507
+ for (let i = 0; i < resolutions.length; i++) {
508
+ matrixIds[i] = i;
509
+ }
510
+
511
+ return new WMTS({
512
+ url: `https://sgx.geodatenzentrum.de/wmts_topplus_open/tile/1.0.0/${layer}/{Style}/{TileMatrixSet}/{TileMatrix}/{TileRow}/{TileCol}.png`,
513
+ layer: "web_grau",
514
+ matrixSet: "EU_EPSG_25832_TOPPLUS",
515
+ format: "image/png",
516
+ projection: "EPSG:25832",
517
+ requestEncoding: "REST",
518
+ tileGrid: new WMTSTileGrid({
519
+ origin: topLeftCorner,
520
+ resolutions: resolutions,
521
+ matrixIds: matrixIds
522
+ }),
523
+ style: "default",
524
+ attributions: `Kartendarstellung und Präsentationsgraphiken: © Bundesamt für Kartographie und Geodäsie ${new Date().getFullYear()}, <a href="https://sg.geodatenzentrum.de/web_public/gdz/datenquellen/Datenquellen_TopPlusOpen.html" target="_blank">Datenquellen</a>`
525
+ });
526
+ }
527
+ ```
528
+
529
+ > Note: The WMTS configuration (for example `topLeftCorner` or `matrixSet`) can be different for each service.
530
+ > Please have a look into the WMTS capabilities.
531
+
532
+ Example: How to create the WMTS source from the services capabilities:
533
+
534
+ ```js
535
+ // YOUR-APP/SomeFile.ts
536
+
537
+ // Imports:
538
+ import { MapModel, registerProjections } from "@open-pioneer/map";
539
+ import WMTSCapabilities from "ol/format/WMTSCapabilities";
540
+ import { optionsFromCapabilities } from "ol/source/WMTS";
541
+
542
+ // Global setup: register UTM32 (only needed for this specific layer)
543
+ registerProjections({
544
+ "EPSG:31466":
545
+ "+proj=tmerc +lat_0=0 +lon_0=6 +k=1 +x_0=2500000 +y_0=0 +ellps=bessel +nadgrids=BETA2007.gsb +units=m +no_defs +type=crs"
546
+ });
547
+
548
+ // Later, for example in a service
549
+ const mapModel: MapModel = ... // retrieved via MapRegistry service
550
+ await mapModel.whenDisplayed();
551
+
552
+ const response = await httpService.fetch("https://sgx.geodatenzentrum.de/wmts_topplus_open/1.0.0/WMTSCapabilities.xml");
553
+ const responseText = await response.text();
554
+
555
+ const wmtsParser = new WMTSCapabilities();
556
+ const wmtsResult = wmtsParser.read(responseText);
557
+ const wmtsOptions = optionsFromCapabilities(wmtsResult, {
558
+ layer: "web_light",
559
+ matrixSet: "EU_EPSG_25832_TOPPLUS"
560
+ });
561
+
562
+ if (wmtsOptions) {
563
+ mapModel.layers.addLayer(new SimpleLayer({
564
+ id: "topplus_open_optionsFromCapabilities",
565
+ title: "TopPlus Open - created with optionsFromCapabilities()",
566
+ visible: false,
567
+ layer: new TileLayer({
568
+ source: new WMTS(wmtsOptions)
569
+ })
570
+ }));
571
+ }
572
+ ```
573
+
574
+ > Note: To avoid adding layers twice (or error messages), check against the layer id with `getLayerById()`.
575
+
576
+ ##### OGC Web Map Service (WMS)
577
+
578
+ To create a layer configuration for a WMS, use the following configuration approach:
579
+
580
+ Example: Create WMS layer configuration
581
+
582
+ ```ts
583
+ // YOUR-APP/MapConfigProviderImpl.ts
584
+ import { MapConfig, MapConfigProvider, WMSLayer } from "@open-pioneer/map";
585
+
586
+ export const MAP_ID = "main";
587
+
588
+ export class MapConfigProviderImpl implements MapConfigProvider {
589
+ mapId = MAP_ID;
590
+
591
+ async getMapConfig(): Promise<MapConfig> {
592
+ return {
593
+ initialView: {
594
+ kind: "position",
595
+ center: { x: 404747, y: 5757920 },
596
+ zoom: 14
597
+ },
598
+ projection: "EPSG:25832",
599
+ layers: [
600
+ new WMSLayer({
601
+ title: "Schulstandorte",
602
+ url: "https://www.wms.nrw.de/wms/wms_nw_inspire-schulen",
603
+
604
+ // Configure service (sub-) layers
605
+ sublayers: [
606
+ {
607
+ name: "US.education",
608
+ title: "Schulen"
609
+ }
610
+ ],
611
+
612
+ // Optional, additional options for the underlying ImageWMS source
613
+ sourceOptions: {
614
+ // Ratio 1 means image requests are the size of the map viewport
615
+ ratio: 1
616
+ }
617
+ })
618
+ ]
619
+ };
620
+ }
621
+ }
622
+ ```
623
+
624
+ ##### GroupLayer
625
+
626
+ A `GroupLayer` contains a list of layers (e.g. `SimpleLayer`, `WMSLayer` or nested `GroupLayer`).
627
+ The visibility of all layers within the group is controlled via the parent group layer(s).
628
+ The hierarchy of the layers, which results from the (nested) groups, is rendered accordingly in the table of contents.
629
+
630
+ Example: Create (nested) group layers
631
+
632
+ ```ts
633
+ // Create group layer with a nested sub group
634
+ const group = new GroupLayer({
635
+ id: "group",
636
+ title: "a group layer",
637
+ layers: [
638
+ new SimpleLayer({
639
+ id: "member",
640
+ title: "group member",
641
+ olLayer: olLayer1
642
+ }),
643
+ new GroupLayer({
644
+ id: "subgroup",
645
+ title: "a nested group layer",
646
+ layers: [
647
+ new SimpleLayer({
648
+ id: "submember",
649
+ title: "subgroup member",
650
+ olLayer: olLayer2
651
+ })
652
+ ]
653
+ })
654
+ ]
655
+ });
656
+
657
+ const childLayers = group.layers; // Access child layers
658
+ ```
659
+
660
+ > Limitations:
661
+ >
662
+ > - Do not add or remove layers directly to or from the underlying OpenLayers layer group (`group.olLayer`)! Changes are not synchronized with the `GroupLayer` instance.
663
+ > - Currently, it is not possible to manipulate (add or remove) the child layers of a `GroupLayer` during runtime.
664
+
665
+ #### Register additional projections
666
+
667
+ The map supports only the following projections by default: `EPSG:4326`, `EPSG:3857`, `EPSG:25832` and `EPSG:25833`.
668
+ To register additional projections to use them for the map, use the `registerProjections` function.
669
+
670
+ Example: How to register an additional projection to the global [proj4js](https://github.com/proj4js/proj4js) definition set by name (such as `"EPSG:4326"`) and projection definition (string defining the projection or an existing proj4 definition object):
671
+
672
+ ```ts
673
+ import { registerProjections } from "@open-pioneer/map";
674
+
675
+ registerProjections({
676
+ "EPSG:31466":
677
+ "+proj=tmerc +lat_0=0 +lon_0=6 +k=1 +x_0=2500000 +y_0=0 +ellps=bessel +nadgrids=BETA2007.gsb +units=m +no_defs +type=crs"
678
+ // ... more projections
679
+ });
680
+ ```
681
+
682
+ Projection definitions can be accessed by the [epsg.io](https://epsg.io/) website or by searching the global [proj4js](https://github.com/proj4js/proj4js) definition set with a valid name.
683
+
684
+ Example: How to use the registered projection:
685
+
686
+ ```ts
687
+ import { getProjection } from "@open-pioneer/map";
688
+
689
+ // Returns a raw proj4 projection definition (or undefined)
690
+ const proj = getProjection("EPSG:3035");
691
+
692
+ // proj can be used as "projection" in "getMapConfig" of MapConfigProvider implementation
693
+ ```
694
+
695
+ ### Using the map model
696
+
697
+ This package allows interacting with maps and their layers through multiple interfaces and classes.
698
+
699
+ The most important API items are as follows:
700
+
701
+ - The `MapRegistry` service (inject via `"map.MapRegistry"`).
702
+ This service is used to obtain a reference to the `MapModel` via `registry.getMapModel(mapId)`.
703
+
704
+ > NOTE: From inside a React component you can also use the hook `useMapModel(mapId)`.
705
+
706
+ - The `MapModel` represents a map in an application.
707
+ Through the `MapModel` one can obtain the map's base layers, operational layers and so on.
708
+ The `MapModel` also provides access to the raw OpenLayers `olMap` for advanced use cases.
709
+
710
+ > NOTE: The `olMap` is manipulated by the `MapModel` to implement its functionality (for example, to add or remove layer instances). When using the `olMap` directly, treat it carefully and as a shared resource.
711
+
712
+ - The `Layer` interface and its various implementations.
713
+ This interface is used to make common properties and methods available (such as `.title`, or `.setVisible`).
714
+ Layers may also have `.sublayers`, which support the same basic properties as other layer types.
715
+
716
+ As is the case in `MapModel`, one can retrieve the raw OpenLayers `olLayer` from a layer instance (the same restrictions apply, see above).
717
+
718
+ As a general rule of thumb, one should always prefer to use properties or methods provided by this package (if available) instead of manipulating the raw OpenLayers instances.
719
+ Manipulating raw instances directly may lead to unexpected results.
720
+ For example, other application components may not react to raw property changes correctly because they expect an "official" property to be changed instead.
721
+
722
+ This point is especially important for the map model's central features:
723
+
724
+ - Map composition (access and configuration of layers, base layers, removing layers)
725
+ - Layer visibility
726
+ - Custom layer metadata (`attributes`)
727
+
728
+ In those cases, the properties or methods provided by this package should always be used:
729
+
730
+ - `map.layers.addLayer(layer)` and `map.layers.removeLayerById(layerId)` to add or remove layers
731
+ - `map.layers.getAllLayers()`, `map.layers.getBaseLayers()`, `map.layers.getOperationalLayers()` etc. to access (top-level) layers
732
+ - `layer.setVisible(visible)` and `map.layers.activateBaseLayer(layerId)` to control visibility
733
+ - `layer.updateAttributes()` and `layer.deleteAttributes()` to change a layer's custom attributes
734
+
735
+ #### Layer classes
736
+
737
+ This package currently provides five layer implementations: `SimpleLayer`, `WMSLayer`, `WMTSLayer`, `GroupLayer` and `WMSSublayer`.
738
+
739
+ The following diagram shows the inheritance structure of the corresponding layer types. The diagram is only intended to show the hierarchy of the layer types; for details on the properties and methods of the layer types, refer to the respective API documentation.
740
+
741
+ ```mermaid
742
+ ---
743
+ config:
744
+ class:
745
+ hideEmptyMembersBox: true
746
+ ---
747
+ classDiagram
748
+ class AnyLayerBaseType {
749
+ type: string
750
+ }
751
+ <<abstract>> AnyLayerBaseType
752
+
753
+ class LayerBaseType {
754
+ type: string
755
+ }
756
+ <<abstract>> LayerBaseType
757
+
758
+ class SimpleLayer {
759
+ type: "simple"
760
+ constructor(config: SimpleLayerConfig)
761
+ }
762
+
763
+ class WMSLayer {
764
+ type: "wms"
765
+ constructor(config: WMSLayerConfig)
766
+ }
767
+
768
+ class WMTSLayer {
769
+ type: "wmts"
770
+ constructor(config: WMTSLayerConfig)
771
+ }
772
+
773
+ class GroupLayer {
774
+ type: "group"
775
+ constructor(config: GroupLayerConfig)
776
+ }
777
+
778
+ class Layer
779
+ <<union>> Layer
780
+
781
+ class Sublayer
782
+ <<union>> Sublayer
783
+
784
+ class SublayerBaseType {
785
+ type: string
786
+ }
787
+ <<abstract>> SublayerBaseType
788
+
789
+ class WMSSublayer {
790
+ type: "wms-sublayer"
791
+ constructor(config: WMSSublayerConfig)
792
+ }
793
+
794
+ AnyLayerBaseType <|-- LayerBaseType
795
+ AnyLayerBaseType <|-- SublayerBaseType
796
+
797
+ LayerBaseType <|-- SimpleLayer
798
+ LayerBaseType <|-- WMSLayer
799
+ LayerBaseType <|-- WMTSLayer
800
+ LayerBaseType <|-- GroupLayer
801
+
802
+ SublayerBaseType <|-- WMSSublayer
803
+
804
+ SimpleLayer .. Layer
805
+ WMSLayer .. Layer
806
+ WMTSLayer .. Layer
807
+ GroupLayer .. Layer
808
+
809
+ WMSSublayer .. Sublayer
810
+ ```
811
+
812
+ #### Using the map model and layers in services
813
+
814
+ Example: Center map to given coordinates using the map model and set layer visibility using the layer instance.
815
+
816
+ ```ts
817
+ import { ServiceOptions } from "@open-pioneer/runtime";
818
+ import { MAP_ID } from "./MapConfigProviderImpl";
819
+ import type { MapRegistry } from "@open-pioneer/map";
820
+
821
+ interface References {
822
+ mapRegistry: MapRegistry;
823
+ }
824
+
825
+ export class TestService {
826
+ private registry: MapRegistry;
827
+
828
+ constructor(options: ServiceOptions<References>) {
829
+ this.registry = options.references.mapRegistry;
830
+ }
831
+
832
+ async centerBerlin() {
833
+ const model = await this.registry.getMapModel(MAP_ID);
834
+ model?.olMap?.getView().fit([1489200, 6894026, 1489200, 6894026], { maxZoom: 13 });
835
+ }
836
+
837
+ async setLayerVisible() {
838
+ const model = await this.registry.getMapModel(MAP_ID);
839
+ const layer = model?.layers.getLayerById("abe0e3f8-0ba2-409c-b6b4-9d8429c732e3");
840
+ layer?.setVisible(true);
841
+ }
842
+ }
843
+ ```
844
+
845
+ #### Using the map model in React components
846
+
847
+ To access the map model instance, use the React hook `useMapModel`.
848
+
849
+ Example: Center map to given coordinates using the map model.
850
+
851
+ ```js
852
+ import { useMapModel } from "@open-pioneer/map";
853
+ import { MAP_ID } from "./MapConfigProviderImpl";
854
+
855
+ export function AppUI() {
856
+ // mapState.map may be undefined initially, if the map is still configuring.
857
+ // the object may may also be in an "error" state.
858
+ const mapState = useMapModel(MAP_ID);
859
+
860
+ const centerBerlin = () => {
861
+ const olMap = mapState.map?.olMap;
862
+ if (olMap) {
863
+ olMap?.getView().fit([1489200, 6894026, 1489200, 6894026], { maxZoom: 13 });
864
+ }
865
+ };
866
+ }
867
+ ```
868
+
869
+ ## License
870
+
871
+ Apache-2.0 (see `LICENSE` file)