@open-pioneer/coordinate-search 0.8.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 +30 -0
- package/CoordinateInput.d.ts +86 -0
- package/CoordinateInput.js +218 -0
- package/CoordinateInput.js.map +1 -0
- package/CoordinateInputField.d.ts +10 -0
- package/CoordinateInputField.js +92 -0
- package/CoordinateInputField.js.map +1 -0
- package/CoordinateSearch.d.ts +26 -0
- package/CoordinateSearch.js +47 -0
- package/CoordinateSearch.js.map +1 -0
- package/LICENSE +202 -0
- package/ProjectionSelect.d.ts +7 -0
- package/ProjectionSelect.js +112 -0
- package/ProjectionSelect.js.map +1 -0
- package/README.md +147 -0
- package/_virtual/_virtual-pioneer-module_react-hooks.js +8 -0
- package/_virtual/_virtual-pioneer-module_react-hooks.js.map +1 -0
- package/coordinates.d.ts +13 -0
- package/coordinates.js +73 -0
- package/coordinates.js.map +1 -0
- package/i18n/de.yaml +14 -0
- package/i18n/en.yaml +14 -0
- package/index.d.ts +2 -0
- package/index.js +3 -0
- package/index.js.map +1 -0
- package/package.json +55 -0
- package/usePlaceholder.d.ts +7 -0
- package/usePlaceholder.js +27 -0
- package/usePlaceholder.js.map +1 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# @open-pioneer/coordinate-search
|
|
2
|
+
|
|
3
|
+
## 0.8.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- c8df895: Added new component CoordinateSearch with functionality to search for coordinates via input. Additionally added component CoordinateInput that allows the user to input coordinates manually and validates the input.
|
|
8
|
+
|
|
9
|
+
```tsx
|
|
10
|
+
<CoordinateSearch mapId="map_id" />
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
```tsx
|
|
14
|
+
<CoordinateInput mapId="map_id" />
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- 49f0207: Update trails core packages to version 2.4.0
|
|
20
|
+
- Updated dependencies [b717121]
|
|
21
|
+
- Updated dependencies [e7978a8]
|
|
22
|
+
- Updated dependencies [7a5f1e1]
|
|
23
|
+
- Updated dependencies [7ae9f90]
|
|
24
|
+
- Updated dependencies [d8337a6]
|
|
25
|
+
- Updated dependencies [49f0207]
|
|
26
|
+
- Updated dependencies [b2127df]
|
|
27
|
+
- Updated dependencies [2fa8020]
|
|
28
|
+
- Updated dependencies [7ae9f90]
|
|
29
|
+
- Updated dependencies [d8337a6]
|
|
30
|
+
- @open-pioneer/map@0.8.0
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { MapModelProps } from "@open-pioneer/map";
|
|
2
|
+
import { CommonComponentProps } from "@open-pioneer/react-utils";
|
|
3
|
+
import { Coordinate } from "ol/coordinate";
|
|
4
|
+
import { Projection, ProjectionLike } from "ol/proj";
|
|
5
|
+
import { FC } from "react";
|
|
6
|
+
/**
|
|
7
|
+
* Dropdown item of projection selection with an optional coordinate precision
|
|
8
|
+
*/
|
|
9
|
+
export interface ProjectionInput {
|
|
10
|
+
/**
|
|
11
|
+
* Label to show the user.
|
|
12
|
+
*/
|
|
13
|
+
label: string;
|
|
14
|
+
/**
|
|
15
|
+
* The map projection as projection or as string.
|
|
16
|
+
*/
|
|
17
|
+
value: ProjectionLike;
|
|
18
|
+
/**
|
|
19
|
+
* The number of displayed decimal places.
|
|
20
|
+
*/
|
|
21
|
+
precision?: number;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Internal view of a (normalized) projection.
|
|
25
|
+
* The projection has been looked up and optional values have been filled in.
|
|
26
|
+
*/
|
|
27
|
+
export interface ProjectionItem {
|
|
28
|
+
/**
|
|
29
|
+
* Label to show the user.
|
|
30
|
+
*/
|
|
31
|
+
label: string;
|
|
32
|
+
/**
|
|
33
|
+
* The map projection.
|
|
34
|
+
*/
|
|
35
|
+
value: Projection;
|
|
36
|
+
/**
|
|
37
|
+
* The number of displayed decimal places.
|
|
38
|
+
*/
|
|
39
|
+
precision: number;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Event type emitted when the user enters new coordinates or projection is changed by the user.
|
|
43
|
+
*/
|
|
44
|
+
export interface CoordinatesSelectEvent {
|
|
45
|
+
/** coordinates in the projection of the object */
|
|
46
|
+
coords: Coordinate;
|
|
47
|
+
/** the projection of the coordinates. */
|
|
48
|
+
projection: Projection;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Props for the {@link CoordinateInput} component.
|
|
52
|
+
*/
|
|
53
|
+
export interface CoordinateInputProps extends CommonComponentProps, MapModelProps {
|
|
54
|
+
/**
|
|
55
|
+
* List of projection options, only projections that are known by the map as projection are shown.
|
|
56
|
+
* Each projection can have an individual precision of coordinates.
|
|
57
|
+
*
|
|
58
|
+
* If no precision is given, the default precision is used.
|
|
59
|
+
*/
|
|
60
|
+
projections?: ProjectionInput[];
|
|
61
|
+
/**
|
|
62
|
+
* Optional event that gets called if (valid) coordinates are entered or projection is changed by the user.
|
|
63
|
+
*/
|
|
64
|
+
onSelect?: (event: CoordinatesSelectEvent) => void;
|
|
65
|
+
/**
|
|
66
|
+
* Optional event that gets called if the input is cleared.
|
|
67
|
+
*/
|
|
68
|
+
onClear?: () => void;
|
|
69
|
+
/**
|
|
70
|
+
* Insert input value and overwrite user input.
|
|
71
|
+
*/
|
|
72
|
+
input?: Coordinate;
|
|
73
|
+
/**
|
|
74
|
+
* Placeholder text to display when no input is present. Common usages:
|
|
75
|
+
* * hint for the user ("enter coordinate here")
|
|
76
|
+
* * example coordinate ("12.345 67.890")
|
|
77
|
+
* * current mouse position
|
|
78
|
+
*
|
|
79
|
+
* If a coordinate is given, it has to be in the current projection of the map.
|
|
80
|
+
*/
|
|
81
|
+
placeholder?: string | Coordinate;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* The `CoordinateInput` component can be used in an app to provide a validated input field for coordinates in a selected projection
|
|
85
|
+
*/
|
|
86
|
+
export declare const CoordinateInput: FC<CoordinateInputProps>;
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { reactive, computed } from '@conterra/reactivity-core';
|
|
3
|
+
import { Box, Portal, Flex, Tooltip, InputGroup, InputRightAddon } from '@open-pioneer/chakra-integration';
|
|
4
|
+
import { useMapModel } from '@open-pioneer/map';
|
|
5
|
+
import { useCommonComponentProps, useEvent } from '@open-pioneer/react-utils';
|
|
6
|
+
import { useReactiveSnapshot } from '@open-pioneer/reactivity';
|
|
7
|
+
import { get, transform } from 'ol/proj.js';
|
|
8
|
+
import { useIntl, useService } from './_virtual/_virtual-pioneer-module_react-hooks.js';
|
|
9
|
+
import { useState, useRef, useEffect, useCallback, useMemo } from 'react';
|
|
10
|
+
import { CoordinateInputField } from './CoordinateInputField.js';
|
|
11
|
+
import { parseCoordinates, formatCoordinates } from './coordinates.js';
|
|
12
|
+
import { ProjectionSelect } from './ProjectionSelect.js';
|
|
13
|
+
import { usePlaceholder } from './usePlaceholder.js';
|
|
14
|
+
|
|
15
|
+
const DEFAULT_PRECISION = 3;
|
|
16
|
+
const DEFAULT_PROJECTIONS = [
|
|
17
|
+
{
|
|
18
|
+
label: "WGS 84",
|
|
19
|
+
value: get("EPSG:4326"),
|
|
20
|
+
precision: 3
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
label: "Web Mercator",
|
|
24
|
+
value: get("EPSG:3857"),
|
|
25
|
+
precision: 2
|
|
26
|
+
}
|
|
27
|
+
];
|
|
28
|
+
const CoordinateInput = (props) => {
|
|
29
|
+
const {
|
|
30
|
+
onSelect: onSelectProp,
|
|
31
|
+
onClear,
|
|
32
|
+
projections = DEFAULT_PROJECTIONS,
|
|
33
|
+
input,
|
|
34
|
+
placeholder = ""
|
|
35
|
+
} = props;
|
|
36
|
+
const { containerProps } = useCommonComponentProps("coordinate-input", props);
|
|
37
|
+
const { map } = useMapModel(props);
|
|
38
|
+
const intl = useIntl();
|
|
39
|
+
const mapProjection = useReactiveSnapshot(() => map?.projection, [map]);
|
|
40
|
+
const availableProjections = useProjectionItems(projections);
|
|
41
|
+
const [selectedProjection, setSelectedProjection] = useState(
|
|
42
|
+
// choose first option initially
|
|
43
|
+
availableProjections[0]
|
|
44
|
+
);
|
|
45
|
+
const onSelect = useEvent((coordinatesResult) => {
|
|
46
|
+
if (!onSelectProp || coordinatesResult.kind !== "success" || mapProjection == null) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const coords = transform(
|
|
50
|
+
coordinatesResult.coordinates,
|
|
51
|
+
coordinatesResult.projection,
|
|
52
|
+
mapProjection
|
|
53
|
+
);
|
|
54
|
+
onSelectProp({ coords, projection: mapProjection });
|
|
55
|
+
});
|
|
56
|
+
const [coordinateSearchInput, setCoordinateSearchInput, validationResult] = useCoordinateState(
|
|
57
|
+
input,
|
|
58
|
+
mapProjection,
|
|
59
|
+
selectedProjection,
|
|
60
|
+
onSelect
|
|
61
|
+
);
|
|
62
|
+
const placeholderString = usePlaceholder(placeholder, mapProjection, selectedProjection);
|
|
63
|
+
const isInputValid = validationResult.kind === "success" || validationResult.kind === "empty";
|
|
64
|
+
const onEnter = useEvent(() => {
|
|
65
|
+
onSelect(validationResult);
|
|
66
|
+
});
|
|
67
|
+
const portalElement = useRef(null);
|
|
68
|
+
return /* @__PURE__ */ jsxs(Box, { ...containerProps, children: [
|
|
69
|
+
/* @__PURE__ */ jsx(Portal, { children: /* @__PURE__ */ jsx("div", { ref: portalElement }) }),
|
|
70
|
+
/* @__PURE__ */ jsx(Flex, { flexDirection: "row", flexDir: "row", children: /* @__PURE__ */ jsx(
|
|
71
|
+
Tooltip,
|
|
72
|
+
{
|
|
73
|
+
label: !isInputValid ? intl.formatMessage({ id: validationResult.kind }) : void 0,
|
|
74
|
+
hasArrow: true,
|
|
75
|
+
placement: "auto",
|
|
76
|
+
isOpen: !isInputValid,
|
|
77
|
+
className: "coordinate-input-tooltip",
|
|
78
|
+
children: /* @__PURE__ */ jsxs(InputGroup, { className: "coordinate-input-group", children: [
|
|
79
|
+
/* @__PURE__ */ jsx(
|
|
80
|
+
CoordinateInputField,
|
|
81
|
+
{
|
|
82
|
+
coordinateSearchInput,
|
|
83
|
+
setCoordinateSearchInput,
|
|
84
|
+
placeholder,
|
|
85
|
+
placeholderString,
|
|
86
|
+
onClear,
|
|
87
|
+
isInputValid,
|
|
88
|
+
onEnter
|
|
89
|
+
}
|
|
90
|
+
),
|
|
91
|
+
/* @__PURE__ */ jsx(InputRightAddon, { padding: "0px", borderLeft: "0px", children: /* @__PURE__ */ jsx(
|
|
92
|
+
ProjectionSelect,
|
|
93
|
+
{
|
|
94
|
+
portalElement,
|
|
95
|
+
currentProjection: selectedProjection,
|
|
96
|
+
projections: availableProjections,
|
|
97
|
+
onProjectionChange: setSelectedProjection
|
|
98
|
+
}
|
|
99
|
+
) })
|
|
100
|
+
] })
|
|
101
|
+
}
|
|
102
|
+
) })
|
|
103
|
+
] });
|
|
104
|
+
};
|
|
105
|
+
function useCoordinateState(inputProp, mapProjection, selectedProjection, onSelect) {
|
|
106
|
+
const intl = useIntl();
|
|
107
|
+
const numberParser = useService("runtime.NumberParserService");
|
|
108
|
+
const [model] = useState(() => new StateModel(intl, selectedProjection, numberParser));
|
|
109
|
+
useEffect(() => {
|
|
110
|
+
const triggerSelect = inputProp !== model.inputProp || selectedProjection !== model.selectedProjection;
|
|
111
|
+
model.setI18n(intl, numberParser);
|
|
112
|
+
model.setInputProp(inputProp);
|
|
113
|
+
model.setSelectedProjection(selectedProjection);
|
|
114
|
+
model.setMapProjection(mapProjection);
|
|
115
|
+
if (triggerSelect) {
|
|
116
|
+
const validationResult2 = model.validationResult;
|
|
117
|
+
onSelect(validationResult2);
|
|
118
|
+
}
|
|
119
|
+
}, [model, intl, numberParser, inputProp, selectedProjection, mapProjection, onSelect]);
|
|
120
|
+
const { rawInput, validationResult } = useReactiveSnapshot(() => {
|
|
121
|
+
return {
|
|
122
|
+
rawInput: model.rawInput,
|
|
123
|
+
validationResult: model.validationResult
|
|
124
|
+
};
|
|
125
|
+
}, [model]);
|
|
126
|
+
const setInputText = useCallback(
|
|
127
|
+
(inputText) => {
|
|
128
|
+
model.setText(inputText);
|
|
129
|
+
},
|
|
130
|
+
[model]
|
|
131
|
+
);
|
|
132
|
+
return [rawInput, setInputText, validationResult];
|
|
133
|
+
}
|
|
134
|
+
class StateModel {
|
|
135
|
+
#intl;
|
|
136
|
+
#selectedProjection;
|
|
137
|
+
#mapProjection = reactive();
|
|
138
|
+
#inputProp = reactive();
|
|
139
|
+
#numberParser;
|
|
140
|
+
#rawInput = reactive("");
|
|
141
|
+
#validationResult = computed(() => {
|
|
142
|
+
return parseCoordinates(
|
|
143
|
+
this.#rawInput.value,
|
|
144
|
+
this.#numberParser.value,
|
|
145
|
+
this.#selectedProjection.value.value
|
|
146
|
+
);
|
|
147
|
+
});
|
|
148
|
+
constructor(intl, selectedProjection, numberParser) {
|
|
149
|
+
this.#intl = reactive(intl);
|
|
150
|
+
this.#selectedProjection = reactive(selectedProjection);
|
|
151
|
+
this.#numberParser = reactive(numberParser);
|
|
152
|
+
}
|
|
153
|
+
get inputProp() {
|
|
154
|
+
return this.#inputProp.value;
|
|
155
|
+
}
|
|
156
|
+
get rawInput() {
|
|
157
|
+
return this.#rawInput.value;
|
|
158
|
+
}
|
|
159
|
+
get validationResult() {
|
|
160
|
+
return this.#validationResult.value;
|
|
161
|
+
}
|
|
162
|
+
get selectedProjection() {
|
|
163
|
+
return this.#selectedProjection.value;
|
|
164
|
+
}
|
|
165
|
+
setI18n(intl, numberParser) {
|
|
166
|
+
this.#intl.value = intl;
|
|
167
|
+
this.#numberParser.value = numberParser;
|
|
168
|
+
}
|
|
169
|
+
setText(text) {
|
|
170
|
+
this.#rawInput.value = text;
|
|
171
|
+
}
|
|
172
|
+
setSelectedProjection(value) {
|
|
173
|
+
if (value !== this.#selectedProjection.value) {
|
|
174
|
+
this.#selectedProjection.value = value;
|
|
175
|
+
this.#updateInput();
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
setInputProp(value) {
|
|
179
|
+
if (value !== this.#inputProp.value) {
|
|
180
|
+
this.#inputProp.value = value;
|
|
181
|
+
this.#updateInput();
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
setMapProjection(value) {
|
|
185
|
+
if (value !== this.#mapProjection.value) {
|
|
186
|
+
this.#mapProjection.value = value;
|
|
187
|
+
this.#updateInput();
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
#updateInput() {
|
|
191
|
+
const inputProp = this.#inputProp.value;
|
|
192
|
+
const mapProjection = this.#mapProjection.value;
|
|
193
|
+
const selectedProjection = this.#selectedProjection.value;
|
|
194
|
+
const intl = this.#intl.value;
|
|
195
|
+
if (mapProjection && inputProp) {
|
|
196
|
+
const transformed = transform(inputProp, mapProjection, selectedProjection.value);
|
|
197
|
+
const formatted = formatCoordinates(transformed, selectedProjection.precision, intl);
|
|
198
|
+
this.#rawInput.value = formatted;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
function useProjectionItems(projections) {
|
|
203
|
+
return useMemo(() => {
|
|
204
|
+
const availableProjections = projections.flatMap((ele) => {
|
|
205
|
+
if (get(ele.value) != null)
|
|
206
|
+
return {
|
|
207
|
+
label: ele.label,
|
|
208
|
+
value: get(ele.value),
|
|
209
|
+
precision: ele.precision ?? DEFAULT_PRECISION
|
|
210
|
+
};
|
|
211
|
+
return [];
|
|
212
|
+
});
|
|
213
|
+
return availableProjections;
|
|
214
|
+
}, [projections]);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
export { CoordinateInput };
|
|
218
|
+
//# sourceMappingURL=CoordinateInput.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CoordinateInput.js","sources":["CoordinateInput.tsx"],"sourcesContent":["// SPDX-FileCopyrightText: 2023 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { computed, Reactive, reactive } from \"@conterra/reactivity-core\";\nimport {\n Box,\n Flex,\n InputGroup,\n InputRightAddon,\n Portal,\n Tooltip\n} from \"@open-pioneer/chakra-integration\";\nimport { MapModelProps, useMapModel } from \"@open-pioneer/map\";\nimport { CommonComponentProps, useCommonComponentProps, useEvent } from \"@open-pioneer/react-utils\";\nimport { useReactiveSnapshot } from \"@open-pioneer/reactivity\";\nimport { NumberParserService, PackageIntl } from \"@open-pioneer/runtime\";\nimport { Coordinate } from \"ol/coordinate\";\nimport { get as getProjection, Projection, ProjectionLike, transform } from \"ol/proj\";\nimport { useIntl, useService } from \"open-pioneer:react-hooks\";\nimport { FC, useCallback, useEffect, useMemo, useRef, useState } from \"react\";\nimport { CoordinateInputField } from \"./CoordinateInputField\";\nimport { formatCoordinates, parseCoordinates, ParseResult } from \"./coordinates\";\nimport { ProjectionSelect } from \"./ProjectionSelect\";\nimport { usePlaceholder } from \"./usePlaceholder\";\n\nconst DEFAULT_PRECISION = 3;\nconst DEFAULT_PROJECTIONS = [\n {\n label: \"WGS 84\",\n value: getProjection(\"EPSG:4326\")!,\n precision: 3\n },\n {\n label: \"Web Mercator\",\n value: getProjection(\"EPSG:3857\")!,\n precision: 2\n }\n];\n\n/**\n * Dropdown item of projection selection with an optional coordinate precision\n */\nexport interface ProjectionInput {\n /**\n * Label to show the user.\n */\n label: string;\n\n /**\n * The map projection as projection or as string.\n */\n value: ProjectionLike;\n\n /**\n * The number of displayed decimal places.\n */\n precision?: number;\n}\n\n/**\n * Internal view of a (normalized) projection.\n * The projection has been looked up and optional values have been filled in.\n */\nexport interface ProjectionItem {\n /**\n * Label to show the user.\n */\n label: string;\n\n /**\n * The map projection.\n */\n value: Projection;\n\n /**\n * The number of displayed decimal places.\n */\n precision: number;\n}\n\n/**\n * Event type emitted when the user enters new coordinates or projection is changed by the user.\n */\nexport interface CoordinatesSelectEvent {\n /** coordinates in the projection of the object */\n coords: Coordinate;\n\n /** the projection of the coordinates. */\n projection: Projection;\n}\n\n/**\n * Props for the {@link CoordinateInput} component.\n */\nexport interface CoordinateInputProps extends CommonComponentProps, MapModelProps {\n /**\n * List of projection options, only projections that are known by the map as projection are shown.\n * Each projection can have an individual precision of coordinates.\n *\n * If no precision is given, the default precision is used.\n */\n projections?: ProjectionInput[];\n\n /**\n * Optional event that gets called if (valid) coordinates are entered or projection is changed by the user.\n */\n onSelect?: (event: CoordinatesSelectEvent) => void;\n\n /**\n * Optional event that gets called if the input is cleared.\n */\n onClear?: () => void;\n\n /**\n * Insert input value and overwrite user input.\n */\n input?: Coordinate;\n\n /**\n * Placeholder text to display when no input is present. Common usages:\n * * hint for the user (\"enter coordinate here\")\n * * example coordinate (\"12.345 67.890\")\n * * current mouse position\n *\n * If a coordinate is given, it has to be in the current projection of the map.\n */\n placeholder?: string | Coordinate;\n}\n\n/**\n * The `CoordinateInput` component can be used in an app to provide a validated input field for coordinates in a selected projection\n */\nexport const CoordinateInput: FC<CoordinateInputProps> = (props) => {\n const {\n onSelect: onSelectProp,\n onClear,\n projections = DEFAULT_PROJECTIONS,\n input,\n placeholder = \"\"\n } = props;\n const { containerProps } = useCommonComponentProps(\"coordinate-input\", props);\n const { map } = useMapModel(props);\n const intl = useIntl();\n const mapProjection = useReactiveSnapshot(() => map?.projection, [map]);\n\n // Projection items (dropdown)\n const availableProjections = useProjectionItems(projections);\n const [selectedProjection, setSelectedProjection] = useState<ProjectionItem>(\n // choose first option initially\n availableProjections[0]!\n );\n\n // Input state\n const onSelect = useEvent((coordinatesResult: ParseResult) => {\n if (!onSelectProp || coordinatesResult.kind !== \"success\" || mapProjection == null) {\n return;\n }\n\n const coords = transform(\n coordinatesResult.coordinates,\n coordinatesResult.projection,\n mapProjection\n );\n onSelectProp({ coords: coords, projection: mapProjection });\n });\n const [coordinateSearchInput, setCoordinateSearchInput, validationResult] = useCoordinateState(\n input,\n mapProjection,\n selectedProjection,\n onSelect\n );\n const placeholderString = usePlaceholder(placeholder, mapProjection, selectedProjection);\n const isInputValid = validationResult.kind === \"success\" || validationResult.kind === \"empty\";\n const onEnter = useEvent(() => {\n onSelect(validationResult);\n });\n\n const portalElement = useRef<HTMLDivElement>(null);\n return (\n <Box {...containerProps}>\n <Portal>\n <div ref={portalElement} />\n </Portal>\n <Flex flexDirection={\"row\"} flexDir={\"row\"}>\n <Tooltip\n label={\n !isInputValid\n ? intl.formatMessage({ id: validationResult.kind })\n : undefined\n }\n hasArrow\n placement=\"auto\"\n isOpen={!isInputValid}\n className=\"coordinate-input-tooltip\"\n >\n <InputGroup className=\"coordinate-input-group\">\n <CoordinateInputField\n coordinateSearchInput={coordinateSearchInput}\n setCoordinateSearchInput={setCoordinateSearchInput}\n placeholder={placeholder}\n placeholderString={placeholderString}\n onClear={onClear}\n isInputValid={isInputValid}\n onEnter={onEnter}\n />\n <InputRightAddon padding={\"0px\"} borderLeft={\"0px\"}>\n <ProjectionSelect\n portalElement={portalElement}\n currentProjection={selectedProjection}\n projections={availableProjections}\n onProjectionChange={setSelectedProjection}\n />\n </InputRightAddon>\n </InputGroup>\n </Tooltip>\n </Flex>\n </Box>\n );\n};\n\n/**\n * Returns the current text input and a callback to change it (used for interactive user input).\n * The current text may also change if the input prop changes (controlled usage).\n */\nfunction useCoordinateState(\n inputProp: Coordinate | undefined,\n mapProjection: Projection | undefined,\n selectedProjection: ProjectionItem,\n onSelect: (validationResult: ParseResult) => void\n): [string, (value: string) => void, ParseResult] {\n const intl = useIntl();\n const numberParser = useService<NumberParserService>(\"runtime.NumberParserService\");\n\n const [model] = useState(() => new StateModel(intl, selectedProjection, numberParser));\n useEffect(() => {\n const triggerSelect =\n inputProp !== model.inputProp || selectedProjection !== model.selectedProjection;\n\n model.setI18n(intl, numberParser);\n model.setInputProp(inputProp);\n model.setSelectedProjection(selectedProjection);\n model.setMapProjection(mapProjection);\n\n if (triggerSelect) {\n const validationResult = model.validationResult;\n onSelect(validationResult);\n }\n }, [model, intl, numberParser, inputProp, selectedProjection, mapProjection, onSelect]);\n\n const { rawInput, validationResult } = useReactiveSnapshot(() => {\n return {\n rawInput: model.rawInput,\n validationResult: model.validationResult\n };\n }, [model]);\n const setInputText = useCallback(\n (inputText: string) => {\n model.setText(inputText);\n },\n [model]\n );\n return [rawInput, setInputText, validationResult];\n}\n\nclass StateModel {\n #intl: Reactive<PackageIntl>;\n #selectedProjection: Reactive<ProjectionItem>;\n #mapProjection = reactive<Projection | undefined>();\n #inputProp = reactive<Coordinate | undefined>();\n #numberParser: Reactive<NumberParserService>;\n\n #rawInput = reactive(\"\");\n #validationResult = computed(() => {\n return parseCoordinates(\n this.#rawInput.value,\n this.#numberParser.value,\n this.#selectedProjection.value.value\n );\n });\n\n constructor(\n intl: PackageIntl,\n selectedProjection: ProjectionItem,\n numberParser: NumberParserService\n ) {\n this.#intl = reactive(intl);\n this.#selectedProjection = reactive(selectedProjection);\n this.#numberParser = reactive(numberParser);\n }\n\n get inputProp() {\n return this.#inputProp.value;\n }\n\n get rawInput() {\n return this.#rawInput.value;\n }\n\n get validationResult() {\n return this.#validationResult.value;\n }\n\n get selectedProjection() {\n return this.#selectedProjection.value;\n }\n\n setI18n(intl: PackageIntl, numberParser: NumberParserService) {\n this.#intl.value = intl;\n this.#numberParser.value = numberParser;\n }\n\n setText(text: string) {\n this.#rawInput.value = text;\n }\n\n setSelectedProjection(value: ProjectionItem) {\n if (value !== this.#selectedProjection.value) {\n this.#selectedProjection.value = value;\n this.#updateInput();\n }\n }\n\n setInputProp(value: Coordinate | undefined) {\n if (value !== this.#inputProp.value) {\n this.#inputProp.value = value;\n this.#updateInput();\n }\n }\n\n setMapProjection(value: Projection | undefined) {\n if (value !== this.#mapProjection.value) {\n this.#mapProjection.value = value;\n this.#updateInput();\n }\n }\n\n #updateInput() {\n const inputProp = this.#inputProp.value;\n const mapProjection = this.#mapProjection.value;\n const selectedProjection = this.#selectedProjection.value;\n const intl = this.#intl.value;\n if (mapProjection && inputProp) {\n // Update state based on input prop.\n const transformed = transform(inputProp, mapProjection, selectedProjection.value);\n const formatted = formatCoordinates(transformed, selectedProjection.precision, intl);\n this.#rawInput.value = formatted;\n }\n }\n}\n\n/**\n * Builds the list of available projection items based on the provided list of projections\n */\nfunction useProjectionItems(projections: ProjectionInput[]) {\n return useMemo(() => {\n // filter out projections that are not known\n const availableProjections: ProjectionItem[] = projections.flatMap((ele) => {\n if (getProjection(ele.value) != null)\n return {\n label: ele.label,\n value: getProjection(ele.value)!,\n precision: ele.precision ?? DEFAULT_PRECISION\n };\n return [];\n });\n return availableProjections;\n }, [projections]);\n}\n"],"names":["getProjection","validationResult"],"mappings":";;;;;;;;;;;;;;AAwBA,MAAM,iBAAoB,GAAA,CAAA,CAAA;AAC1B,MAAM,mBAAsB,GAAA;AAAA,EACxB;AAAA,IACI,KAAO,EAAA,QAAA;AAAA,IACP,KAAA,EAAOA,IAAc,WAAW,CAAA;AAAA,IAChC,SAAW,EAAA,CAAA;AAAA,GACf;AAAA,EACA;AAAA,IACI,KAAO,EAAA,cAAA;AAAA,IACP,KAAA,EAAOA,IAAc,WAAW,CAAA;AAAA,IAChC,SAAW,EAAA,CAAA;AAAA,GACf;AACJ,CAAA,CAAA;AA+Fa,MAAA,eAAA,GAA4C,CAAC,KAAU,KAAA;AAChE,EAAM,MAAA;AAAA,IACF,QAAU,EAAA,YAAA;AAAA,IACV,OAAA;AAAA,IACA,WAAc,GAAA,mBAAA;AAAA,IACd,KAAA;AAAA,IACA,WAAc,GAAA,EAAA;AAAA,GACd,GAAA,KAAA,CAAA;AACJ,EAAA,MAAM,EAAE,cAAA,EAAmB,GAAA,uBAAA,CAAwB,oBAAoB,KAAK,CAAA,CAAA;AAC5E,EAAA,MAAM,EAAE,GAAA,EAAQ,GAAA,WAAA,CAAY,KAAK,CAAA,CAAA;AACjC,EAAA,MAAM,OAAO,OAAQ,EAAA,CAAA;AACrB,EAAA,MAAM,gBAAgB,mBAAoB,CAAA,MAAM,KAAK,UAAY,EAAA,CAAC,G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AAc,GAAA,SAAA,CAAU,SAAW,EAAA,aAAA,EAAe,mBAAmB,KAAK,CAAA,CAAA;AAChF,MAAA,MAAM,SAAY,GAAA,iBAAA,CAAkB,WAAa,EAAA,kBAAA,CAAmB,WAAW,IAAI,CAAA,CAAA;AACnF,MAAA,IAAA,CAAK,UAAU,KAAQ,GAAA,SAAA,CAAA;AAAA,KAC3B;AAAA,GACJ;AACJ,CAAA;AAKA,SAAS,mBAAmB,WAAgC,EAAA;AACxD,EAAA,OAAO,QAAQ,MAAM;AAEjB,IAAA,MAAM,oBAAyC,GAAA,WAAA,CAAY,OAAQ,CAAA,CAAC,GAAQ,KAAA;AACxE,MAAI,IAAAD,GAAA,CAAc,GAAI,CAAA,KAAK,CAAK,IAAA,IAAA;AAC5B,QAAO,OAAA;AAAA,UACH,OAAO,GAAI,CAAA,KAAA;AAAA,UACX,KAAA,EAAOA,GAAc,CAAA,GAAA,CAAI,KAAK,CAAA;AAAA,UAC9B,SAAA,EAAW,IAAI,SAAa,IAAA,iBAAA;AAAA,SAChC,CAAA;AACJ,MAAA,OAAO,EAAC,CAAA;AAAA,KACX,CAAA,CAAA;AACD,IAAO,OAAA,oBAAA,CAAA;AAAA,GACX,EAAG,CAAC,WAAW,CAAC,CAAA,CAAA;AACpB;;;;"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Coordinate } from "ol/coordinate";
|
|
2
|
+
export declare function CoordinateInputField(props: {
|
|
3
|
+
isInputValid: boolean;
|
|
4
|
+
coordinateSearchInput: string;
|
|
5
|
+
setCoordinateSearchInput: (searchInput: string) => void;
|
|
6
|
+
placeholder: string | Coordinate;
|
|
7
|
+
placeholderString: string;
|
|
8
|
+
onClear: (() => void) | undefined;
|
|
9
|
+
onEnter: () => void;
|
|
10
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
2
|
+
import { CloseIcon, CopyIcon } from '@chakra-ui/icons';
|
|
3
|
+
import { Input, InputGroup, InputRightElement, Tooltip, IconButton } from '@open-pioneer/chakra-integration';
|
|
4
|
+
import { useIntl } from './_virtual/_virtual-pioneer-module_react-hooks.js';
|
|
5
|
+
|
|
6
|
+
function CoordinateInputField(props) {
|
|
7
|
+
const {
|
|
8
|
+
isInputValid,
|
|
9
|
+
coordinateSearchInput,
|
|
10
|
+
setCoordinateSearchInput,
|
|
11
|
+
placeholder,
|
|
12
|
+
placeholderString,
|
|
13
|
+
onClear,
|
|
14
|
+
onEnter
|
|
15
|
+
} = props;
|
|
16
|
+
const intl = useIntl();
|
|
17
|
+
const leftInput = /* @__PURE__ */ jsx(
|
|
18
|
+
Input,
|
|
19
|
+
{
|
|
20
|
+
type: "text",
|
|
21
|
+
value: coordinateSearchInput,
|
|
22
|
+
onChange: (e) => {
|
|
23
|
+
setCoordinateSearchInput(e.target.value);
|
|
24
|
+
},
|
|
25
|
+
isInvalid: !isInputValid,
|
|
26
|
+
backgroundColor: !isInputValid ? "red.100" : "undefined",
|
|
27
|
+
placeholder: placeholderString,
|
|
28
|
+
errorBorderColor: "red.500",
|
|
29
|
+
"aria-label": intl.formatMessage({
|
|
30
|
+
id: "coordinateInput.ariaLabel"
|
|
31
|
+
}),
|
|
32
|
+
borderRightRadius: 0,
|
|
33
|
+
onKeyDown: (e) => {
|
|
34
|
+
if (e.key == "Enter") {
|
|
35
|
+
onEnter();
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
);
|
|
40
|
+
let rightButton = null;
|
|
41
|
+
if (coordinateSearchInput !== "") {
|
|
42
|
+
rightButton = /* @__PURE__ */ jsx(
|
|
43
|
+
RightButton,
|
|
44
|
+
{
|
|
45
|
+
className: "coordinate-input-clear-button",
|
|
46
|
+
label: intl.formatMessage({
|
|
47
|
+
id: "coordinateInput.clearPlaceholder"
|
|
48
|
+
}),
|
|
49
|
+
onClick: () => {
|
|
50
|
+
setCoordinateSearchInput("");
|
|
51
|
+
onClear?.();
|
|
52
|
+
},
|
|
53
|
+
icon: /* @__PURE__ */ jsx(CloseIcon, {})
|
|
54
|
+
}
|
|
55
|
+
);
|
|
56
|
+
} else if (typeof placeholder === "object") {
|
|
57
|
+
rightButton = /* @__PURE__ */ jsx(
|
|
58
|
+
RightButton,
|
|
59
|
+
{
|
|
60
|
+
className: "coordinate-input-copy-button",
|
|
61
|
+
label: intl.formatMessage({
|
|
62
|
+
id: "coordinateInput.copyPlaceholder"
|
|
63
|
+
}),
|
|
64
|
+
onClick: () => {
|
|
65
|
+
navigator.clipboard.writeText(placeholderString);
|
|
66
|
+
},
|
|
67
|
+
icon: /* @__PURE__ */ jsx(CopyIcon, {})
|
|
68
|
+
}
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
return /* @__PURE__ */ jsxs(InputGroup, { className: "coordinate-input-field-group", children: [
|
|
72
|
+
leftInput,
|
|
73
|
+
rightButton
|
|
74
|
+
] });
|
|
75
|
+
}
|
|
76
|
+
function RightButton(props) {
|
|
77
|
+
const { className, label, onClick, icon } = props;
|
|
78
|
+
return /* @__PURE__ */ jsx(InputRightElement, { children: /* @__PURE__ */ jsx(Tooltip, { label, children: /* @__PURE__ */ jsx(
|
|
79
|
+
IconButton,
|
|
80
|
+
{
|
|
81
|
+
className,
|
|
82
|
+
size: "sm",
|
|
83
|
+
onClick,
|
|
84
|
+
padding: 0,
|
|
85
|
+
icon,
|
|
86
|
+
"aria-label": label
|
|
87
|
+
}
|
|
88
|
+
) }) });
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export { CoordinateInputField };
|
|
92
|
+
//# sourceMappingURL=CoordinateInputField.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CoordinateInputField.js","sources":["CoordinateInputField.tsx"],"sourcesContent":["// SPDX-FileCopyrightText: 2023 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { CloseIcon, CopyIcon } from \"@chakra-ui/icons\";\nimport {\n IconButton,\n Input,\n InputGroup,\n InputRightElement,\n Tooltip\n} from \"@open-pioneer/chakra-integration\";\nimport { Coordinate } from \"ol/coordinate\";\nimport { useIntl } from \"open-pioneer:react-hooks\";\n\nexport function CoordinateInputField(props: {\n isInputValid: boolean;\n coordinateSearchInput: string;\n setCoordinateSearchInput: (searchInput: string) => void;\n placeholder: string | Coordinate;\n placeholderString: string;\n onClear: (() => void) | undefined;\n onEnter: () => void;\n}) {\n const {\n isInputValid,\n coordinateSearchInput,\n setCoordinateSearchInput,\n placeholder,\n placeholderString,\n onClear,\n onEnter\n } = props;\n const intl = useIntl();\n\n const leftInput = (\n <Input\n type=\"text\"\n value={coordinateSearchInput}\n onChange={(e) => {\n setCoordinateSearchInput(e.target.value);\n }}\n isInvalid={!isInputValid}\n backgroundColor={!isInputValid ? \"red.100\" : \"undefined\"}\n placeholder={placeholderString}\n errorBorderColor=\"red.500\"\n aria-label={intl.formatMessage({\n id: \"coordinateInput.ariaLabel\"\n })}\n borderRightRadius={0}\n onKeyDown={(e) => {\n if (e.key == \"Enter\") {\n onEnter();\n }\n }}\n />\n );\n\n let rightButton = null;\n if (coordinateSearchInput !== \"\") {\n rightButton = (\n <RightButton\n className=\"coordinate-input-clear-button\"\n label={intl.formatMessage({\n id: \"coordinateInput.clearPlaceholder\"\n })}\n onClick={() => {\n setCoordinateSearchInput(\"\");\n onClear?.();\n }}\n icon={<CloseIcon />}\n />\n );\n } else if (typeof placeholder === \"object\") {\n rightButton = (\n <RightButton\n className=\"coordinate-input-copy-button\"\n label={intl.formatMessage({\n id: \"coordinateInput.copyPlaceholder\"\n })}\n onClick={() => {\n navigator.clipboard.writeText(placeholderString);\n }}\n icon={<CopyIcon />}\n />\n );\n }\n return (\n <InputGroup className=\"coordinate-input-field-group\">\n {leftInput}\n {rightButton}\n </InputGroup>\n );\n}\n\nfunction RightButton(props: {\n className: string;\n label: string;\n onClick: () => void;\n icon: JSX.Element;\n}) {\n const { className, label, onClick, icon } = props;\n return (\n <InputRightElement>\n <Tooltip label={label}>\n <IconButton\n className={className}\n size=\"sm\"\n onClick={onClick}\n padding={0}\n icon={icon}\n aria-label={label}\n />\n </Tooltip>\n </InputRightElement>\n );\n}\n"],"names":[],"mappings":";;;;;AAaO,SAAS,qBAAqB,KAQlC,EAAA;AACC,EAAM,MAAA;AAAA,IACF,YAAA;AAAA,IACA,qBAAA;AAAA,IACA,wBAAA;AAAA,IACA,WAAA;AAAA,IACA,iBAAA;AAAA,IACA,OAAA;AAAA,IACA,OAAA;AAAA,GACA,GAAA,KAAA,CAAA;AACJ,EAAA,MAAM,OAAO,OAAQ,EAAA,CAAA;AAErB,EAAA,MAAM,SACF,mBAAA,GAAA;AAAA,IAAC,KAAA;AAAA,IAAA;AAAA,MACG,IAAK,EAAA,MAAA;AAAA,MACL,KAAO,EAAA,qBAAA;AAAA,MACP,QAAA,EAAU,CAAC,CAAM,KAAA;AACb,QAAyB,wBAAA,CAAA,CAAA,CAAE,OAAO,KAAK,CAAA,CAAA;AAAA,OAC3C;AAAA,MACA,WAAW,CAAC,YAAA;AAAA,MACZ,eAAA,EAAiB,CAAC,YAAA,GAAe,SAAY,GAAA,WAAA;AAAA,MAC7C,WAAa,EAAA,iBAAA;AAAA,MACb,gBAAiB,EAAA,SAAA;AAAA,MACjB,YAAA,EAAY,KAAK,aAAc,CAAA;AAAA,QAC3B,EAAI,EAAA,2BAAA;AAAA,OACP,CAAA;AAAA,MACD,iBAAmB,EAAA,CAAA;AAAA,MACnB,SAAA,EAAW,CAAC,CAAM,KAAA;AACd,QAAI,IAAA,CAAA,CAAE,OAAO,OAAS,EAAA;AAClB,UAAQ,OAAA,EAAA,CAAA;AAAA,SACZ;AAAA,OACJ;AAAA,KAAA;AAAA,GACJ,CAAA;AAGJ,EAAA,IAAI,WAAc,GAAA,IAAA,CAAA;AAClB,EAAA,IAAI,0BAA0B,EAAI,EAAA;AAC9B,IACI,WAAA,mBAAA,GAAA;AAAA,MAAC,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AAAA,MACA,OAAS,EAAA,CAAA;AAAA,MACT,IAAA;AAAA,MACA,YAAY,EAAA,KAAA;AAAA,KAAA;AAAA,KAEpB,CACJ,EAAA,CAAA,CAAA;AAER;;;;"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { MapModelProps } from "@open-pioneer/map";
|
|
2
|
+
import { CommonComponentProps } from "@open-pioneer/react-utils";
|
|
3
|
+
import { FC } from "react";
|
|
4
|
+
import { CoordinatesSelectEvent, ProjectionInput } from "./CoordinateInput";
|
|
5
|
+
/**
|
|
6
|
+
* Properties for the {@link CoordinateSearch}.
|
|
7
|
+
*/
|
|
8
|
+
export interface CoordinateSearchProps extends CommonComponentProps, MapModelProps {
|
|
9
|
+
/**
|
|
10
|
+
* Searchable projections, only projections that are known by the map as projection are shown.
|
|
11
|
+
* Each projection can have an individual precision of coordinates. If no precision is given, the default precision is used.
|
|
12
|
+
*/
|
|
13
|
+
projections?: ProjectionInput[];
|
|
14
|
+
/**
|
|
15
|
+
* Optional event that gets called if some coordinates are entered or projection is changed by the user.
|
|
16
|
+
*/
|
|
17
|
+
onSelect?: (event: CoordinatesSelectEvent) => void;
|
|
18
|
+
/**
|
|
19
|
+
* Optional event that gets called if the input is cleared.
|
|
20
|
+
*/
|
|
21
|
+
onClear?: () => void;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The `CoordinateSearch` component can be used in an app to search for entered coordinates in a selected projection
|
|
25
|
+
*/
|
|
26
|
+
export declare const CoordinateSearch: FC<CoordinateSearchProps>;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { useMapModel } from '@open-pioneer/map';
|
|
3
|
+
import { useCommonComponentProps } from '@open-pioneer/react-utils';
|
|
4
|
+
import { useState, useEffect } from 'react';
|
|
5
|
+
import { unByKey } from 'ol/Observable.js';
|
|
6
|
+
import { CoordinateInput } from './CoordinateInput.js';
|
|
7
|
+
|
|
8
|
+
const CoordinateSearch = (props) => {
|
|
9
|
+
const { onSelect, onClear, projections } = props;
|
|
10
|
+
const { containerProps } = useCommonComponentProps("coordinate-search", props);
|
|
11
|
+
const { map } = useMapModel(props);
|
|
12
|
+
const olMap = map?.olMap;
|
|
13
|
+
const { coordinates } = useCoordinates(olMap);
|
|
14
|
+
return /* @__PURE__ */ jsx(
|
|
15
|
+
CoordinateInput,
|
|
16
|
+
{
|
|
17
|
+
...containerProps,
|
|
18
|
+
mapId: props.mapId,
|
|
19
|
+
onSelect: (event) => {
|
|
20
|
+
if (!map) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
olMap?.getView().setCenter(event.coords);
|
|
24
|
+
onSelect?.(event);
|
|
25
|
+
},
|
|
26
|
+
onClear,
|
|
27
|
+
placeholder: coordinates ? coordinates : "",
|
|
28
|
+
projections
|
|
29
|
+
}
|
|
30
|
+
);
|
|
31
|
+
};
|
|
32
|
+
function useCoordinates(map) {
|
|
33
|
+
const [coordinates, setCoordinates] = useState();
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
if (!map) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const eventsKey = map.on("pointermove", (evt) => {
|
|
39
|
+
setCoordinates(evt.coordinate);
|
|
40
|
+
});
|
|
41
|
+
return () => unByKey(eventsKey);
|
|
42
|
+
}, [map]);
|
|
43
|
+
return { coordinates };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export { CoordinateSearch };
|
|
47
|
+
//# sourceMappingURL=CoordinateSearch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CoordinateSearch.js","sources":["CoordinateSearch.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 { CommonComponentProps, useCommonComponentProps } from \"@open-pioneer/react-utils\";\nimport { FC, useEffect, useState } from \"react\";\nimport { Coordinate } from \"ol/coordinate\";\nimport { EventsKey } from \"ol/events\";\nimport { unByKey } from \"ol/Observable\";\nimport OlMap from \"ol/Map\";\nimport { CoordinateInput, CoordinatesSelectEvent, ProjectionInput } from \"./CoordinateInput\";\n\n/**\n * Properties for the {@link CoordinateSearch}.\n */\nexport interface CoordinateSearchProps extends CommonComponentProps, MapModelProps {\n /**\n * Searchable projections, only projections that are known by the map as projection are shown.\n * Each projection can have an individual precision of coordinates. If no precision is given, the default precision is used.\n */\n projections?: ProjectionInput[];\n\n /**\n * Optional event that gets called if some coordinates are entered or projection is changed by the user.\n */\n onSelect?: (event: CoordinatesSelectEvent) => void;\n\n /**\n * Optional event that gets called if the input is cleared.\n */\n onClear?: () => void;\n}\n\n/**\n * The `CoordinateSearch` component can be used in an app to search for entered coordinates in a selected projection\n */\nexport const CoordinateSearch: FC<CoordinateSearchProps> = (props) => {\n const { onSelect, onClear, projections } = props;\n const { containerProps } = useCommonComponentProps(\"coordinate-search\", props);\n const { map } = useMapModel(props);\n const olMap = map?.olMap;\n\n const { coordinates } = useCoordinates(olMap); // coordinates of the pointer in the map\n\n return (\n <CoordinateInput\n {...containerProps}\n mapId={props.mapId}\n onSelect={(event: CoordinatesSelectEvent) => {\n if (!map) {\n return;\n }\n\n olMap?.getView().setCenter(event.coords);\n onSelect?.(event);\n }}\n onClear={onClear}\n placeholder={coordinates ? coordinates : \"\"}\n projections={projections}\n />\n );\n};\n\n/* get the current coordinates of the pointer on the map */\nfunction useCoordinates(map: OlMap | undefined): { coordinates: Coordinate | undefined } {\n const [coordinates, setCoordinates] = useState<Coordinate | undefined>();\n\n useEffect(() => {\n if (!map) {\n return;\n }\n\n const eventsKey: EventsKey = map.on(\"pointermove\", (evt) => {\n setCoordinates(evt.coordinate);\n });\n\n return () => unByKey(eventsKey);\n }, [map]);\n\n return { coordinates };\n}\n"],"names":[],"mappings":";;;;;;;AAmCa,MAAA,gBAAA,GAA8C,CAAC,KAAU,KAAA;AAClE,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