@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.
- package/CHANGELOG.md +354 -0
- package/LICENSE +202 -0
- package/MapRegistryImpl.d.ts +17 -0
- package/MapRegistryImpl.js +91 -0
- package/MapRegistryImpl.js.map +1 -0
- package/README.md +871 -0
- package/_virtual/_virtual-pioneer-module_react-hooks.js +7 -0
- package/_virtual/_virtual-pioneer-module_react-hooks.js.map +1 -0
- package/api/BaseFeature.d.ts +31 -0
- package/api/MapConfig.d.ts +111 -0
- package/api/MapModel.d.ts +229 -0
- package/api/MapRegistry.d.ts +48 -0
- package/api/index.d.ts +15 -0
- package/api/layers/GroupLayer.d.ts +50 -0
- package/api/layers/GroupLayer.js +6 -0
- package/api/layers/GroupLayer.js.map +1 -0
- package/api/layers/SimpleLayer.d.ts +27 -0
- package/api/layers/SimpleLayer.js +6 -0
- package/api/layers/SimpleLayer.js.map +1 -0
- package/api/layers/WMSLayer.d.ts +57 -0
- package/api/layers/WMSLayer.js +6 -0
- package/api/layers/WMSLayer.js.map +1 -0
- package/api/layers/WMTSLayer.d.ts +33 -0
- package/api/layers/WMTSLayer.js +6 -0
- package/api/layers/WMTSLayer.js.map +1 -0
- package/api/layers/base.d.ts +242 -0
- package/api/layers/base.js +9 -0
- package/api/layers/base.js.map +1 -0
- package/api/layers/index.d.ts +5 -0
- package/api/shared.d.ts +10 -0
- package/assets/images/mapMarker.png +0 -0
- package/index.d.ts +1 -0
- package/index.js +15 -0
- package/index.js.map +1 -0
- package/internalTestSupport.d.ts +8 -0
- package/internalTestSupport.js +2 -0
- package/internalTestSupport.js.map +1 -0
- package/layers/BkgTopPlusOpen.d.ts +21 -0
- package/layers/BkgTopPlusOpen.js +61 -0
- package/layers/BkgTopPlusOpen.js.map +1 -0
- package/model/AbstractLayer.d.ts +25 -0
- package/model/AbstractLayer.js +186 -0
- package/model/AbstractLayer.js.map +1 -0
- package/model/AbstractLayerBase.d.ts +54 -0
- package/model/AbstractLayerBase.js +119 -0
- package/model/AbstractLayerBase.js.map +1 -0
- package/model/Highlights.d.ts +42 -0
- package/model/Highlights.js +272 -0
- package/model/Highlights.js.map +1 -0
- package/model/LayerCollectionImpl.d.ts +27 -0
- package/model/LayerCollectionImpl.js +228 -0
- package/model/LayerCollectionImpl.js.map +1 -0
- package/model/MapModelImpl.d.ts +46 -0
- package/model/MapModelImpl.js +271 -0
- package/model/MapModelImpl.js.map +1 -0
- package/model/SublayersCollectionImpl.d.ts +18 -0
- package/model/SublayersCollectionImpl.js +31 -0
- package/model/SublayersCollectionImpl.js.map +1 -0
- package/model/createMapModel.d.ts +4 -0
- package/model/createMapModel.js +157 -0
- package/model/createMapModel.js.map +1 -0
- package/model/layers/GroupLayerImpl.d.ts +39 -0
- package/model/layers/GroupLayerImpl.js +88 -0
- package/model/layers/GroupLayerImpl.js.map +1 -0
- package/model/layers/SimpleLayerImpl.d.ts +13 -0
- package/model/layers/SimpleLayerImpl.js +19 -0
- package/model/layers/SimpleLayerImpl.js.map +1 -0
- package/model/layers/WMSLayerImpl.d.ts +41 -0
- package/model/layers/WMSLayerImpl.js +297 -0
- package/model/layers/WMSLayerImpl.js.map +1 -0
- package/model/layers/WMTSLayerImpl.d.ts +17 -0
- package/model/layers/WMTSLayerImpl.js +156 -0
- package/model/layers/WMTSLayerImpl.js.map +1 -0
- package/package.json +86 -0
- package/projections.d.ts +27 -0
- package/projections.js +15 -0
- package/projections.js.map +1 -0
- package/services.d.ts +1 -0
- package/services.js +2 -0
- package/services.js.map +1 -0
- package/ui/CssProps.d.ts +9 -0
- package/ui/CssProps.js +13 -0
- package/ui/CssProps.js.map +1 -0
- package/ui/DefaultMapProvider.d.ts +39 -0
- package/ui/DefaultMapProvider.js +24 -0
- package/ui/DefaultMapProvider.js.map +1 -0
- package/ui/MapAnchor.d.ts +36 -0
- package/ui/MapAnchor.js +28 -0
- package/ui/MapAnchor.js.map +1 -0
- package/ui/MapContainer.d.ts +50 -0
- package/ui/MapContainer.js +191 -0
- package/ui/MapContainer.js.map +1 -0
- package/ui/MapContainerContext.d.ts +7 -0
- package/ui/MapContainerContext.js +17 -0
- package/ui/MapContainerContext.js.map +1 -0
- package/ui/computeMapAnchorStyles.d.ts +3 -0
- package/ui/computeMapAnchorStyles.js +51 -0
- package/ui/computeMapAnchorStyles.js.map +1 -0
- package/ui/hooks.d.ts +34 -0
- package/ui/hooks.js +73 -0
- package/ui/hooks.js.map +1 -0
- package/ui/styles.css +10 -0
- package/ui/styles.css.map +1 -0
- package/ui/useMapModel.d.ts +58 -0
- package/ui/useMapModel.js +59 -0
- package/ui/useMapModel.js.map +1 -0
- package/util/capabilities-utils.d.ts +2 -0
- package/util/capabilities-utils.js +11 -0
- package/util/capabilities-utils.js.map +1 -0
- package/util/geometry-utils.d.ts +7 -0
- package/util/geometry-utils.js +25 -0
- package/util/geometry-utils.js.map +1 -0
- package/util/ol-test-support.d.ts +2 -0
- package/util/ol-test-support.js +24 -0
- package/util/ol-test-support.js.map +1 -0
package/ui/hooks.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { unByKey } from 'ol/Observable.js';
|
|
2
|
+
import { getPointResolution } from 'ol/proj.js';
|
|
3
|
+
import { useMemo, useCallback, useSyncExternalStore } from 'react';
|
|
4
|
+
|
|
5
|
+
const DEFAULT_DPI = 25.4 / 0.28;
|
|
6
|
+
const INCHES_PER_METRE = 39.37;
|
|
7
|
+
function useView(map) {
|
|
8
|
+
return useOlProperty(map, getView, watchView);
|
|
9
|
+
}
|
|
10
|
+
function getView(map) {
|
|
11
|
+
return map.getView();
|
|
12
|
+
}
|
|
13
|
+
function watchView(map, cb) {
|
|
14
|
+
return map.on("change:view", cb);
|
|
15
|
+
}
|
|
16
|
+
function useProjection(map) {
|
|
17
|
+
const view = useView(map);
|
|
18
|
+
return view?.getProjection();
|
|
19
|
+
}
|
|
20
|
+
function useResolution(map) {
|
|
21
|
+
const view = useView(map);
|
|
22
|
+
return useOlProperty(view, getResolution, watchResolution);
|
|
23
|
+
}
|
|
24
|
+
function getResolution(view) {
|
|
25
|
+
return view.getResolution();
|
|
26
|
+
}
|
|
27
|
+
function watchResolution(view, cb) {
|
|
28
|
+
return view.on("change:resolution", cb);
|
|
29
|
+
}
|
|
30
|
+
function useCenter(map) {
|
|
31
|
+
const view = useView(map);
|
|
32
|
+
return useOlProperty(view, getCenter, watchCenter);
|
|
33
|
+
}
|
|
34
|
+
function getCenter(view) {
|
|
35
|
+
return view.getCenter();
|
|
36
|
+
}
|
|
37
|
+
function watchCenter(view, cb) {
|
|
38
|
+
return view.on("change:center", cb);
|
|
39
|
+
}
|
|
40
|
+
function useScale(map) {
|
|
41
|
+
const center = useCenter(map);
|
|
42
|
+
const resolution = useResolution(map);
|
|
43
|
+
const projection = useProjection(map);
|
|
44
|
+
const scale = useMemo(() => {
|
|
45
|
+
if (projection == null || resolution == null || center == null) {
|
|
46
|
+
return void 0;
|
|
47
|
+
}
|
|
48
|
+
const pointResolution = getPointResolution(projection, resolution, center);
|
|
49
|
+
const scale2 = Math.round(pointResolution * INCHES_PER_METRE * DEFAULT_DPI);
|
|
50
|
+
return scale2;
|
|
51
|
+
}, [projection, resolution, center]);
|
|
52
|
+
return scale;
|
|
53
|
+
}
|
|
54
|
+
function useOlProperty(object, accessor, watcher) {
|
|
55
|
+
const getSnapshot = useCallback(
|
|
56
|
+
() => object ? accessor(object) : void 0,
|
|
57
|
+
[object, accessor]
|
|
58
|
+
);
|
|
59
|
+
const subscribe = useCallback(
|
|
60
|
+
(cb) => {
|
|
61
|
+
if (!object) {
|
|
62
|
+
return () => void 0;
|
|
63
|
+
}
|
|
64
|
+
const key = watcher(object, cb);
|
|
65
|
+
return () => unByKey(key);
|
|
66
|
+
},
|
|
67
|
+
[object, watcher]
|
|
68
|
+
);
|
|
69
|
+
return useSyncExternalStore(subscribe, getSnapshot);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export { useCenter, useProjection, useResolution, useScale, useView };
|
|
73
|
+
//# sourceMappingURL=hooks.js.map
|
package/ui/hooks.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks.js","sources":["hooks.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport OlMap from \"ol/Map\";\nimport OlView from \"ol/View\";\nimport { unByKey } from \"ol/Observable\";\nimport { Projection, getPointResolution } from \"ol/proj\";\nimport { Coordinate } from \"ol/coordinate\";\nimport { EventsKey } from \"ol/events\";\nimport { useCallback, useMemo, useSyncExternalStore } from \"react\";\n\n/**\n * From Web Map Server Implementation Specification -> 7.2.4.6.9 Scale denominators\n *\n * For the purposes of this International Standard, the common pixel size is defined to be 0,28 mm × 0,28 mm.\n * Because arbitrary clients can request maps from a server, the true pixel size of the final rendering device is\n * unknown to the server.\n */\nconst DEFAULT_DPI = 25.4 / 0.28;\nconst INCHES_PER_METRE = 39.37;\n\n/**\n * Returns the current view of the given map.\n *\n * @deprecated Use `mapModel.olView` instead.\n */\nexport function useView(map: OlMap | undefined): OlView | undefined {\n return useOlProperty(map, getView, watchView);\n}\n\nfunction getView(map: OlMap) {\n return map.getView();\n}\n\nfunction watchView(map: OlMap, cb: Callback) {\n return map.on(\"change:view\", cb);\n}\n\n/**\n * Returns the current projection of the map.\n *\n * @deprecated Use `mapModel.projection` instead.\n */\nexport function useProjection(map: OlMap | undefined): Projection | undefined {\n const view = useView(map);\n return view?.getProjection();\n}\n\n/**\n * Returns the current resolution of the map.\n *\n * @deprecated Use `mapModel.resolution` instead.\n */\nexport function useResolution(map: OlMap | undefined): number | undefined {\n const view = useView(map);\n return useOlProperty(view, getResolution, watchResolution);\n}\n\nfunction getResolution(view: OlView): number | undefined {\n return view.getResolution();\n}\n\nfunction watchResolution(view: OlView, cb: Callback) {\n return view.on(\"change:resolution\", cb);\n}\n\n/**\n * Returns the current center coordinates of the map.\n *\n * @deprecated Use `mapModel.center` instead.\n */\nexport function useCenter(map: OlMap | undefined): Coordinate | undefined {\n const view = useView(map);\n return useOlProperty(view, getCenter, watchCenter);\n}\n\nfunction getCenter(view: OlView): Coordinate | undefined {\n return view.getCenter();\n}\n\nfunction watchCenter(view: OlView, cb: Callback) {\n return view.on(\"change:center\", cb);\n}\n\n/**\n * Returns the current scale of the map.\n *\n * @deprecated Use `mapModel.scale` instead.\n */\nexport function useScale(map: OlMap | undefined): number | undefined {\n const center = useCenter(map);\n const resolution = useResolution(map);\n const projection = useProjection(map);\n const scale = useMemo(() => {\n if (projection == null || resolution == null || center == null) {\n return undefined;\n }\n\n /**\n * Returns the appropriate scale for the given resolution and units, see OpenLayers function getScaleForResolution()\n * https://github.com/openlayers/openlayers/blob/7fa9df03431e9e1bc517e6c414565d9f848a3132/src/ol/control/ScaleLine.js#L454C3-L454C24\n */\n const pointResolution = getPointResolution(projection, resolution, center);\n const scale = Math.round(pointResolution * INCHES_PER_METRE * DEFAULT_DPI);\n return scale;\n }, [projection, resolution, center]);\n return scale;\n}\n\ntype Callback = () => void;\n\n/**\n * Returns the value of an observable ol property.\n *\n * Make sure to keep `accessor` and `watcher` stable to reduce re-subscriptions:\n * either use global functions or wrap the functions into `useCallback`.\n */\nfunction useOlProperty<T, R>(\n object: T | undefined,\n accessor: (object: T) => R,\n watcher: (object: T, cb: Callback) => EventsKey\n): R | undefined {\n const getSnapshot = useCallback(\n () => (object ? accessor(object) : undefined),\n [object, accessor]\n );\n const subscribe = useCallback(\n (cb: Callback) => {\n if (!object) {\n return () => undefined;\n }\n\n const key = watcher(object, cb);\n return () => unByKey(key);\n },\n [object, watcher]\n );\n return useSyncExternalStore(subscribe, getSnapshot);\n}\n"],"names":["scale"],"mappings":";;;;AAiBA,MAAM,cAAc,IAAO,GAAA,IAAA,CAAA;AAC3B,MAAM,gBAAmB,GAAA,KAAA,CAAA;AAOlB,SAAS,QAAQ,GAA4C,EAAA;AAChE,EAAO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GACpB,CAAA;AACA,EAAO,OAAA,oBAAA,CAAqB,WAAW,WAAW,CAAA,CAAA;AACtD;;;;"}
|
package/ui/styles.css
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["styles.css"],"names":[],"mappings":"AAAA,mBAAmB;;AAEnB,qDAAqD;;AACrD;IACI,iCAAiC;IACjC,+BAA+B;AACnC","file":"styles.css","sourcesContent":["@import \"ol/ol.css\";\n\n/* Move attribution according to map view's padding */\n.map-container .ol-viewport .ol-attribution {\n bottom: var(--map-padding-bottom);\n right: var(--map-padding-right);\n}\n"]}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { MapModel } from "../api";
|
|
2
|
+
/** Return value of {@link useMapModel}. */
|
|
3
|
+
export type UseMapModelResult = UseMapModelLoading | UseMapModelResolved | UseMapModelRejected;
|
|
4
|
+
export interface UseMapModelLoading {
|
|
5
|
+
kind: "loading";
|
|
6
|
+
map?: undefined;
|
|
7
|
+
error?: undefined;
|
|
8
|
+
}
|
|
9
|
+
export interface UseMapModelResolved {
|
|
10
|
+
kind: "resolved";
|
|
11
|
+
map: MapModel;
|
|
12
|
+
error?: undefined;
|
|
13
|
+
}
|
|
14
|
+
export interface UseMapModelRejected {
|
|
15
|
+
kind: "rejected";
|
|
16
|
+
map?: undefined;
|
|
17
|
+
error: Error;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Options that specify which map to use. See {@link useMapModel}.
|
|
21
|
+
*
|
|
22
|
+
* When not setting any of these properties on a component, the default map (from the `DefaultMapProvider`) will be used.
|
|
23
|
+
* If that is not available either, an error will be thrown.
|
|
24
|
+
*/
|
|
25
|
+
export interface MapModelProps {
|
|
26
|
+
/**
|
|
27
|
+
* The id of the map.
|
|
28
|
+
* The map will be looked up in the MapRegistry service.
|
|
29
|
+
*/
|
|
30
|
+
mapId?: string | undefined;
|
|
31
|
+
/**
|
|
32
|
+
* The direct map model reference to use.
|
|
33
|
+
* This property can be used as an alternative to the {@link mapId}.
|
|
34
|
+
*/
|
|
35
|
+
map?: MapModel | undefined;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* React hook that looks up the map with the given id in the `map.MapRegistry` service.
|
|
39
|
+
*
|
|
40
|
+
* Returns an object representing the progress, which will eventually represent either
|
|
41
|
+
* the map model value or an initialization error.
|
|
42
|
+
*
|
|
43
|
+
* The map model cannot be returned directly because it may not have completed its initialization yet.
|
|
44
|
+
*/
|
|
45
|
+
export declare function useMapModel(mapId: string): UseMapModelResult;
|
|
46
|
+
/**
|
|
47
|
+
* React hook that resolves a map model specified by the given `props` (see {@link MapModelProps}).
|
|
48
|
+
*
|
|
49
|
+
* Returns an object representing the progress, which will eventually represent either
|
|
50
|
+
* the map model value or an initialization error.
|
|
51
|
+
*
|
|
52
|
+
* The map model cannot be returned directly because it may not have completed its initialization yet.
|
|
53
|
+
*/
|
|
54
|
+
export declare function useMapModel(props: MapModelProps): UseMapModelResult;
|
|
55
|
+
/**
|
|
56
|
+
* React hook that returns the default map model (if available, see {@link DefaultMapProvider}).
|
|
57
|
+
*/
|
|
58
|
+
export declare function useMapModel(): UseMapModelResult;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { useService } from '../_virtual/_virtual-pioneer-module_react-hooks.js';
|
|
2
|
+
import { useMemo } from 'react';
|
|
3
|
+
import { useAsync } from 'react-use';
|
|
4
|
+
import { MapModelImpl } from '../model/MapModelImpl.js';
|
|
5
|
+
import { useDefaultMapProps } from './DefaultMapProvider.js';
|
|
6
|
+
|
|
7
|
+
function useMapModel(props) {
|
|
8
|
+
const resolvedMapArg = useResolvedMapArg(props);
|
|
9
|
+
const mapRegistry = useService("map.MapRegistry");
|
|
10
|
+
const state = useAsync(async () => {
|
|
11
|
+
if (typeof resolvedMapArg === "string") {
|
|
12
|
+
return await mapRegistry.expectMapModel(resolvedMapArg);
|
|
13
|
+
}
|
|
14
|
+
return Promise.resolve(resolvedMapArg);
|
|
15
|
+
}, [mapRegistry, resolvedMapArg]);
|
|
16
|
+
const result = useMemo(() => {
|
|
17
|
+
if (state.loading) {
|
|
18
|
+
return { kind: "loading" };
|
|
19
|
+
}
|
|
20
|
+
if (state.error) {
|
|
21
|
+
return { kind: "rejected", error: state.error };
|
|
22
|
+
}
|
|
23
|
+
return { kind: "resolved", map: state.value };
|
|
24
|
+
}, [state]);
|
|
25
|
+
return result;
|
|
26
|
+
}
|
|
27
|
+
function useResolvedMapArg(props) {
|
|
28
|
+
if (typeof props === "object" && props.mapId != null && props.map != null) {
|
|
29
|
+
throw new Error(`Cannot specify both 'mapId' and 'map' in useMapModel at the same time.`);
|
|
30
|
+
}
|
|
31
|
+
if (props instanceof MapModelImpl) {
|
|
32
|
+
throw new Error(
|
|
33
|
+
`Map model instances cannot be passed directly to 'useMapModel' (see TypeScript signature).`
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
const localProps = useMemo(() => {
|
|
37
|
+
if (props == null) {
|
|
38
|
+
return {};
|
|
39
|
+
}
|
|
40
|
+
if (typeof props === "string") {
|
|
41
|
+
return { mapId: props };
|
|
42
|
+
}
|
|
43
|
+
return { mapId: props.mapId, map: props.map };
|
|
44
|
+
}, [...typeof props === "string" || props == null ? [props] : [props.mapId, props.map]]);
|
|
45
|
+
const defaultProps = useDefaultMapProps();
|
|
46
|
+
const resolvedMapArg = resolveMap(localProps) ?? resolveMap(defaultProps);
|
|
47
|
+
if (resolvedMapArg == null) {
|
|
48
|
+
throw new Error(
|
|
49
|
+
`No map specified. You must either specify the map (or its id) via a DefaultMapProvider parent or configure it explicitly.`
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
return resolvedMapArg;
|
|
53
|
+
}
|
|
54
|
+
function resolveMap(props) {
|
|
55
|
+
return props?.map ?? props?.mapId;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export { useMapModel };
|
|
59
|
+
//# sourceMappingURL=useMapModel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useMapModel.js","sources":["useMapModel.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { useService } from \"open-pioneer:react-hooks\";\nimport { useMemo } from \"react\";\nimport { useAsync } from \"react-use\";\nimport { MapModel, MapRegistry } from \"../api\";\nimport { MapModelImpl } from \"../model/MapModelImpl\";\n// eslint-disable-next-line unused-imports/no-unused-imports\nimport { DefaultMapProvider, useDefaultMapProps } from \"./DefaultMapProvider\";\n\n/** Return value of {@link useMapModel}. */\nexport type UseMapModelResult = UseMapModelLoading | UseMapModelResolved | UseMapModelRejected;\n\nexport interface UseMapModelLoading {\n kind: \"loading\";\n map?: undefined;\n error?: undefined;\n}\n\nexport interface UseMapModelResolved {\n kind: \"resolved\";\n map: MapModel;\n error?: undefined;\n}\n\nexport interface UseMapModelRejected {\n kind: \"rejected\";\n map?: undefined;\n error: Error;\n}\n\n/**\n * Options that specify which map to use. See {@link useMapModel}.\n *\n * When not setting any of these properties on a component, the default map (from the `DefaultMapProvider`) will be used.\n * If that is not available either, an error will be thrown.\n */\nexport interface MapModelProps {\n /**\n * The id of the map.\n * The map will be looked up in the MapRegistry service.\n */\n mapId?: string | undefined;\n\n /**\n * The direct map model reference to use.\n * This property can be used as an alternative to the {@link mapId}.\n */\n map?: MapModel | undefined;\n}\n\n/**\n * React hook that looks up the map with the given id in the `map.MapRegistry` service.\n *\n * Returns an object representing the progress, which will eventually represent either\n * the map model value or an initialization error.\n *\n * The map model cannot be returned directly because it may not have completed its initialization yet.\n */\nexport function useMapModel(mapId: string): UseMapModelResult;\n\n/**\n * React hook that resolves a map model specified by the given `props` (see {@link MapModelProps}).\n *\n * Returns an object representing the progress, which will eventually represent either\n * the map model value or an initialization error.\n *\n * The map model cannot be returned directly because it may not have completed its initialization yet.\n */\nexport function useMapModel(props: MapModelProps): UseMapModelResult;\n\n/**\n * React hook that returns the default map model (if available, see {@link DefaultMapProvider}).\n */\nexport function useMapModel(): UseMapModelResult;\nexport function useMapModel(props?: undefined | string | MapModelProps): UseMapModelResult {\n const resolvedMapArg = useResolvedMapArg(props);\n const mapRegistry = useService<MapRegistry>(\"map.MapRegistry\");\n const state = useAsync(async () => {\n if (typeof resolvedMapArg === \"string\") {\n return await mapRegistry.expectMapModel(resolvedMapArg);\n }\n return Promise.resolve(resolvedMapArg);\n }, [mapRegistry, resolvedMapArg]);\n const result = useMemo((): UseMapModelResult => {\n if (state.loading) {\n return { kind: \"loading\" };\n }\n if (state.error) {\n return { kind: \"rejected\", error: state.error };\n }\n return { kind: \"resolved\", map: state.value! };\n }, [state]);\n return result;\n}\n\n/**\n * Resolves the map model (or its id) from the given props and the default map props.\n */\nfunction useResolvedMapArg(props?: undefined | string | MapModelProps): MapModel | string {\n if (typeof props === \"object\" && props.mapId != null && props.map != null) {\n throw new Error(`Cannot specify both 'mapId' and 'map' in useMapModel at the same time.`);\n }\n if (props instanceof MapModelImpl) {\n // This cannot happen in valid typescript code, but it might be a common mistake.\n throw new Error(\n `Map model instances cannot be passed directly to 'useMapModel' (see TypeScript signature).`\n );\n }\n const localProps = useMemo((): MapModelProps => {\n // Normalize local props for compatibility with old string overload.\n if (props == null) {\n return {};\n }\n if (typeof props === \"string\") {\n return { mapId: props };\n }\n return { mapId: props.mapId, map: props.map };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [...(typeof props === \"string\" || props == null ? [props] : [props.mapId, props.map])]);\n const defaultProps = useDefaultMapProps();\n\n const resolvedMapArg = resolveMap(localProps) ?? resolveMap(defaultProps);\n if (resolvedMapArg == null) {\n throw new Error(\n `No map specified. ` +\n `You must either specify the map (or its id) via a DefaultMapProvider parent or configure it explicitly.`\n );\n }\n return resolvedMapArg;\n}\n\nfunction resolveMap(props?: MapModelProps): MapModel | string | undefined {\n return props?.map ?? props?.mapId;\n}\n"],"names":[],"mappings":";;;;;;AA2EO,SAAS,YAAY,KAA+D,EAAA;AACvF,EAAM,MAAA,cAA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,IAAM,EAAA;AACf,MAAA,OAAO,EAAC,CAAA;AAAA,KACZ;AACA,IAAI,IAAA,OAAO,UAAU,QAAU,EAAA;AAC3B,MAAO,OAAA,EAAE,OAAO,KAAM,EAAA,CAAA;AAAA,KAC1B;AACA,IAAA,OAAO,EAAE,KAAO,EAAA,KAAA,CAAM,KAAO,EAAA,GAAA,EAAK,MAAM,GAAI,EAAA,CAAA;AAAA,KAE7C,CAAC,GAAI,OAAO,KAAA,KAAU,YAAY,KAAS,IAAA,IAAA,GAAO,CAAC,KAAK,IAAI,CAAC,KAAA,CAAM,OAAO,KAAM,CAAA,GAAG,CAAE,CAAC,CAAA,CAAA;AACzF,EAAA,MAAM,eAAe,kBAAmB,EAAA,CAAA;AAExC,EAAA,MAAM,cAAiB,GAAA,UAAA,CAAW,UAAU,CAAA,IAAK,WAAW,YAAY,CAAA,CAAA;AACxE,EAAA,IAAI,kBAAkB,IAAM,EAAA;AACxB,IAAA,MAAM,IAAI,KAAA;AAAA,MACN,CAAA,yHAAA,CAAA;AAAA,KAEJ,CAAA;AAAA,GACJ;AACA,EAAO,OAAA,cAAA,CAAA;AACX,CAAA;AAEA,SAAS,WAAW,KAAsD,EAAA;AACtE,EAAO,OAAA,KAAA,EAAO,OAAO,KAAO,EAAA,KAAA,CAAA;AAChC;;;;"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
async function fetchCapabilities(url, httpService, signal) {
|
|
2
|
+
const response = await httpService.fetch(url, { signal });
|
|
3
|
+
if (!response.ok) {
|
|
4
|
+
throw new Error("Request failed: " + response.status);
|
|
5
|
+
}
|
|
6
|
+
const result = await response.text();
|
|
7
|
+
return result;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export { fetchCapabilities };
|
|
11
|
+
//# sourceMappingURL=capabilities-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"capabilities-utils.js","sources":["capabilities-utils.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { HttpService } from \"@open-pioneer/http\";\n\nexport async function fetchCapabilities(\n url: string,\n httpService: HttpService,\n signal: AbortSignal\n): Promise<string> {\n const response = await httpService.fetch(url, { signal });\n if (!response.ok) {\n throw new Error(\"Request failed: \" + response.status);\n }\n const result = await response.text();\n return result;\n}\n"],"names":[],"mappings":"AAIsB,eAAA,iBAAA,CAClB,GACA,EAAA,WAAA,EACA,MACe,EAAA;AACf,EAAA,MAAM,WAAW,MAAM,WAAA,CAAY,MAAM,GAAK,EAAA,EAAE,QAAQ,CAAA,CAAA;AACxD,EAAI,IAAA,CAAC,SAAS,EAAI,EAAA;AACd,IAAA,MAAM,IAAI,KAAA,CAAM,kBAAqB,GAAA,QAAA,CAAS,MAAM,CAAA,CAAA;AAAA,GACxD;AACA,EAAM,MAAA,MAAA,GAAS,MAAM,QAAA,CAAS,IAAK,EAAA,CAAA;AACnC,EAAO,OAAA,MAAA,CAAA;AACX;;;;"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Extent } from "ol/extent";
|
|
2
|
+
/**
|
|
3
|
+
* Computes a buffered extent using the given original extent.
|
|
4
|
+
*
|
|
5
|
+
* Use the `factor` (`1.2` by default) to specify the size increase.
|
|
6
|
+
*/
|
|
7
|
+
export declare function calculateBufferedExtent(extent: Extent, factor?: number): Extent;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { getHeight, getWidth } from 'ol/extent.js';
|
|
2
|
+
|
|
3
|
+
const DEFAULT_BUFFER_FACTOR = 1.2;
|
|
4
|
+
function calculateBufferedExtent(extent, factor = DEFAULT_BUFFER_FACTOR) {
|
|
5
|
+
checkExtent(extent);
|
|
6
|
+
const width = getHeight(extent);
|
|
7
|
+
const height = getWidth(extent);
|
|
8
|
+
const bufferWidth = width * factor;
|
|
9
|
+
const bufferHeight = height * factor;
|
|
10
|
+
const bufferedExtent = [
|
|
11
|
+
extent[0] - (bufferWidth - width) / 2,
|
|
12
|
+
extent[1] - (bufferHeight - height) / 2,
|
|
13
|
+
extent[2] + (bufferWidth - width) / 2,
|
|
14
|
+
extent[3] + (bufferHeight - height) / 2
|
|
15
|
+
];
|
|
16
|
+
return bufferedExtent;
|
|
17
|
+
}
|
|
18
|
+
function checkExtent(extent) {
|
|
19
|
+
if (extent.length !== 4) {
|
|
20
|
+
throw new Error(`Invalid extent (expected length 4, but got length ${extent.length}).`);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export { calculateBufferedExtent };
|
|
25
|
+
//# sourceMappingURL=geometry-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geometry-utils.js","sources":["geometry-utils.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { Extent, getHeight, getWidth } from \"ol/extent\";\n\nconst DEFAULT_BUFFER_FACTOR = 1.2;\n\n/**\n * Computes a buffered extent using the given original extent.\n *\n * Use the `factor` (`1.2` by default) to specify the size increase.\n */\nexport function calculateBufferedExtent(extent: Extent, factor = DEFAULT_BUFFER_FACTOR): Extent {\n checkExtent(extent);\n const width = getHeight(extent);\n const height = getWidth(extent);\n const bufferWidth = width * factor;\n const bufferHeight = height * factor;\n const bufferedExtent = [\n extent[0] - (bufferWidth - width) / 2,\n extent[1] - (bufferHeight - height) / 2,\n extent[2] + (bufferWidth - width) / 2,\n extent[3] + (bufferHeight - height) / 2\n ];\n return bufferedExtent;\n}\n\nfunction checkExtent(extent: Extent): asserts extent is [number, number, number, number] {\n if (extent.length !== 4) {\n throw new Error(`Invalid extent (expected length 4, but got length ${extent.length}).`);\n }\n}\n"],"names":[],"mappings":";;AAIA,MAAM,qBAAwB,GAAA,GAAA,CAAA;AAOd,SAAA,uBAAA,CAAwB,MAAgB,EAAA,MAAA,GAAS,qBAA+B,EAAA;AAC5F,EAAA,WAAA,CAAY,MAAM,CAAA,CAAA;AAClB,EAAM,MAAA,KAAA,GAAQ,UAAU,MAAM,CAAA,CAAA;AAC9B,EAAM,MAAA,MAAA,GAAS,SAAS,MAAM,CAAA,CAAA;AAC9B,EAAA,MAAM,cAAc,KAAQ,GAAA,MAAA,CAAA;AAC5B,EAAA,MAAM,eAAe,MAAS,GAAA,MAAA,CAAA;AAC9B,EAAA,MAAM,cAAiB,GAAA;AAAA,IACnB,MAAO,CAAA,CAAC,CAAK,GAAA,CAAA,WAAA,GAAc,KAAS,IAAA,CAAA;AAAA,IACpC,MAAO,CAAA,CAAC,CAAK,GAAA,CAAA,YAAA,GAAe,MAAU,IAAA,CAAA;AAAA,IACtC,MAAO,CAAA,CAAC,CAAK,GAAA,CAAA,WAAA,GAAc,KAAS,IAAA,CAAA;AAAA,IACpC,MAAO,CAAA,CAAC,CAAK,GAAA,CAAA,YAAA,GAAe,MAAU,IAAA,CAAA;AAAA,GAC1C,CAAA;AACA,EAAO,OAAA,cAAA,CAAA;AACX,CAAA;AAEA,SAAS,YAAY,MAAoE,EAAA;AACrF,EAAI,IAAA,MAAA,CAAO,WAAW,CAAG,EAAA;AACrB,IAAA,MAAM,IAAI,KAAA,CAAM,CAAqD,kDAAA,EAAA,MAAA,CAAO,MAAM,CAAI,EAAA,CAAA,CAAA,CAAA;AAAA,GAC1F;AACJ;;;;"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { equals } from 'ol/extent.js';
|
|
2
|
+
import OlMap from 'ol/Map.js';
|
|
3
|
+
|
|
4
|
+
let setupDone = false;
|
|
5
|
+
function patchOpenLayersClassesForTesting() {
|
|
6
|
+
if (setupDone) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
OlMap.prototype.updateSize = function() {
|
|
10
|
+
const target = this.getTargetElement();
|
|
11
|
+
const height = 500;
|
|
12
|
+
const width = 500;
|
|
13
|
+
const size = target ? [width, height] : void 0;
|
|
14
|
+
const oldSize = this.getSize();
|
|
15
|
+
if (size && (!oldSize || !equals(size, oldSize))) {
|
|
16
|
+
this.setSize(size);
|
|
17
|
+
this.updateViewportSize_();
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
setupDone = true;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export { patchOpenLayersClassesForTesting };
|
|
24
|
+
//# sourceMappingURL=ol-test-support.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ol-test-support.js","sources":["ol-test-support.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { equals as extentEquals } from \"ol/extent\";\nimport OlMap from \"ol/Map\";\n\nlet setupDone = false;\n\n/** @internal */\nexport function patchOpenLayersClassesForTesting() {\n if (setupDone) {\n return;\n }\n\n // Test support: OpenLayers relies on div.offsetHeight (and Width)\n // plus getComputedStyle(div), which do not work as expected in happy dom.\n // The following snippet fakes a size so tests can work with the map.\n OlMap.prototype.updateSize = function () {\n const target = this.getTargetElement();\n const height = 500;\n const width = 500;\n const size = target ? [width, height] : undefined;\n const oldSize = this.getSize();\n if (size && (!oldSize || !extentEquals(size, oldSize))) {\n this.setSize(size);\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (this as any).updateViewportSize_();\n }\n };\n setupDone = true;\n}\n"],"names":["extentEquals"],"mappings":";;;AAKA,IAAI,SAAY,GAAA,KAAA,CAAA;AAGT,SAAS,gCAAmC,GAAA;AAC/C,EAAA,IAAI,SAAW,EAAA;AACX,IAAA,OAAA;AAAA,GACJ;AAKA,EAAM,KAAA,CAAA,SAAA,CAAU,aAAa,WAAY;AACrC,IAAM,MAAA,MAAA,GAAS,KAAK,gBAAiB,EAAA,CAAA;AACrC,IAAA,MAAM,MAAS,GAAA,GAAA,CAAA;AACf,IAAA,MAAM,KAAQ,GAAA,GAAA,CAAA;AACd,IAAA,MAAM,IAAO,GAAA,MAAA,GAAS,CAAC,KAAA,EAAO,MAAM,CAAI,GAAA,KAAA,CAAA,CAAA;AACxC,IAAM,MAAA,OAAA,GAAU,KAAK,OAAQ,EAAA,CAAA;AAC7B,IAAA,IAAI,SAAS,CAAC,OAAA,IAAW,CAACA,MAAa,CAAA,IAAA,EAAM,OAAO,CAAI,CAAA,EAAA;AACpD,MAAA,IAAA,CAAK,QAAQ,IAAI,CAAA,CAAA;AAEjB,MAAC,KAAa,mBAAoB,EAAA,CAAA;AAAA,KACtC;AAAA,GACJ,CAAA;AACA,EAAY,SAAA,GAAA,IAAA,CAAA;AAChB;;;;"}
|