@open-pioneer/map-navigation 0.4.3 → 0.7.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 +50 -0
- package/History.d.ts +29 -0
- package/History.js +75 -0
- package/History.js.map +1 -0
- package/InitialExtent.d.ts +2 -5
- package/InitialExtent.js +1 -2
- package/InitialExtent.js.map +1 -1
- package/README.md +16 -0
- package/ViewHistoryModel.d.ts +36 -0
- package/ViewHistoryModel.js +124 -0
- package/ViewHistoryModel.js.map +1 -0
- package/Zoom.d.ts +2 -5
- package/Zoom.js +13 -6
- package/Zoom.js.map +1 -1
- package/i18n/de.yaml +4 -0
- package/i18n/en.yaml +4 -0
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/index.js.map +1 -1
- package/package.json +10 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,55 @@
|
|
|
1
1
|
# @open-pioneer/map-navigation
|
|
2
2
|
|
|
3
|
+
## 0.7.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 440b165: Create new tool buttons that allow the user to navigate the history of map views (e.g. jump back to previous map extent):
|
|
8
|
+
|
|
9
|
+
```jsx
|
|
10
|
+
<HistoryBackward /* ... */ />
|
|
11
|
+
<HistoryForward /* ... */ />
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
- 310800c: Switch from `peerDependencies` to normal `dependencies`. Peer dependencies have some usability problems when used at scale.
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- 310800c: Update core packages version.
|
|
19
|
+
- 483c416: Don't attempt to zoom past configured zoom limits (#356).
|
|
20
|
+
As a side effect of this change, clicks on the zoom in/out buttons are ignored during the brief animation period (currently 200ms).
|
|
21
|
+
- 583f1d6: The `mapId` or `map` properties are now optional on individual components.
|
|
22
|
+
You can use the `DefaultMapProvider` to configure an implicit default value.
|
|
23
|
+
|
|
24
|
+
Note that configuring _neither_ a default _nor_ an explicit `map` or `mapId` will trigger a runtime error.
|
|
25
|
+
|
|
26
|
+
- 583f1d6: All UI components in this project now accept the `mapId` (a `string`) _or_ the `map` (a `MapModel`) directly.
|
|
27
|
+
- a8b3449: Switch to a new versioning strategy.
|
|
28
|
+
From now on, packages released by this repository share a common version number.
|
|
29
|
+
- 900eb11: Update dependencies.
|
|
30
|
+
- Updated dependencies [310800c]
|
|
31
|
+
- Updated dependencies [2502050]
|
|
32
|
+
- Updated dependencies [583f1d6]
|
|
33
|
+
- Updated dependencies [583f1d6]
|
|
34
|
+
- Updated dependencies [397d617]
|
|
35
|
+
- Updated dependencies [a8b3449]
|
|
36
|
+
- Updated dependencies [310800c]
|
|
37
|
+
- Updated dependencies [900eb11]
|
|
38
|
+
- Updated dependencies [583f1d6]
|
|
39
|
+
- Updated dependencies [397d617]
|
|
40
|
+
- @open-pioneer/map-ui-components@0.7.0
|
|
41
|
+
- @open-pioneer/map@0.7.0
|
|
42
|
+
|
|
43
|
+
## 0.4.4
|
|
44
|
+
|
|
45
|
+
### Patch Changes
|
|
46
|
+
|
|
47
|
+
- b152428: Update trails dependencies
|
|
48
|
+
- Updated dependencies [b152428]
|
|
49
|
+
- Updated dependencies [291ccb6]
|
|
50
|
+
- @open-pioneer/map-ui-components@0.1.1
|
|
51
|
+
- @open-pioneer/map@0.6.1
|
|
52
|
+
|
|
3
53
|
## 0.4.3
|
|
4
54
|
|
|
5
55
|
### Patch Changes
|
package/History.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { MapModelProps } from "@open-pioneer/map";
|
|
2
|
+
import { CommonComponentProps } from "@open-pioneer/react-utils";
|
|
3
|
+
import { FC, RefAttributes } from "react";
|
|
4
|
+
export type HistoryForwardProps = Omit<HistoryProps, "viewDirection">;
|
|
5
|
+
/**
|
|
6
|
+
* Provides a button by which the user can navigate to the next map view.
|
|
7
|
+
*
|
|
8
|
+
* This component composes {@link History}.
|
|
9
|
+
*/
|
|
10
|
+
export declare const HistoryForward: FC<HistoryForwardProps>;
|
|
11
|
+
export type HistoryBackwardProps = HistoryForwardProps;
|
|
12
|
+
/**
|
|
13
|
+
* Provides a button by which the user can navigate to the previous map view.
|
|
14
|
+
*
|
|
15
|
+
* This component composes {@link History}.
|
|
16
|
+
*/
|
|
17
|
+
export declare const HistoryBackward: FC<HistoryBackwardProps>;
|
|
18
|
+
export interface HistoryProps extends CommonComponentProps, RefAttributes<HTMLButtonElement>, MapModelProps {
|
|
19
|
+
/**
|
|
20
|
+
* The view direction.
|
|
21
|
+
*
|
|
22
|
+
* The button will either view forward or view backward depending on this value.
|
|
23
|
+
*/
|
|
24
|
+
viewDirection: "forward" | "backward";
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Provides a button by which the user can navigate forward or backward in the view history of the map.
|
|
28
|
+
*/
|
|
29
|
+
export declare const History: FC<HistoryProps>;
|
package/History.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { useMapModel } from '@open-pioneer/map';
|
|
3
|
+
import { ToolButton } from '@open-pioneer/map-ui-components';
|
|
4
|
+
import { useCommonComponentProps } from '@open-pioneer/react-utils';
|
|
5
|
+
import { useReactiveSnapshot } from '@open-pioneer/reactivity';
|
|
6
|
+
import classNames from 'classnames';
|
|
7
|
+
import { useIntl } from './_virtual/_virtual-pioneer-module_react-hooks.js';
|
|
8
|
+
import { forwardRef } from 'react';
|
|
9
|
+
import { FiCornerUpLeft, FiCornerUpRight } from 'react-icons/fi';
|
|
10
|
+
import { useHistoryViewModel } from './ViewHistoryModel.js';
|
|
11
|
+
|
|
12
|
+
const HistoryForward = forwardRef(function HistoryForward2(props, ref) {
|
|
13
|
+
return /* @__PURE__ */ jsx(History, { viewDirection: "forward", ref, ...props });
|
|
14
|
+
});
|
|
15
|
+
const HistoryBackward = forwardRef(function HistoryBackward2(props, ref) {
|
|
16
|
+
return /* @__PURE__ */ jsx(History, { viewDirection: "backward", ref, ...props });
|
|
17
|
+
});
|
|
18
|
+
const History = forwardRef(function History2(props, ref) {
|
|
19
|
+
const intl = useIntl();
|
|
20
|
+
const { viewDirection } = props;
|
|
21
|
+
const { map } = useMapModel(props);
|
|
22
|
+
const viewModel = useHistoryViewModel(map);
|
|
23
|
+
const { defaultClassName, buttonLabel, buttonIcon } = getDirectionProps(intl, viewDirection);
|
|
24
|
+
const { containerProps } = useCommonComponentProps(classNames("view", defaultClassName), props);
|
|
25
|
+
const canNavigate = useReactiveSnapshot(() => {
|
|
26
|
+
if (!viewModel) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
if (viewDirection === "forward") {
|
|
30
|
+
return viewModel.canForward;
|
|
31
|
+
} else {
|
|
32
|
+
return viewModel.canBackward;
|
|
33
|
+
}
|
|
34
|
+
}, [viewModel, viewDirection]);
|
|
35
|
+
const navigate = () => {
|
|
36
|
+
if (!viewModel) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
if (viewDirection === "forward") {
|
|
40
|
+
viewModel.forward();
|
|
41
|
+
} else {
|
|
42
|
+
viewModel.backward();
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
return viewModel && /* @__PURE__ */ jsx(
|
|
46
|
+
ToolButton,
|
|
47
|
+
{
|
|
48
|
+
ref,
|
|
49
|
+
...containerProps,
|
|
50
|
+
label: buttonLabel,
|
|
51
|
+
icon: buttonIcon,
|
|
52
|
+
onClick: navigate,
|
|
53
|
+
isDisabled: !canNavigate
|
|
54
|
+
}
|
|
55
|
+
);
|
|
56
|
+
});
|
|
57
|
+
function getDirectionProps(intl, viewDirection) {
|
|
58
|
+
switch (viewDirection) {
|
|
59
|
+
case "forward":
|
|
60
|
+
return {
|
|
61
|
+
defaultClassName: "view-forward",
|
|
62
|
+
buttonLabel: intl.formatMessage({ id: "view-forward.title" }),
|
|
63
|
+
buttonIcon: /* @__PURE__ */ jsx(FiCornerUpRight, {})
|
|
64
|
+
};
|
|
65
|
+
case "backward":
|
|
66
|
+
return {
|
|
67
|
+
defaultClassName: "view-backward",
|
|
68
|
+
buttonLabel: intl.formatMessage({ id: "view-backward.title" }),
|
|
69
|
+
buttonIcon: /* @__PURE__ */ jsx(FiCornerUpLeft, {})
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export { History, HistoryBackward, HistoryForward };
|
|
75
|
+
//# sourceMappingURL=History.js.map
|
package/History.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"History.js","sources":["History.tsx"],"sourcesContent":["// SPDX-FileCopyrightText: 2023 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { MapModelProps, useMapModel } from \"@open-pioneer/map\";\nimport { ToolButton } from \"@open-pioneer/map-ui-components\";\nimport { CommonComponentProps, useCommonComponentProps } from \"@open-pioneer/react-utils\";\nimport { useReactiveSnapshot } from \"@open-pioneer/reactivity\";\nimport { PackageIntl } from \"@open-pioneer/runtime\";\nimport classNames from \"classnames\";\nimport { useIntl } from \"open-pioneer:react-hooks\";\nimport { FC, ForwardedRef, forwardRef, RefAttributes } from \"react\";\nimport { FiCornerUpLeft, FiCornerUpRight } from \"react-icons/fi\";\nimport { useHistoryViewModel } from \"./ViewHistoryModel\";\n\nexport type HistoryForwardProps = Omit<HistoryProps, \"viewDirection\">;\n\n/**\n * Provides a button by which the user can navigate to the next map view.\n *\n * This component composes {@link History}.\n */\nexport const HistoryForward: FC<HistoryForwardProps> = forwardRef(function HistoryForward(\n props: HistoryForwardProps,\n ref: ForwardedRef<HTMLButtonElement>\n) {\n return <History viewDirection=\"forward\" ref={ref} {...props} />;\n});\n\nexport type HistoryBackwardProps = HistoryForwardProps;\n\n/**\n * Provides a button by which the user can navigate to the previous map view.\n *\n * This component composes {@link History}.\n */\nexport const HistoryBackward: FC<HistoryBackwardProps> = forwardRef(function HistoryBackward(\n props: HistoryBackwardProps,\n ref: ForwardedRef<HTMLButtonElement>\n) {\n return <History viewDirection=\"backward\" ref={ref} {...props} />;\n});\n\nexport interface HistoryProps\n extends CommonComponentProps,\n RefAttributes<HTMLButtonElement>,\n MapModelProps {\n /**\n * The view direction.\n *\n * The button will either view forward or view backward depending on this value.\n */\n viewDirection: \"forward\" | \"backward\";\n}\n\n/**\n * Provides a button by which the user can navigate forward or backward in the view history of the map.\n */\nexport const History: FC<HistoryProps> = forwardRef(function History(\n props: HistoryProps,\n ref: ForwardedRef<HTMLButtonElement>\n) {\n const intl = useIntl();\n const { viewDirection } = props;\n const { map } = useMapModel(props);\n const viewModel = useHistoryViewModel(map);\n const { defaultClassName, buttonLabel, buttonIcon } = getDirectionProps(intl, viewDirection);\n const { containerProps } = useCommonComponentProps(classNames(\"view\", defaultClassName), props);\n\n const canNavigate = useReactiveSnapshot(() => {\n if (!viewModel) {\n return false;\n }\n\n if (viewDirection === \"forward\") {\n return viewModel.canForward;\n } else {\n return viewModel.canBackward;\n }\n }, [viewModel, viewDirection]);\n const navigate = () => {\n if (!viewModel) {\n return;\n }\n\n if (viewDirection === \"forward\") {\n viewModel.forward();\n } else {\n viewModel.backward();\n }\n };\n\n return (\n viewModel && (\n <ToolButton\n ref={ref}\n {...containerProps}\n label={buttonLabel}\n icon={buttonIcon}\n onClick={navigate}\n isDisabled={!canNavigate}\n />\n )\n );\n});\n\nfunction getDirectionProps(intl: PackageIntl, viewDirection: \"forward\" | \"backward\") {\n switch (viewDirection) {\n case \"forward\":\n return {\n defaultClassName: \"view-forward\",\n buttonLabel: intl.formatMessage({ id: \"view-forward.title\" }),\n buttonIcon: <FiCornerUpRight />\n };\n case \"backward\":\n return {\n defaultClassName: \"view-backward\",\n buttonLabel: intl.formatMessage({ id: \"view-backward.title\" }),\n buttonIcon: <FiCornerUpLeft />\n };\n }\n}\n"],"names":["HistoryForward","HistoryBackward","History"],"mappings":";;;;;;;;;;;AAoBO,MAAM,cAA0C,GAAA,UAAA,CAAW,SAASA,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,CAAC,SAAW,EAAA;AACZ,MAAA,OAAA;AAAA,KACJ;AAEA,IAAA,IAAI,kBAAkB,SAAW,EAAA;AAC7B,MAAA,SAAA,CAAU,OAAQ,EAAA,CAAA;AAAA,KACf,MAAA;AACH,MAAA,SAAA,CAAU,QAAS,EAAA,CAAA;AAAA,KACvB;AAAA,GACJ,CAAA;AAEA,EAAA,OACI,SACI,oBAAA,GAAA;AAAA,IAAC,UAAA;AAAA,IAAA;AAAA,MACG,GAAA;AAAA,MACC,GAAG,cAAA;AAAA,MACJ,KAAO,EAAA,WAAA;AAAA,MACP,IAAM,EAAA,UAAA;AAAA,MACN,OAAS,EAAA,QAAA;AAAA,MACT,YAAY,CAAC,WAAA;AAAA,KAAA;AAAA,GACjB,CAAA;AAGZ,CAAC,EAAA;AAED,SAAS,iBAAA,CAAkB,MAAmB,aAAuC,EAAA;AACjF,EAAA,QAAQ,aAAe;AAAA,IACnB,KAAK,SAAA;AACD,MAAO,OAAA;AAAA,QACH,gBAAkB,EAAA,cAAA;AAAA,QAClB,aAAa,IAAK,CAAA,aAAA,CAAc,EAAE,EAAA,EAAI,sBAAsB,CAAA;AAAA,QAC5D,UAAA,sBAAa,eAAgB,EAAA,EAAA,CAAA;AAAA,OACjC,CAAA;AAAA,IACJ,KAAK,UAAA;AACD,MAAO,OAAA;AAAA,QACH,gBAAkB,EAAA,eAAA;AAAA,QAClB,aAAa,IAAK,CAAA,aAAA,CAAc,EAAE,EAAA,EAAI,uBAAuB,CAAA;AAAA,QAC7D,UAAA,sBAAa,cAAe,EAAA,EAAA,CAAA;AAAA,OAChC,CAAA;AAAA,GACR;AACJ;;;;"}
|
package/InitialExtent.d.ts
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
+
import { MapModelProps } from "@open-pioneer/map";
|
|
1
2
|
import { CommonComponentProps } from "@open-pioneer/react-utils";
|
|
2
3
|
import { FC, RefAttributes } from "react";
|
|
3
|
-
export interface InitialExtentProps extends CommonComponentProps, RefAttributes<HTMLButtonElement
|
|
4
|
-
/**
|
|
5
|
-
* The map id.
|
|
6
|
-
*/
|
|
7
|
-
mapId: string;
|
|
4
|
+
export interface InitialExtentProps extends CommonComponentProps, RefAttributes<HTMLButtonElement>, MapModelProps {
|
|
8
5
|
}
|
|
9
6
|
/**
|
|
10
7
|
* Provides a simple button that switches the view to its initial viewpoint.
|
package/InitialExtent.js
CHANGED
|
@@ -7,9 +7,8 @@ import { forwardRef } from 'react';
|
|
|
7
7
|
import { FiHome } from 'react-icons/fi';
|
|
8
8
|
|
|
9
9
|
const InitialExtent = forwardRef(function InitialExtent2(props, ref) {
|
|
10
|
-
const { mapId } = props;
|
|
11
10
|
const { containerProps } = useCommonComponentProps("initial-extent", props);
|
|
12
|
-
const { map } = useMapModel(
|
|
11
|
+
const { map } = useMapModel(props);
|
|
13
12
|
const intl = useIntl();
|
|
14
13
|
function setInitExtent() {
|
|
15
14
|
const initialExtent = map?.initialExtent;
|
package/InitialExtent.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InitialExtent.js","sources":["InitialExtent.tsx"],"sourcesContent":["// SPDX-FileCopyrightText: 2023 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { useMapModel } from \"@open-pioneer/map\";\nimport { ToolButton } from \"@open-pioneer/map-ui-components\";\nimport { CommonComponentProps, useCommonComponentProps } from \"@open-pioneer/react-utils\";\nimport { Extent } from \"ol/extent\";\nimport { useIntl } from \"open-pioneer:react-hooks\";\nimport { FC, ForwardedRef, RefAttributes, forwardRef } from \"react\";\nimport { FiHome } from \"react-icons/fi\";\n\nexport interface InitialExtentProps
|
|
1
|
+
{"version":3,"file":"InitialExtent.js","sources":["InitialExtent.tsx"],"sourcesContent":["// SPDX-FileCopyrightText: 2023 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { MapModelProps, useMapModel } from \"@open-pioneer/map\";\nimport { ToolButton } from \"@open-pioneer/map-ui-components\";\nimport { CommonComponentProps, useCommonComponentProps } from \"@open-pioneer/react-utils\";\nimport { Extent } from \"ol/extent\";\nimport { useIntl } from \"open-pioneer:react-hooks\";\nimport { FC, ForwardedRef, RefAttributes, forwardRef } from \"react\";\nimport { FiHome } from \"react-icons/fi\";\n\nexport interface InitialExtentProps\n extends CommonComponentProps,\n RefAttributes<HTMLButtonElement>,\n MapModelProps {}\n\n/**\n * Provides a simple button that switches the view to its initial viewpoint.\n */\nexport const InitialExtent: FC<InitialExtentProps> = forwardRef(function InitialExtent(\n props: InitialExtentProps,\n ref: ForwardedRef<HTMLButtonElement>\n) {\n const { containerProps } = useCommonComponentProps(\"initial-extent\", props);\n const { map } = useMapModel(props);\n const intl = useIntl();\n\n function setInitExtent() {\n const initialExtent = map?.initialExtent;\n const olMap = map?.olMap;\n\n if (initialExtent && olMap) {\n const newExtent: Extent = [\n initialExtent.xMin,\n initialExtent.yMin,\n initialExtent.xMax,\n initialExtent.yMax\n ];\n\n olMap.getView().fit(newExtent, { duration: 200 });\n }\n }\n\n return (\n <ToolButton\n ref={ref}\n label={intl.formatMessage({ id: \"initial-extent.title\" })}\n icon={<FiHome />}\n onClick={setInitExtent}\n {...containerProps}\n />\n );\n});\n"],"names":["InitialExtent"],"mappings":";;;;;;;;AAkBO,MAAM,aAAwC,GAAA,UAAA,CAAW,SAASA,cAAAA,CACrE,OACA,GACF,EAAA;AACE,EAAA,MAAM,EAAE,cAAA,EAAmB,GAAA,uBAAA,CAAwB,kBAAkB,KAAK,CAAA,CAAA;AAC1E,EAAA,MAAM,EAAE,GAAA,EAAQ,GAAA,WAAA,CAAY,KAAK,CAAA,CAAA;AACjC,EAAA,MAAM,OAAO,OAAQ,EAAA,CAAA;AAErB,EAAA,SAAS,aAAgB,GAAA;AACrB,IAAA,MAAM,gBAAgB,GAAK,EAAA,aAAA,CAAA;AAC3B,IAAA,MAAM,QAAQ,GAAK,EAAA,KAAA,CAAA;AAEnB,IAAA,IAAI,iBAAiB,KAAO,EAAA;AACxB,MAAA,MAAM,SAAoB,GAAA;AAAA,QACtB,aAAc,CAAA,IAAA;AAAA,QACd,aAAc,CAAA,IAAA;AAAA,QACd,aAAc,CAAA,IAAA;AAAA,QACd,aAAc,CAAA,IAAA;AAAA,OAClB,CAAA;AAEA,MAAA,KAAA,CAAM,SAAU,CAAA,GAAA,CAAI,WAAW,EAAE,QAAA,EAAU,KAAK,CAAA,CAAA;AAAA,KACpD;AAAA,GACJ;AAEA,EACI,uBAAA,GAAA;AAAA,IAAC,UAAA;AAAA,IAAA;AAAA,MACG,GAAA;AAAA,MACA,OAAO,IAAK,CAAA,aAAA,CAAc,EAAE,EAAA,EAAI,wBAAwB,CAAA;AAAA,MACxD,IAAA,sBAAO,MAAO,EAAA,EAAA,CAAA;AAAA,MACd,OAAS,EAAA,aAAA;AAAA,MACR,GAAG,cAAA;AAAA,KAAA;AAAA,GACR,CAAA;AAER,CAAC;;;;"}
|
package/README.md
CHANGED
|
@@ -4,6 +4,7 @@ This package provides a collection of the following map navigation controls:
|
|
|
4
4
|
|
|
5
5
|
- [Initial extent](#initial-extent): A button that allows the user to reset the map to the initial view.
|
|
6
6
|
- [Zoom](#zoom): Two buttons that allow the user to zoom in and zoom out of the map.
|
|
7
|
+
- [Navigate history forward and backward](#navigate-history-forward-and-backward): Two separate buttons that allow the user to navigate in the history of map views (e.g. jump back to previous map extent).
|
|
7
8
|
|
|
8
9
|
## Usage
|
|
9
10
|
|
|
@@ -30,6 +31,21 @@ You can also use the generic `Zoom` component:
|
|
|
30
31
|
<Zoom mapId="map_id" zoomDirection="in" />
|
|
31
32
|
```
|
|
32
33
|
|
|
34
|
+
### View history forward and backward
|
|
35
|
+
|
|
36
|
+
To integrate the component in your app, insert the following snippet and reference a view Model:
|
|
37
|
+
|
|
38
|
+
```jsx
|
|
39
|
+
<HistoryBackward mapId="map_id" />
|
|
40
|
+
<HistoryForward mapId="map_id" />
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
#### Limitations
|
|
44
|
+
|
|
45
|
+
The history tools use a shared history of previous map states.
|
|
46
|
+
Map states are tracked while at least one history tool is mounted into the application.
|
|
47
|
+
If all history tools are unmounted, the history of previous map states is discarded.
|
|
48
|
+
|
|
33
49
|
## License
|
|
34
50
|
|
|
35
51
|
Apache-2.0 (see `LICENSE` file)
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { MapModel } from "@open-pioneer/map";
|
|
2
|
+
import { ReactiveMap } from "@conterra/reactivity-core";
|
|
3
|
+
import { Coordinate } from "ol/coordinate";
|
|
4
|
+
interface MapViewState {
|
|
5
|
+
/** Map resolution */
|
|
6
|
+
resolution: number;
|
|
7
|
+
/** Map center */
|
|
8
|
+
center: Coordinate;
|
|
9
|
+
}
|
|
10
|
+
export declare class ViewHistoryModel {
|
|
11
|
+
#private;
|
|
12
|
+
private olMap;
|
|
13
|
+
private handle;
|
|
14
|
+
private _mapViews;
|
|
15
|
+
private _activeViewId;
|
|
16
|
+
constructor(map: MapModel);
|
|
17
|
+
destroy(): void;
|
|
18
|
+
get activeViewId(): number;
|
|
19
|
+
get mapViews(): ReactiveMap<number, MapViewState>;
|
|
20
|
+
get canBackward(): boolean;
|
|
21
|
+
get canForward(): boolean;
|
|
22
|
+
backward: () => void;
|
|
23
|
+
forward: () => void;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* An internal hook that returns a shared HistoryViewModel.
|
|
27
|
+
* History tools that are active at the same time share a single model.
|
|
28
|
+
*
|
|
29
|
+
* The model is destroyed when the last tool is unmounted.
|
|
30
|
+
*
|
|
31
|
+
* TODO: `undefined` only because the map can be undefined at the moment (loading).
|
|
32
|
+
*
|
|
33
|
+
* NOTE: May be useful to have this a general solution in the future; but this is the only usage right now.
|
|
34
|
+
*/
|
|
35
|
+
export declare function useHistoryViewModel(map: MapModel | undefined): ViewHistoryModel | undefined;
|
|
36
|
+
export {};
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { View } from 'ol';
|
|
2
|
+
import { unByKey } from 'ol/Observable.js';
|
|
3
|
+
import { reactiveMap, reactive } from '@conterra/reactivity-core';
|
|
4
|
+
import { useState, useEffect } from 'react';
|
|
5
|
+
|
|
6
|
+
const SIZE_LIMIT = 200;
|
|
7
|
+
class ViewHistoryModel {
|
|
8
|
+
olMap;
|
|
9
|
+
handle;
|
|
10
|
+
_mapViews = reactiveMap();
|
|
11
|
+
_activeViewId = reactive(0);
|
|
12
|
+
constructor(map) {
|
|
13
|
+
this.olMap = map.olMap;
|
|
14
|
+
this.handle = this.#subscribeToMapEvents();
|
|
15
|
+
}
|
|
16
|
+
destroy() {
|
|
17
|
+
this.handle && unByKey(this.handle);
|
|
18
|
+
this.handle = void 0;
|
|
19
|
+
}
|
|
20
|
+
get activeViewId() {
|
|
21
|
+
return this._activeViewId.value;
|
|
22
|
+
}
|
|
23
|
+
get mapViews() {
|
|
24
|
+
return this._mapViews;
|
|
25
|
+
}
|
|
26
|
+
get canBackward() {
|
|
27
|
+
return this.mapViews.get(this.activeViewId - 1) != null;
|
|
28
|
+
}
|
|
29
|
+
get canForward() {
|
|
30
|
+
return this.mapViews.get(this.activeViewId + 1) != null;
|
|
31
|
+
}
|
|
32
|
+
backward = () => {
|
|
33
|
+
if (this.canBackward) {
|
|
34
|
+
this.#setActiveView(this.activeViewId - 1);
|
|
35
|
+
this.#goto(this.activeViewId);
|
|
36
|
+
} else throw new Error("Backward is not possible at the moment");
|
|
37
|
+
};
|
|
38
|
+
forward = () => {
|
|
39
|
+
if (this.canForward) {
|
|
40
|
+
this.#setActiveView(this.activeViewId + 1);
|
|
41
|
+
this.#goto(this.activeViewId);
|
|
42
|
+
} else throw new Error("Forward is not possible at the moment");
|
|
43
|
+
};
|
|
44
|
+
#goto(activeViewId) {
|
|
45
|
+
const view = this.olMap.getView();
|
|
46
|
+
this.olMap.setView(
|
|
47
|
+
new View({
|
|
48
|
+
center: this.mapViews.get(activeViewId).center,
|
|
49
|
+
resolution: this.mapViews.get(activeViewId).resolution,
|
|
50
|
+
projection: view.getProjection()
|
|
51
|
+
})
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
#setActiveView(activeViewId) {
|
|
55
|
+
this._activeViewId.value = activeViewId;
|
|
56
|
+
}
|
|
57
|
+
#subscribeToMapEvents() {
|
|
58
|
+
const eventsKey = this.olMap.on("moveend", () => {
|
|
59
|
+
onCenterResChange();
|
|
60
|
+
});
|
|
61
|
+
const onCenterResChange = () => {
|
|
62
|
+
const olMap = this.olMap;
|
|
63
|
+
const mapViews = this.mapViews;
|
|
64
|
+
const view = olMap.getView();
|
|
65
|
+
const resolution = view.getResolution();
|
|
66
|
+
const center = view.getCenter();
|
|
67
|
+
if (resolution != null && center != null) {
|
|
68
|
+
if (center !== mapViews.get(this.activeViewId)?.center || resolution !== mapViews.get(this.activeViewId)?.resolution) {
|
|
69
|
+
const mapState = {
|
|
70
|
+
resolution,
|
|
71
|
+
center
|
|
72
|
+
};
|
|
73
|
+
const nextViewId = this.activeViewId + 1;
|
|
74
|
+
for (const k of mapViews.keys()) {
|
|
75
|
+
if (k > nextViewId) {
|
|
76
|
+
mapViews.delete(k);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
for (const k of mapViews.keys()) {
|
|
80
|
+
if (mapViews.size < SIZE_LIMIT) {
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
mapViews.delete(k);
|
|
84
|
+
}
|
|
85
|
+
this.#setActiveView(nextViewId);
|
|
86
|
+
mapViews.set(nextViewId, mapState);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
return eventsKey;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
const VIEW_MODELS = /* @__PURE__ */ new WeakMap();
|
|
94
|
+
function useHistoryViewModel(map) {
|
|
95
|
+
const [vm, setVm] = useState();
|
|
96
|
+
useEffect(() => {
|
|
97
|
+
if (!map) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
let state = VIEW_MODELS.get(map);
|
|
101
|
+
if (state == null) {
|
|
102
|
+
state = {
|
|
103
|
+
vm: new ViewHistoryModel(map),
|
|
104
|
+
useCount: 1
|
|
105
|
+
};
|
|
106
|
+
VIEW_MODELS.set(map, state);
|
|
107
|
+
} else {
|
|
108
|
+
state.useCount++;
|
|
109
|
+
}
|
|
110
|
+
setVm(state.vm);
|
|
111
|
+
return () => {
|
|
112
|
+
setVm(void 0);
|
|
113
|
+
state.useCount--;
|
|
114
|
+
if (state.useCount === 0) {
|
|
115
|
+
state.vm.destroy();
|
|
116
|
+
VIEW_MODELS.delete(map);
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
}, [map]);
|
|
120
|
+
return vm;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export { ViewHistoryModel, useHistoryViewModel };
|
|
124
|
+
//# sourceMappingURL=ViewHistoryModel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ViewHistoryModel.js","sources":["ViewHistoryModel.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { MapModel } from \"@open-pioneer/map\";\nimport { View } from \"ol\";\nimport { EventsKey } from \"ol/events\";\nimport { unByKey } from \"ol/Observable\";\nimport OlMap from \"ol/Map\";\nimport { Reactive, reactive, ReactiveMap, reactiveMap } from \"@conterra/reactivity-core\";\nimport { Coordinate } from \"ol/coordinate\";\nimport { useEffect, useState } from \"react\";\n\ninterface MapViewState {\n /** Map resolution */\n resolution: number;\n\n /** Map center */\n center: Coordinate;\n}\n\nconst SIZE_LIMIT = 200;\n\nexport class ViewHistoryModel {\n private olMap: OlMap;\n private handle: EventsKey | undefined;\n\n private _mapViews: ReactiveMap<number, MapViewState> = reactiveMap<number, MapViewState>();\n private _activeViewId: Reactive<number> = reactive(0);\n\n constructor(map: MapModel) {\n this.olMap = map.olMap;\n this.handle = this.#subscribeToMapEvents();\n }\n\n destroy() {\n this.handle && unByKey(this.handle);\n this.handle = undefined;\n }\n\n get activeViewId(): number {\n return this._activeViewId.value;\n }\n\n get mapViews(): ReactiveMap<number, MapViewState> {\n return this._mapViews;\n }\n\n get canBackward(): boolean {\n return this.mapViews.get(this.activeViewId - 1) != null;\n }\n\n get canForward(): boolean {\n return this.mapViews.get(this.activeViewId + 1) != null;\n }\n\n backward = () => {\n if (this.canBackward) {\n this.#setActiveView(this.activeViewId - 1);\n this.#goto(this.activeViewId);\n } else throw new Error(\"Backward is not possible at the moment\");\n };\n\n forward = () => {\n if (this.canForward) {\n this.#setActiveView(this.activeViewId + 1);\n this.#goto(this.activeViewId);\n } else throw new Error(\"Forward is not possible at the moment\");\n };\n\n #goto(activeViewId: number) {\n const view = this.olMap.getView();\n this.olMap.setView(\n new View({\n center: this.mapViews.get(activeViewId)!.center,\n resolution: this.mapViews.get(activeViewId)!.resolution,\n projection: view.getProjection()\n })\n );\n }\n\n #setActiveView(activeViewId: number) {\n this._activeViewId.value = activeViewId;\n }\n\n #subscribeToMapEvents() {\n const eventsKey: EventsKey = this.olMap.on(\"moveend\", () => {\n onCenterResChange();\n });\n\n const onCenterResChange = () => {\n const olMap = this.olMap;\n const mapViews = this.mapViews;\n const view = olMap.getView();\n const resolution = view.getResolution();\n const center = view.getCenter();\n if (resolution != null && center != null) {\n if (\n center !== mapViews.get(this.activeViewId)?.center ||\n resolution !== mapViews.get(this.activeViewId)?.resolution\n ) {\n const mapState = {\n resolution: resolution,\n center: center\n };\n const nextViewId = this.activeViewId + 1;\n\n // Remove keys in the \"future\". Note: an array would probably be more efficient.\n for (const k of mapViews.keys()) {\n if (k > nextViewId) {\n mapViews.delete(k);\n }\n }\n\n // Remove old keys above limit (maps are sorted by insertion order, so this removes the oldest entries)\n for (const k of mapViews.keys()) {\n if (mapViews.size < SIZE_LIMIT) {\n break;\n }\n mapViews.delete(k);\n }\n\n this.#setActiveView(nextViewId);\n mapViews.set(nextViewId, mapState);\n }\n }\n };\n\n return eventsKey;\n }\n}\n\ninterface ViewModelState {\n vm: ViewHistoryModel;\n useCount: number; // 0 -> must destroy\n}\n\nconst VIEW_MODELS = new WeakMap<MapModel, ViewModelState>();\n\n/**\n * An internal hook that returns a shared HistoryViewModel.\n * History tools that are active at the same time share a single model.\n *\n * The model is destroyed when the last tool is unmounted.\n *\n * TODO: `undefined` only because the map can be undefined at the moment (loading).\n *\n * NOTE: May be useful to have this a general solution in the future; but this is the only usage right now.\n */\nexport function useHistoryViewModel(map: MapModel | undefined): ViewHistoryModel | undefined {\n const [vm, setVm] = useState<ViewHistoryModel>();\n useEffect(() => {\n if (!map) {\n return;\n }\n\n let state = VIEW_MODELS.get(map);\n if (state == null) {\n state = {\n vm: new ViewHistoryModel(map),\n useCount: 1\n };\n VIEW_MODELS.set(map, state);\n } else {\n state.useCount++;\n }\n setVm(state.vm);\n\n return () => {\n setVm(undefined);\n\n state.useCount--;\n if (state.useCount === 0) {\n state.vm.destroy();\n VIEW_MODELS.delete(map);\n }\n };\n }, [map]);\n return vm;\n}\n"],"names":[],"mappings":";;;;;AAmBA,MAAM,UAAa,GAAA,GAAA,CAAA;AAEZ,MAAM,gBAAiB,CAAA;AAAA,EAClB,KAAA,CAAA;AAAA,EACA,MAAA,CAAA;AAAA,EAEA,YAA+C,WAAkC,EAAA,CAAA;AAAA,EACjF,aAAA,GAAkC,SAAS,CAAC,CAAA,CAAA;AAAA,EAEpD,YAAY,GAAe,EAAA;AACvB,IAAA,IAAA,CAAK,QAAQ,GAAI,CAAA,KAAA,CAAA;AACjB,IAAK,IAAA,CAAA,MAAA,GAAS,KAAK,qBAAsB,EAAA,CAAA;AAAA,GAC7C;AAAA,EAEA,OAAU,GAAA;AACN,IAAK,IAAA,CAAA,MAAA,IAAU,OAAQ,CAAA,IAAA,CAAK,MAAM,CAAA,CAAA;AAClC,IAAA,IAAA,CAAK,MAAS,GAAA,KAAA,CAAA,CAAA;AAAA,GAClB;AAAA,EAEA,IAAI,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A,CAAA;AAEf,MAAM,KAAA,CAAA,QAAA,EAAA,CAAA;AACN,MAAI,IAAA,KAAA,CAAM,aAAa,CAAG,EAAA;AACtB,QAAA,KAAA,CAAM,GAAG,OAAQ,EAAA,CAAA;AACjB,QAAA,WAAA,CAAY,OAAO,GAAG,CAAA,CAAA;AAAA,OAC1B;AAAA,KACJ,CAAA;AAAA,GACJ,EAAG,CAAC,GAAG,CAAC,CAAA,CAAA;AACR,EAAO,OAAA,EAAA,CAAA;AACX;;;;"}
|
package/Zoom.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { MapModelProps } from "@open-pioneer/map";
|
|
1
2
|
import { CommonComponentProps } from "@open-pioneer/react-utils";
|
|
2
3
|
import { FC, RefAttributes } from "react";
|
|
3
4
|
export type ZoomInProps = Omit<ZoomProps, "zoomDirection">;
|
|
@@ -14,11 +15,7 @@ export type ZoomOutProps = ZoomInProps;
|
|
|
14
15
|
* This component composes {@link Zoom}.
|
|
15
16
|
*/
|
|
16
17
|
export declare const ZoomOut: FC<ZoomOutProps>;
|
|
17
|
-
export interface ZoomProps extends CommonComponentProps, RefAttributes<HTMLButtonElement
|
|
18
|
-
/**
|
|
19
|
-
* The map id.
|
|
20
|
-
*/
|
|
21
|
-
mapId: string;
|
|
18
|
+
export interface ZoomProps extends CommonComponentProps, RefAttributes<HTMLButtonElement>, MapModelProps {
|
|
22
19
|
/**
|
|
23
20
|
* The zoom direction.
|
|
24
21
|
*
|
package/Zoom.js
CHANGED
|
@@ -4,7 +4,7 @@ import { ToolButton } from '@open-pioneer/map-ui-components';
|
|
|
4
4
|
import { useCommonComponentProps } from '@open-pioneer/react-utils';
|
|
5
5
|
import classNames from 'classnames';
|
|
6
6
|
import { useIntl } from './_virtual/_virtual-pioneer-module_react-hooks.js';
|
|
7
|
-
import { forwardRef } from 'react';
|
|
7
|
+
import { forwardRef, useState } from 'react';
|
|
8
8
|
import { FiMinus, FiPlus } from 'react-icons/fi';
|
|
9
9
|
|
|
10
10
|
const ZoomIn = forwardRef(function ZoomIn2(props, ref) {
|
|
@@ -14,21 +14,28 @@ const ZoomOut = forwardRef(function ZoomOut2(props, ref) {
|
|
|
14
14
|
return /* @__PURE__ */ jsx(Zoom, { zoomDirection: "out", ref, ...props });
|
|
15
15
|
});
|
|
16
16
|
const Zoom = forwardRef(function Zoom2(props, ref) {
|
|
17
|
-
const {
|
|
18
|
-
const { map } = useMapModel(
|
|
17
|
+
const { zoomDirection } = props;
|
|
18
|
+
const { map } = useMapModel(props);
|
|
19
19
|
const intl = useIntl();
|
|
20
|
+
const [disabled, setDisabled] = useState(false);
|
|
20
21
|
const { defaultClassName, buttonLabel, buttonIcon } = getDirectionProps(intl, zoomDirection);
|
|
21
22
|
const { containerProps } = useCommonComponentProps(classNames("zoom", defaultClassName), props);
|
|
22
23
|
function zoom() {
|
|
24
|
+
if (disabled) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
setDisabled(true);
|
|
23
28
|
const view = map?.olMap.getView();
|
|
24
29
|
let currZoom = view?.getZoom();
|
|
30
|
+
const maxZoom = view?.getMaxZoom() || Number.MAX_SAFE_INTEGER;
|
|
31
|
+
const minZoom = view?.getMinZoom() || 0;
|
|
25
32
|
if (view && currZoom !== void 0) {
|
|
26
|
-
if (zoomDirection === "in") {
|
|
33
|
+
if (zoomDirection === "in" && currZoom < maxZoom) {
|
|
27
34
|
++currZoom;
|
|
28
|
-
} else {
|
|
35
|
+
} else if (zoomDirection === "out" && currZoom > minZoom) {
|
|
29
36
|
--currZoom;
|
|
30
37
|
}
|
|
31
|
-
view.animate({ zoom: currZoom, duration: 200 });
|
|
38
|
+
view.animate({ zoom: currZoom, duration: 200 }, () => setDisabled(false));
|
|
32
39
|
}
|
|
33
40
|
}
|
|
34
41
|
return /* @__PURE__ */ jsx(
|
package/Zoom.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Zoom.js","sources":["Zoom.tsx"],"sourcesContent":["// SPDX-FileCopyrightText: 2023 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { useMapModel } from \"@open-pioneer/map\";\nimport { ToolButton } from \"@open-pioneer/map-ui-components\";\nimport { CommonComponentProps, useCommonComponentProps } from \"@open-pioneer/react-utils\";\nimport { PackageIntl } from \"@open-pioneer/runtime\";\nimport classNames from \"classnames\";\nimport { useIntl } from \"open-pioneer:react-hooks\";\nimport { FC, ForwardedRef, RefAttributes, forwardRef } from \"react\";\nimport { FiMinus, FiPlus } from \"react-icons/fi\";\n\nexport type ZoomInProps = Omit<ZoomProps, \"zoomDirection\">;\n\n/**\n * Provides a button by which the user can zoom into the map.\n *\n * This component composes {@link Zoom}.\n */\nexport const ZoomIn: FC<ZoomInProps> = forwardRef(function ZoomIn(props, ref) {\n return <Zoom zoomDirection=\"in\" ref={ref} {...props} />;\n});\n\nexport type ZoomOutProps = ZoomInProps;\n\n/**\n * Provides a button by which the user can zoom out of the map.\n *\n * This component composes {@link Zoom}.\n */\nexport const ZoomOut: FC<ZoomOutProps> = forwardRef(function ZoomOut(props, ref) {\n return <Zoom zoomDirection=\"out\" ref={ref} {...props} />;\n});\n\nexport interface ZoomProps
|
|
1
|
+
{"version":3,"file":"Zoom.js","sources":["Zoom.tsx"],"sourcesContent":["// SPDX-FileCopyrightText: 2023 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { MapModelProps, useMapModel } from \"@open-pioneer/map\";\nimport { ToolButton } from \"@open-pioneer/map-ui-components\";\nimport { CommonComponentProps, useCommonComponentProps } from \"@open-pioneer/react-utils\";\nimport { PackageIntl } from \"@open-pioneer/runtime\";\nimport classNames from \"classnames\";\nimport { useIntl } from \"open-pioneer:react-hooks\";\nimport { FC, ForwardedRef, RefAttributes, forwardRef, useState } from \"react\";\nimport { FiMinus, FiPlus } from \"react-icons/fi\";\n\nexport type ZoomInProps = Omit<ZoomProps, \"zoomDirection\">;\n\n/**\n * Provides a button by which the user can zoom into the map.\n *\n * This component composes {@link Zoom}.\n */\nexport const ZoomIn: FC<ZoomInProps> = forwardRef(function ZoomIn(props, ref) {\n return <Zoom zoomDirection=\"in\" ref={ref} {...props} />;\n});\n\nexport type ZoomOutProps = ZoomInProps;\n\n/**\n * Provides a button by which the user can zoom out of the map.\n *\n * This component composes {@link Zoom}.\n */\nexport const ZoomOut: FC<ZoomOutProps> = forwardRef(function ZoomOut(props, ref) {\n return <Zoom zoomDirection=\"out\" ref={ref} {...props} />;\n});\n\nexport interface ZoomProps\n extends CommonComponentProps,\n RefAttributes<HTMLButtonElement>,\n MapModelProps {\n /**\n * The zoom direction.\n *\n * The button will either zoom in or zoom out depending on this value.\n */\n zoomDirection: \"in\" | \"out\";\n}\n\n/**\n * Provides a button by which the user can zoom in or zoom out of the map.\n */\nexport const Zoom: FC<ZoomProps> = forwardRef(function Zoom(\n props: ZoomProps,\n ref: ForwardedRef<HTMLButtonElement>\n) {\n const { zoomDirection } = props;\n const { map } = useMapModel(props);\n const intl = useIntl();\n const [disabled, setDisabled] = useState<boolean>(false);\n const { defaultClassName, buttonLabel, buttonIcon } = getDirectionProps(intl, zoomDirection);\n\n const { containerProps } = useCommonComponentProps(classNames(\"zoom\", defaultClassName), props);\n\n function zoom() {\n if (disabled) {\n return;\n }\n setDisabled(true);\n const view = map?.olMap.getView();\n let currZoom = view?.getZoom();\n\n const maxZoom = view?.getMaxZoom() || Number.MAX_SAFE_INTEGER;\n const minZoom = view?.getMinZoom() || 0;\n if (view && currZoom !== undefined) {\n if (zoomDirection === \"in\" && currZoom < maxZoom) {\n ++currZoom;\n } else if (zoomDirection === \"out\" && currZoom > minZoom) {\n --currZoom;\n }\n\n view.animate({ zoom: currZoom, duration: 200 }, () => setDisabled(false));\n }\n }\n\n return (\n <ToolButton\n ref={ref}\n label={buttonLabel}\n icon={buttonIcon}\n onClick={zoom}\n {...containerProps}\n />\n );\n});\n\nfunction getDirectionProps(intl: PackageIntl, zoomDirection: \"in\" | \"out\") {\n switch (zoomDirection) {\n case \"in\":\n return {\n defaultClassName: \"zoom-in\",\n buttonLabel: intl.formatMessage({ id: \"zoom-in.title\" }),\n buttonIcon: <FiPlus />\n };\n case \"out\":\n return {\n defaultClassName: \"zoom-out\",\n buttonLabel: intl.formatMessage({ id: \"zoom-out.title\" }),\n buttonIcon: <FiMinus />\n };\n }\n}\n"],"names":["ZoomIn","ZoomOut","Zoom"],"mappings":";;;;;;;;;AAkBO,MAAM,MAA0B,GAAA,UAAA,CAAW,SAASA,OAAAA,CAAO,OAAO,GAAK,EAAA;AAC1E,EAAA,2BAAQ,IAAK,EAAA,EAAA,aAAA,EAAc,IAAK,EAAA,GAAA,EAAW,GAAG,KAAO,EAAA,CAAA,CAAA;AACzD,CAAC,EAAA;AASM,MAAM,OAA4B,GAAA,UAAA,CAAW,SAASC,QAAAA,CAAQ,OAAO,GAAK,EAAA;AAC7E,EAAA,2BAAQ,IAAK,EAAA,EAAA,aAAA,EAAc,KAAM,EAAA,GAAA,EAAW,GAAG,KAAO,EAAA,CAAA,CAAA;AAC1D,CAAC,EAAA;AAiBM,MAAM,IAAsB,GAAA,UAAA,CAAW,SAASC,KAAAA,CACnD,OACA,GACF,EAAA;AACE,EAAM,MAAA,EAAE,eAAkB,GAAA,KAAA,CAAA;AAC1B,EAAA,MAAM,EAAE,GAAA,EAAQ,GAAA,WAAA,CAAY,KAAK,CAAA,CAAA;AACjC,EAAA,MAAM,OAAO,OAAQ,EAAA,CAAA;AACrB,EAAA,MAAM,CAAC,QAAA,EAAU,WAAW,CAAA,GAAI,SAAkB,KAAK,CAAA,CAAA;AACvD,EAAA,MAAM,EAAE,gBAAkB,EAAA,WAAA,EAAa,YAAe,GAAA,iBAAA,CAAkB,MAAM,aAAa,CAAA,CAAA;AAE3F,EAAM,MAAA,EAAE,gBAAmB,GAAA,uBAAA,CAAwB,WAAW,MAAQ,EAAA,gBAAgB,GAAG,KAAK,CAAA,CAAA;AAE9F,EAAA,SAAS,I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,CAAc,EAAE,EAAA,EAAI,iBAAiB,CAAA;AAAA,QACvD,UAAA,sBAAa,MAAO,EAAA,EAAA,CAAA;AAAA,OACxB,CAAA;AAAA,IACJ,KAAK,KAAA;AACD,MAAO,OAAA;AAAA,QACH,gBAAkB,EAAA,UAAA;AAAA,QAClB,aAAa,IAAK,CAAA,aAAA,CAAc,EAAE,EAAA,EAAI,kBAAkB,CAAA;AAAA,QACxD,UAAA,sBAAa,OAAQ,EAAA,EAAA,CAAA;AAAA,OACzB,CAAA;AAAA,GACR;AACJ;;;;"}
|
package/i18n/de.yaml
CHANGED
package/i18n/en.yaml
CHANGED
package/index.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
export { InitialExtent, type InitialExtentProps } from "./InitialExtent";
|
|
2
2
|
export { Zoom, type ZoomProps, ZoomIn, type ZoomInProps, ZoomOut, type ZoomOutProps } from "./Zoom";
|
|
3
|
+
export { HistoryForward, type HistoryForwardProps, HistoryBackward, type HistoryBackwardProps, History, type HistoryProps } from "./History";
|
package/index.js
CHANGED
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@open-pioneer/map-navigation",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.7.0",
|
|
5
5
|
"description": "This package provides a collection of map navigation controls.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"open-pioneer-trails"
|
|
@@ -13,16 +13,18 @@
|
|
|
13
13
|
"url": "https://github.com/open-pioneer/trails-openlayers-base-packages",
|
|
14
14
|
"directory": "src/packages/map-navigation"
|
|
15
15
|
},
|
|
16
|
-
"
|
|
17
|
-
"@
|
|
18
|
-
"@open-pioneer/
|
|
19
|
-
"@open-pioneer/
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@conterra/reactivity-core": "^0.4.3",
|
|
18
|
+
"@open-pioneer/chakra-integration": "^2.3.0",
|
|
19
|
+
"@open-pioneer/react-utils": "^2.3.0",
|
|
20
|
+
"@open-pioneer/reactivity": "^2.3.0",
|
|
21
|
+
"@open-pioneer/runtime": "^2.3.0",
|
|
20
22
|
"classnames": "^2.3.2",
|
|
21
23
|
"ol": "^9.2.4",
|
|
22
24
|
"react": "^18.3.1",
|
|
23
|
-
"react-icons": "^5.
|
|
24
|
-
"@open-pioneer/map": "^0.
|
|
25
|
-
"@open-pioneer/map
|
|
25
|
+
"react-icons": "^5.3.0",
|
|
26
|
+
"@open-pioneer/map-ui-components": "^0.7.0",
|
|
27
|
+
"@open-pioneer/map": "^0.7.0"
|
|
26
28
|
},
|
|
27
29
|
"exports": {
|
|
28
30
|
"./package.json": "./package.json",
|