@open-pioneer/coordinate-search 1.0.0 → 1.2.0-dev.20251128143231
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 +26 -0
- package/CoordinateInput.js +6 -2
- package/CoordinateInput.js.map +1 -1
- package/coordinates.js +6 -3
- package/coordinates.js.map +1 -1
- package/package.json +10 -10
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
# @open-pioneer/coordinate-search
|
|
2
2
|
|
|
3
|
+
## 1.2.0-dev.20251128143231
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 279ca67: Use `workspace:*` instead of `workspace:^` for local package references as default. This ensures that trails packages from this repository are always referenced with their exact version to avoid potential issues with version mismatches. If a project specifically wants to use other versions for some trails packages, a pnpm override can be used to force other versions.
|
|
8
|
+
- Updated dependencies [279ca67]
|
|
9
|
+
- @open-pioneer/map@1.2.0-dev.20251128143231
|
|
10
|
+
|
|
11
|
+
## 1.1.0
|
|
12
|
+
|
|
13
|
+
### Minor Changes
|
|
14
|
+
|
|
15
|
+
- 10338fa: Update OpenLayers to 10.7.0
|
|
16
|
+
- a8b8a36: Update trails core packages to 4.3.0
|
|
17
|
+
- 10338fa: Update Chakra to 3.29.0
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- fce7fa9: Implement stricter null safety checks.
|
|
22
|
+
- Updated dependencies [fce7fa9]
|
|
23
|
+
- Updated dependencies [10338fa]
|
|
24
|
+
- Updated dependencies [a8b8a36]
|
|
25
|
+
- Updated dependencies [10338fa]
|
|
26
|
+
- Updated dependencies [c38b619]
|
|
27
|
+
- @open-pioneer/map@1.1.0
|
|
28
|
+
|
|
3
29
|
## 1.0.0
|
|
4
30
|
|
|
5
31
|
### Minor Changes
|
package/CoordinateInput.js
CHANGED
|
@@ -17,11 +17,13 @@ const DEFAULT_PRECISION = 3;
|
|
|
17
17
|
const DEFAULT_PROJECTIONS = [
|
|
18
18
|
{
|
|
19
19
|
label: "WGS 84",
|
|
20
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
20
21
|
value: get("EPSG:4326"),
|
|
21
22
|
precision: 3
|
|
22
23
|
},
|
|
23
24
|
{
|
|
24
25
|
label: "Web Mercator",
|
|
26
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
25
27
|
value: get("EPSG:3857"),
|
|
26
28
|
precision: 2
|
|
27
29
|
}
|
|
@@ -41,6 +43,7 @@ const CoordinateInput = (props) => {
|
|
|
41
43
|
const availableProjections = useProjectionItems(projections);
|
|
42
44
|
const [selectedProjection, setSelectedProjection] = useState(
|
|
43
45
|
// choose first option initially
|
|
46
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
44
47
|
availableProjections[0]
|
|
45
48
|
);
|
|
46
49
|
const onSelect = useEvent((coordinatesResult) => {
|
|
@@ -198,10 +201,11 @@ class StateModel {
|
|
|
198
201
|
function useProjectionItems(projections) {
|
|
199
202
|
return useMemo(() => {
|
|
200
203
|
const availableProjections = projections.flatMap((ele) => {
|
|
201
|
-
|
|
204
|
+
const projection = get(ele.value);
|
|
205
|
+
if (projection != null)
|
|
202
206
|
return {
|
|
203
207
|
label: ele.label,
|
|
204
|
-
value:
|
|
208
|
+
value: projection,
|
|
205
209
|
precision: ele.precision ?? DEFAULT_PRECISION
|
|
206
210
|
};
|
|
207
211
|
return [];
|
package/CoordinateInput.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CoordinateInput.js","sources":["CoordinateInput.tsx"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { Flex, Group } from \"@chakra-ui/react\";\nimport { computed, Reactive, reactive } from \"@conterra/reactivity-core\";\nimport { Tooltip } from \"@open-pioneer/chakra-snippets/tooltip\";\nimport { MapModelProps, useMapModelValue } 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, 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 = useMapModelValue(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 errorMessage = !isInputValid\n ? intl.formatMessage({ id: validationResult.kind })\n : undefined;\n\n const onEnter = useEvent(() => {\n onSelect(validationResult);\n });\n\n return (\n <Flex {...containerProps} flexDirection={\"row\"} flexDir={\"row\"}>\n <Tooltip\n content={errorMessage}\n showArrow\n open={!isInputValid}\n // explicity mount / unmount the tooltip.\n // Previously an empty tooltip could be shown even though \"open\" was false.\n present={!isInputValid}\n >\n <Group className=\"coordinate-input-group\" attached w=\"full\">\n <ProjectionSelect\n currentProjection={selectedProjection}\n projections={availableProjections}\n onProjectionChange={setSelectedProjection}\n />\n <CoordinateInputField\n coordinateSearchInput={coordinateSearchInput}\n setCoordinateSearchInput={setCoordinateSearchInput}\n placeholder={placeholder}\n placeholderString={placeholderString}\n errorMessage={errorMessage}\n onClear={onClear}\n onEnter={onEnter}\n />\n </Group>\n </Tooltip>\n </Flex>\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":";;;;;;;;;;;;;;;AAkBA,MAAM,iBAAA,GAAoB,CAAA;AAC1B,MAAM,mBAAA,GAAsB;AAAA,EACxB;AAAA,IACI,KAAA,EAAO,QAAA;AAAA,IACP,KAAA,EAAOA,IAAc,WAAW,CAAA;AAAA,IAChC,SAAA,EAAW;AAAA,GACf;AAAA,EACA;AAAA,IACI,KAAA,EAAO,cAAA;AAAA,IACP,KAAA,EAAOA,IAAc,WAAW,CAAA;AAAA,IAChC,SAAA,EAAW;AAAA;AAEnB,CAAA;AA+FO,MAAM,eAAA,GAA4C,CAAC,KAAA,KAAU;AAChE,EAAA,MAAM;AAAA,IACF,QAAA,EAAU,YAAA;AAAA,IACV,OAAA;AAAA,IACA,WAAA,GAAc,mBAAA;AAAA,IACd,KAAA;AAAA,IACA,WAAA,GAAc;AAAA,GAClB,GAAI,KAAA;AACJ,EAAA,MAAM,EAAE,cAAA,EAAe,GAAI,uBAAA,CAAwB,oBAAoB,KAAK,CAAA;AAC5E,EAAA,MAAM,GAAA,GAAM,iBAAiB,KAAK,CAAA;AAClC,EAAA,MAAM,OAAO,OAAA,EAAQ;AACrB,EAAA,MAAM,gBAAgB,mBAAA,CAAoB,MAAM,IAAI,UAAA,EAAY,CAAC,GAAG,CAAC,CAAA;AAGrE,EAAA,MAAM,oBAAA,GAAuB,mBAAmB,WAAW,CAAA;AAC3D,EAAA,MAAM,CAAC,kBAAA,EAAoB,qBAAqB,CAAA,GAAI,QAAA;AAAA;AAAA,IAEhD,qBAAqB,CAAC;AAAA,GAC1B;AAGA,EAAA,MAAM,QAAA,GAAW,QAAA,CAAS,CAAC,iBAAA,KAAmC;AAC1D,IAAA,IAAI,CAAC,YAAA,IAAgB,iBAAA,CAAkB,IAAA,KAAS,SAAA,IAAa,iBAA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AAK,mBAAA,CAAoB,KAAA;AACpD,IAAA,MAAM,IAAA,GAAO,KAAK,KAAA,CAAM,KAAA;AACxB,IAAA,IAAI,iBAAiB,SAAA,EAAW;AAE5B,MAAA,MAAM,WAAA,GAAc,SAAA,CAAU,SAAA,EAAW,aAAA,EAAe,mBAAmB,KAAK,CAAA;AAChF,MAAA,MAAM,SAAA,GAAY,iBAAA,CAAkB,WAAA,EAAa,kBAAA,CAAmB,WAAW,IAAI,CAAA;AACnF,MAAA,IAAA,CAAK,UAAU,KAAA,GAAQ,SAAA;AAAA,IAC3B;AAAA,EACJ;AACJ;AAKA,SAAS,mBAAmB,WAAA,EAAgC;AACxD,EAAA,OAAO,QAAQ,MAAM;AAEjB,IAAA,MAAM,oBAAA,GAAyC,WAAA,CAAY,OAAA,CAAQ,CAAC,GAAA,KAAQ;AACxE,MAAA,IAAID,GAAA,CAAc,GAAA,CAAI,KAAK,CAAA,IAAK,IAAA;AAC5B,QAAA,OAAO;AAAA,UACH,OAAO,GAAA,CAAI,KAAA;AAAA,UACX,KAAA,EAAOA,GAAA,CAAc,GAAA,CAAI,KAAK,CAAA;AAAA,UAC9B,SAAA,EAAW,IAAI,SAAA,IAAa;AAAA,SAChC;AACJ,MAAA,OAAO,EAAC;AAAA,IACZ,CAAC,CAAA;AACD,IAAA,OAAO,oBAAA;AAAA,EACX,CAAA,EAAG,CAAC,WAAW,CAAC,CAAA;AACpB;;;;"}
|
|
1
|
+
{"version":3,"file":"CoordinateInput.js","sources":["CoordinateInput.tsx"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { Flex, Group } from \"@chakra-ui/react\";\nimport { computed, Reactive, reactive } from \"@conterra/reactivity-core\";\nimport { Tooltip } from \"@open-pioneer/chakra-snippets/tooltip\";\nimport { MapModelProps, useMapModelValue } 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, 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 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n value: getProjection(\"EPSG:4326\")!,\n precision: 3\n },\n {\n label: \"Web Mercator\",\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\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 = useMapModelValue(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 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\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 errorMessage = !isInputValid\n ? intl.formatMessage({ id: validationResult.kind })\n : undefined;\n\n const onEnter = useEvent(() => {\n onSelect(validationResult);\n });\n\n return (\n <Flex {...containerProps} flexDirection={\"row\"} flexDir={\"row\"}>\n <Tooltip\n content={errorMessage}\n showArrow\n open={!isInputValid}\n // explicity mount / unmount the tooltip.\n // Previously an empty tooltip could be shown even though \"open\" was false.\n present={!isInputValid}\n >\n <Group className=\"coordinate-input-group\" attached w=\"full\">\n <ProjectionSelect\n currentProjection={selectedProjection}\n projections={availableProjections}\n onProjectionChange={setSelectedProjection}\n />\n <CoordinateInputField\n coordinateSearchInput={coordinateSearchInput}\n setCoordinateSearchInput={setCoordinateSearchInput}\n placeholder={placeholder}\n placeholderString={placeholderString}\n errorMessage={errorMessage}\n onClear={onClear}\n onEnter={onEnter}\n />\n </Group>\n </Tooltip>\n </Flex>\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 const projection = getProjection(ele.value);\n if (projection != null)\n return {\n label: ele.label,\n value: projection,\n precision: ele.precision ?? DEFAULT_PRECISION\n };\n return [];\n });\n return availableProjections;\n }, [projections]);\n}\n"],"names":["getProjection","validationResult"],"mappings":";;;;;;;;;;;;;;;AAkBA,MAAM,iBAAA,GAAoB,CAAA;AAC1B,MAAM,mBAAA,GAAsB;AAAA,EACxB;AAAA,IACI,KAAA,EAAO,QAAA;AAAA;AAAA,IAEP,KAAA,EAAOA,IAAc,WAAW,CAAA;AAAA,IAChC,SAAA,EAAW;AAAA,GACf;AAAA,EACA;AAAA,IACI,KAAA,EAAO,cAAA;AAAA;AAAA,IAEP,KAAA,EAAOA,IAAc,WAAW,CAAA;AAAA,IAChC,SAAA,EAAW;AAAA;AAEnB,CAAA;AA+FO,MAAM,eAAA,GAA4C,CAAC,KAAA,KAAU;AAChE,EAAA,MAAM;AAAA,IACF,QAAA,EAAU,YAAA;AAAA,IACV,OAAA;AAAA,IACA,WAAA,GAAc,mBAAA;AAAA,IACd,KAAA;AAAA,IACA,WAAA,GAAc;AAAA,GAClB,GAAI,KAAA;AACJ,EAAA,MAAM,EAAE,cAAA,EAAe,GAAI,uBAAA,CAAwB,oBAAoB,KAAK,CAAA;AAC5E,EAAA,MAAM,GAAA,GAAM,iBAAiB,KAAK,CAAA;AAClC,EAAA,MAAM,OAAO,OAAA,EAAQ;AACrB,EAAA,MAAM,gBAAgB,mBAAA,CAAoB,MAAM,IAAI,UAAA,EAAY,CAAC,GAAG,CAAC,CAAA;AAGrE,EAAA,MAAM,oBAAA,GAAuB,mBAAmB,WAAW,CAAA;AAC3D,EAAA,MAAM,CAAC,kBAAA,EAAoB,qBAAqB,CAAA,GAAI,QAAA;AAAA;AAAA;AAAA,IAGhD,qBAAqB,CAAC;AAAA,GAC1B;AAGA,EAAA,MAAM,QAAA,GAAW,QAAA,CAAS,CAAC,iBAAA,KAAmC;AAC1D,IAAA,IAAI,CAAC,YAAA,IAAgB,iB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KAAA;AAC1C,IAAA,MAAM,kBAAA,GAAqB,KAAK,mBAAA,CAAoB,KAAA;AACpD,IAAA,MAAM,IAAA,GAAO,KAAK,KAAA,CAAM,KAAA;AACxB,IAAA,IAAI,iBAAiB,SAAA,EAAW;AAE5B,MAAA,MAAM,WAAA,GAAc,SAAA,CAAU,SAAA,EAAW,aAAA,EAAe,mBAAmB,KAAK,CAAA;AAChF,MAAA,MAAM,SAAA,GAAY,iBAAA,CAAkB,WAAA,EAAa,kBAAA,CAAmB,WAAW,IAAI,CAAA;AACnF,MAAA,IAAA,CAAK,UAAU,KAAA,GAAQ,SAAA;AAAA,IAC3B;AAAA,EACJ;AACJ;AAKA,SAAS,mBAAmB,WAAA,EAAgC;AACxD,EAAA,OAAO,QAAQ,MAAM;AAEjB,IAAA,MAAM,oBAAA,GAAyC,WAAA,CAAY,OAAA,CAAQ,CAAC,GAAA,KAAQ;AACxE,MAAA,MAAM,UAAA,GAAaD,GAAA,CAAc,GAAA,CAAI,KAAK,CAAA;AAC1C,MAAA,IAAI,UAAA,IAAc,IAAA;AACd,QAAA,OAAO;AAAA,UACH,OAAO,GAAA,CAAI,KAAA;AAAA,UACX,KAAA,EAAO,UAAA;AAAA,UACP,SAAA,EAAW,IAAI,SAAA,IAAa;AAAA,SAChC;AACJ,MAAA,OAAO,EAAC;AAAA,IACZ,CAAC,CAAA;AACD,IAAA,OAAO,oBAAA;AAAA,EACX,CAAA,EAAG,CAAC,WAAW,CAAC,CAAA;AACpB;;;;"}
|
package/coordinates.js
CHANGED
|
@@ -11,7 +11,7 @@ function parseCoordinates(input, numberParser, projection) {
|
|
|
11
11
|
return err("tooltip.spaceOne");
|
|
12
12
|
}
|
|
13
13
|
const splitCoords = input.split(" ");
|
|
14
|
-
if (splitCoords
|
|
14
|
+
if (splitCoords[0] == void 0 || splitCoords[1] == void 0 || splitCoords[0] == "" || splitCoords[1] == "") {
|
|
15
15
|
return err("tooltip.2coords");
|
|
16
16
|
}
|
|
17
17
|
const coordsString1 = numberParser.parseNumber(splitCoords[0]);
|
|
@@ -44,14 +44,17 @@ function err(kind) {
|
|
|
44
44
|
return { kind };
|
|
45
45
|
}
|
|
46
46
|
function checkIfCoordsInProjectionsExtent(projection, coords) {
|
|
47
|
-
const extent = projection
|
|
47
|
+
const extent = projection?.getExtent();
|
|
48
48
|
if (!extent || extent.length !== 4) {
|
|
49
49
|
return true;
|
|
50
50
|
}
|
|
51
51
|
if (!coords || coords.length !== 2) {
|
|
52
52
|
throw new Error(`Internal error: invalid coordinates ${coords}.`);
|
|
53
53
|
}
|
|
54
|
-
return
|
|
54
|
+
return (
|
|
55
|
+
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
56
|
+
extent[0] <= coords[0] && extent[1] <= coords[1] && extent[2] >= coords[0] && extent[3] >= coords[1]
|
|
57
|
+
);
|
|
55
58
|
}
|
|
56
59
|
function formatCoordinates(coordinates, precision, intl) {
|
|
57
60
|
if (coordinates[0] == null || coordinates[1] == null) {
|
package/coordinates.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"coordinates.js","sources":["coordinates.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { NumberParserService, PackageIntl } from \"@open-pioneer/runtime\";\nimport { get as getProjection, Projection, transform } from \"ol/proj\";\nimport { createLogger } from \"@open-pioneer/core\";\nconst LOG = createLogger(\"coordinate-search\");\n\nexport interface ParseSuccess {\n kind: \"success\";\n projection: Projection;\n coordinates: [number, number];\n}\n\nexport interface ParseError {\n // Double duty as i18n message at the moment\n kind:\n | \"empty\"\n | \"tooltip.space\"\n | \"tooltip.spaceOne\"\n | \"tooltip.2coords\"\n | \"tooltip.invalidNumbers\"\n | \"tooltip.extent\"\n | \"tooltip.projection\";\n}\n\nexport type ParseResult = ParseSuccess | ParseError;\n\nexport function parseCoordinates(\n input: string,\n numberParser: NumberParserService,\n projection: Projection\n): ParseResult {\n if (input == \"\") return err(\"empty\");\n\n if (!input.includes(\" \")) {\n return err(\"tooltip.space\");\n }\n if (input.indexOf(\" \") != input.lastIndexOf(\" \")) {\n return err(\"tooltip.spaceOne\");\n }\n\n const splitCoords = input.split(\" \");\n if (splitCoords
|
|
1
|
+
{"version":3,"file":"coordinates.js","sources":["coordinates.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { NumberParserService, PackageIntl } from \"@open-pioneer/runtime\";\nimport { get as getProjection, Projection, transform } from \"ol/proj\";\nimport { createLogger } from \"@open-pioneer/core\";\nimport { Coordinate } from \"ol/coordinate\";\nconst LOG = createLogger(\"coordinate-search\");\n\nexport interface ParseSuccess {\n kind: \"success\";\n projection: Projection;\n coordinates: [number, number];\n}\n\nexport interface ParseError {\n // Double duty as i18n message at the moment\n kind:\n | \"empty\"\n | \"tooltip.space\"\n | \"tooltip.spaceOne\"\n | \"tooltip.2coords\"\n | \"tooltip.invalidNumbers\"\n | \"tooltip.extent\"\n | \"tooltip.projection\";\n}\n\nexport type ParseResult = ParseSuccess | ParseError;\n\nexport function parseCoordinates(\n input: string,\n numberParser: NumberParserService,\n projection: Projection\n): ParseResult {\n if (input == \"\") return err(\"empty\");\n\n if (!input.includes(\" \")) {\n return err(\"tooltip.space\");\n }\n if (input.indexOf(\" \") != input.lastIndexOf(\" \")) {\n return err(\"tooltip.spaceOne\");\n }\n\n const splitCoords = input.split(\" \");\n if (\n splitCoords[0] == undefined ||\n splitCoords[1] == undefined ||\n splitCoords[0] == \"\" ||\n splitCoords[1] == \"\"\n ) {\n return err(\"tooltip.2coords\");\n }\n\n const coordsString1 = numberParser.parseNumber(splitCoords[0]);\n const coordsString2 = numberParser.parseNumber(splitCoords[1]);\n\n const coords: [number, number] = [coordsString1, coordsString2];\n if (coords.some((number) => Number.isNaN(number))) {\n return err(\"tooltip.invalidNumbers\");\n }\n try {\n if (!checkIfCoordsInProjectionsExtent(projection, coords)) {\n return err(\"tooltip.extent\");\n }\n\n if (\n !checkIfCoordsInProjectionsExtent(\n getProjection(\"EPSG:4326\"),\n transform(coords, projection, \"EPSG:4326\")\n )\n ) {\n return err(\"tooltip.extent\");\n }\n } catch (e) {\n LOG.warn(\"Failed to check if coordinates are in projection extent\", e);\n return err(\"tooltip.projection\");\n }\n\n return {\n kind: \"success\",\n projection,\n coordinates: coords\n };\n}\n\nfunction err(kind: ParseError[\"kind\"]): ParseError {\n return { kind };\n}\n\n/* validate if the coordinates fit to the extent of the selected projection */\nfunction checkIfCoordsInProjectionsExtent(\n projection: Projection | null,\n coords: Coordinate\n): boolean {\n const extent = projection?.getExtent();\n if (!extent || extent.length !== 4) {\n // Some projections don't have an extent, cannot validate.\n return true;\n }\n if (!coords || coords.length !== 2) {\n throw new Error(`Internal error: invalid coordinates ${coords}.`);\n }\n\n return (\n /* eslint-disable @typescript-eslint/no-non-null-assertion */\n extent[0]! <= coords[0]! &&\n extent[1]! <= coords[1]! &&\n extent[2]! >= coords[0]! &&\n extent[3]! >= coords[1]!\n /* eslint-enable @typescript-eslint/no-non-null-assertion */\n );\n}\n\n/* Formats the coordinates as a string with given precision considering locales */\nexport function formatCoordinates(\n coordinates: number[],\n precision: number,\n intl: PackageIntl\n): string {\n if (coordinates[0] == null || coordinates[1] == null) {\n return \"\";\n }\n\n const [x, y] = coordinates;\n\n const xString = intl.formatNumber(x, {\n maximumFractionDigits: precision,\n minimumFractionDigits: precision\n });\n const yString = intl.formatNumber(y, {\n maximumFractionDigits: precision,\n minimumFractionDigits: precision\n });\n\n return xString + \" \" + yString;\n}\n"],"names":["getProjection"],"mappings":";;;AAMA,MAAM,GAAA,GAAM,aAAa,mBAAmB,CAAA;AAsBrC,SAAS,gBAAA,CACZ,KAAA,EACA,YAAA,EACA,UAAA,EACW;AACX,EAAA,IAAI,KAAA,IAAS,EAAA,EAAI,OAAO,GAAA,CAAI,OAAO,CAAA;AA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AA,CAAa,CAAA,EAAG;AAAA,IACjC,qBAAA,EAAuB,SAAA;AAAA,IACvB,qBAAA,EAAuB;AAAA,GAC1B,CAAA;AACD,EAAA,MAAM,OAAA,GAAU,IAAA,CAAK,YAAA,CAAa,CAAA,EAAG;AAAA,IACjC,qBAAA,EAAuB,SAAA;AAAA,IACvB,qBAAA,EAAuB;AAAA,GAC1B,CAAA;AAED,EAAA,OAAO,UAAU,GAAA,GAAM,OAAA;AAC3B;;;;"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@open-pioneer/coordinate-search",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.2.0-dev.20251128143231",
|
|
5
5
|
"description": "This package provides a UI component to search for entered coordinates in the choosen projection.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"open-pioneer-trails"
|
|
@@ -14,17 +14,17 @@
|
|
|
14
14
|
"directory": "src/packages/coordinate-search"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@chakra-ui/react": "^3.
|
|
18
|
-
"@conterra/reactivity-core": "^0.8.
|
|
19
|
-
"@open-pioneer/chakra-snippets": "^4.
|
|
20
|
-
"@open-pioneer/core": "^4.
|
|
21
|
-
"@open-pioneer/runtime": "^4.
|
|
22
|
-
"@open-pioneer/react-utils": "^4.
|
|
23
|
-
"@open-pioneer/reactivity": "^4.
|
|
24
|
-
"ol": "^10.
|
|
17
|
+
"@chakra-ui/react": "^3.29.0",
|
|
18
|
+
"@conterra/reactivity-core": "^0.8.1",
|
|
19
|
+
"@open-pioneer/chakra-snippets": "^4.3.0",
|
|
20
|
+
"@open-pioneer/core": "^4.3.0",
|
|
21
|
+
"@open-pioneer/runtime": "^4.3.0",
|
|
22
|
+
"@open-pioneer/react-utils": "^4.3.0",
|
|
23
|
+
"@open-pioneer/reactivity": "^4.3.0",
|
|
24
|
+
"ol": "^10.7.0",
|
|
25
25
|
"react": "^19.2.0",
|
|
26
26
|
"react-icons": "^5.5.0",
|
|
27
|
-
"@open-pioneer/map": "
|
|
27
|
+
"@open-pioneer/map": "1.2.0-dev.20251128143231"
|
|
28
28
|
},
|
|
29
29
|
"exports": {
|
|
30
30
|
"./package.json": "./package.json",
|