@open-pioneer/coordinate-search 0.9.0-dev.20250220091855 → 0.9.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 +27 -18
- package/CoordinateInput.js +1 -1
- package/CoordinateInput.js.map +1 -1
- package/CoordinateInputField.js.map +1 -1
- package/CoordinateSearch.js.map +1 -1
- package/ProjectionSelect.d.ts +1 -1
- package/ProjectionSelect.js.map +1 -1
- package/coordinates.js.map +1 -1
- package/package.json +10 -10
- package/usePlaceholder.js.map +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,19 +1,28 @@
|
|
|
1
1
|
# @open-pioneer/coordinate-search
|
|
2
2
|
|
|
3
|
-
## 0.9.0
|
|
3
|
+
## 0.9.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- cb94c75: update dependencies
|
|
4
8
|
|
|
5
9
|
### Patch Changes
|
|
6
10
|
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
-
|
|
10
|
-
|
|
11
|
+
- Updated dependencies [e7fdc5d]
|
|
12
|
+
- Updated dependencies [cb94c75]
|
|
13
|
+
- Updated dependencies [37cd707]
|
|
14
|
+
- Updated dependencies [32ed2cd]
|
|
15
|
+
- Updated dependencies [f327eec]
|
|
16
|
+
- Updated dependencies [f327eec]
|
|
17
|
+
- Updated dependencies [209eb8e]
|
|
18
|
+
- Updated dependencies [d72e42c]
|
|
19
|
+
- @open-pioneer/map@0.9.0
|
|
11
20
|
|
|
12
21
|
## 0.8.0
|
|
13
22
|
|
|
14
23
|
### Minor Changes
|
|
15
24
|
|
|
16
|
-
-
|
|
25
|
+
- 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.
|
|
17
26
|
|
|
18
27
|
```tsx
|
|
19
28
|
<CoordinateSearch mapId="map_id" />
|
|
@@ -25,15 +34,15 @@
|
|
|
25
34
|
|
|
26
35
|
### Patch Changes
|
|
27
36
|
|
|
28
|
-
-
|
|
29
|
-
-
|
|
30
|
-
-
|
|
31
|
-
-
|
|
32
|
-
-
|
|
33
|
-
-
|
|
34
|
-
-
|
|
35
|
-
-
|
|
36
|
-
-
|
|
37
|
-
-
|
|
38
|
-
-
|
|
39
|
-
-
|
|
37
|
+
- 49f0207: Update trails core packages to version 2.4.0
|
|
38
|
+
- Updated dependencies [b717121]
|
|
39
|
+
- Updated dependencies [e7978a8]
|
|
40
|
+
- Updated dependencies [7a5f1e1]
|
|
41
|
+
- Updated dependencies [7ae9f90]
|
|
42
|
+
- Updated dependencies [d8337a6]
|
|
43
|
+
- Updated dependencies [49f0207]
|
|
44
|
+
- Updated dependencies [b2127df]
|
|
45
|
+
- Updated dependencies [2fa8020]
|
|
46
|
+
- Updated dependencies [7ae9f90]
|
|
47
|
+
- Updated dependencies [d8337a6]
|
|
48
|
+
- @open-pioneer/map@0.8.0
|
package/CoordinateInput.js
CHANGED
|
@@ -6,7 +6,7 @@ import { useCommonComponentProps, useEvent } from '@open-pioneer/react-utils';
|
|
|
6
6
|
import { useReactiveSnapshot } from '@open-pioneer/reactivity';
|
|
7
7
|
import { get, transform } from 'ol/proj.js';
|
|
8
8
|
import { useIntl, useService } from './_virtual/_virtual-pioneer-module_react-hooks.js';
|
|
9
|
-
import { useState, useRef, useEffect, useCallback
|
|
9
|
+
import { useState, useRef, useMemo, useEffect, useCallback } from 'react';
|
|
10
10
|
import { CoordinateInputField } from './CoordinateInputField.js';
|
|
11
11
|
import { parseCoordinates, formatCoordinates } from './coordinates.js';
|
|
12
12
|
import { ProjectionSelect } from './ProjectionSelect.js';
|
package/CoordinateInput.js.map
CHANGED
|
@@ -1 +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,GAAG,CAAC,CAAA,CAAA;AAGtE,EAAM,MAAA,o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Ae,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;;;;"}
|
|
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 { 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}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,SAAA,GAAY,KAAK,UAAW,CAAA,KAAA;AAClC,IAAM,MAAA,aAAA,GAAgB,KAAK,cAAe,CAAA,KAAA;AAC1C,IAAM,MAAA,kBAAA,GAAqB,KAAK,mBAAoB,CAAA,KAAA;AACpD,IAAM,MAAA,IAAA,GAAO,KAAK,KAAM,CAAA,KAAA;AACxB,IAAA,IAAI,iBAAiB,SAAW,EAAA;AAE5B,MAAA,MAAM,WAAc,GAAA,SAAA,CAAU,SAAW,EAAA,aAAA,EAAe,mBAAmB,KAAK,CAAA;AAChF,MAAA,MAAM,SAAY,GAAA,iBAAA,CAAkB,WAAa,EAAA,kBAAA,CAAmB,WAAW,IAAI,CAAA;AACnF,MAAA,IAAA,CAAK,UAAU,KAAQ,GAAA,SAAA;AAAA;AAC3B;AAER;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;AAAA,SAChC;AACJ,MAAA,OAAO,EAAC;AAAA,KACX,CAAA;AACD,IAAO,OAAA,oBAAA;AAAA,GACX,EAAG,CAAC,WAAW,CAAC,CAAA;AACpB;;;;"}
|
|
@@ -1 +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:
|
|
1
|
+
{"version":3,"file":"CoordinateInputField.js","sources":["CoordinateInputField.tsx"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 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: React.ReactElement;\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;AAAA,GACA,GAAA,KAAA;AACJ,EAAA,MAAM,OAAO,OAAQ,EAAA;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;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;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;AAAA;AACZ;AACJ;AAAA,GACJ;AAGJ,EAAA,IAAI,WAAc,GAAA,IAAA;AAClB,EAAA,IAAI,0BAA0B,EAAI,EAAA;AA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,YAAY,EAAA;AAAA;AAAA,KAEpB,CACJ,EAAA,CAAA;AAER;;;;"}
|
package/CoordinateSearch.js.map
CHANGED
|
@@ -1 +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,EAAA,MAAM,EAAE,QAAA,EAAU,OAAS,EAAA,WAAA,EAAgB,GAAA,KAAA
|
|
1
|
+
{"version":3,"file":"CoordinateSearch.js","sources":["CoordinateSearch.tsx"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 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,EAAA,MAAM,EAAE,QAAA,EAAU,OAAS,EAAA,WAAA,EAAgB,GAAA,KAAA;AAC3C,EAAA,MAAM,EAAE,cAAA,EAAmB,GAAA,uBAAA,CAAwB,qBAAqB,KAAK,CAAA;AAC7E,EAAA,MAAM,EAAE,GAAA,EAAQ,GAAA,WAAA,CAAY,KAAK,CAAA;AACjC,EAAA,MAAM,QAAQ,GAAK,EAAA,KAAA;AAEnB,EAAA,MAAM,EAAE,WAAA,EAAgB,GAAA,cAAA,CAAe,KAAK,CAAA;AAE5C,EACI,uBAAA,GAAA;AAAA,IAAC,eAAA;AAAA,IAAA;AAAA,MACI,GAAG,cAAA;AAAA,MACJ,OAAO,KAAM,CAAA,KAAA;AAAA,MACb,QAAA,EAAU,CAAC,KAAkC,KAAA;AACzC,QAAA,IAAI,CAAC,GAAK,EAAA;AACN,UAAA;AAAA;AAGJ,QAAA,KAAA,EAAO,OAAQ,EAAA,CAAE,SAAU,CAAA,KAAA,CAAM,MAAM,CAAA;AACvC,QAAA,QAAA,GAAW,KAAK,CAAA;AAAA,OACpB;AAAA,MACA,OAAA;AAAA,MACA,WAAA,EAAa,cAAc,WAAc,GAAA,EAAA;AAAA,MACzC;AAAA;AAAA,GACJ;AAER;AAGA,SAAS,eAAe,GAAiE,EAAA;AACrF,EAAA,MAAM,CAAC,WAAA,EAAa,cAAc,CAAA,GAAI,QAAiC,EAAA;AAEvE,EAAA,SAAA,CAAU,MAAM;AACZ,IAAA,IAAI,CAAC,GAAK,EAAA;AACN,MAAA;AAAA;AAGJ,IAAA,MAAM,SAAuB,GAAA,GAAA,CAAI,EAAG,CAAA,aAAA,EAAe,CAAC,GAAQ,KAAA;AACxD,MAAA,cAAA,CAAe,IAAI,UAAU,CAAA;AAAA,KAChC,CAAA;AAED,IAAO,OAAA,MAAM,QAAQ,SAAS,CAAA;AAAA,GAClC,EAAG,CAAC,GAAG,CAAC,CAAA;AAER,EAAA,OAAO,EAAE,WAAY,EAAA;AACzB;;;;"}
|
package/ProjectionSelect.d.ts
CHANGED
|
@@ -2,6 +2,6 @@ import { ProjectionItem } from "./CoordinateInput";
|
|
|
2
2
|
export declare const ProjectionSelect: import("react").NamedExoticComponent<{
|
|
3
3
|
currentProjection: ProjectionItem;
|
|
4
4
|
projections: ProjectionItem[];
|
|
5
|
-
portalElement: React.RefObject<HTMLDivElement>;
|
|
5
|
+
portalElement: React.RefObject<HTMLDivElement | null>;
|
|
6
6
|
onProjectionChange: (proj: ProjectionItem) => void;
|
|
7
7
|
}>;
|
package/ProjectionSelect.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProjectionSelect.js","sources":["ProjectionSelect.tsx"],"sourcesContent":["// SPDX-FileCopyrightText: 2023 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { useEvent } from \"@open-pioneer/react-utils\";\nimport { PackageIntl } from \"@open-pioneer/runtime\";\nimport { AriaLiveMessages, AriaOnChange, AriaOnFocus, Select } from \"chakra-react-select\";\nimport { useIntl } from \"open-pioneer:react-hooks\";\nimport { KeyboardEvent, memo, useMemo, useState } from \"react\";\nimport { ProjectionItem } from \"./CoordinateInput\";\n\nexport const ProjectionSelect = memo(function ProjectionSelect(props: {\n currentProjection: ProjectionItem;\n projections: ProjectionItem[];\n portalElement: React.RefObject<HTMLDivElement>;\n onProjectionChange: (proj: ProjectionItem) => void;\n}) {\n const { currentProjection, projections, portalElement, onProjectionChange } = props;\n const intl = useIntl();\n const ariaMessages = useAriaMessages(intl);\n const [isOpen, setIsOpen] = useState(false);\n\n const keyDown = useEvent((event: KeyboardEvent<HTMLDivElement>) => {\n // if the menu is already open, do nothing\n if (!isOpen && event.key === \"Enter\") {\n setIsOpen(true);\n }\n });\n\n return (\n <Select<ProjectionItem>\n value={currentProjection}\n defaultValue={currentProjection}\n options={projections}\n menuPlacement=\"auto\"\n menuPortalTarget={portalElement.current}\n aria-label={intl.formatMessage({\n id: \"coordinateInput.ariaLabel\"\n })}\n classNamePrefix=\"coordinate-input-select\"\n isSearchable={false}\n chakraStyles={{\n menu: (base) => {\n return {\n ...base,\n width: \"max-content\",\n minWidth: \"100%\"\n };\n },\n control: (base, { selectProps: { menuIsOpen } }) => ({\n ...base,\n width: \"max-content\",\n minWidth: \"100%\",\n color: \"white\",\n borderLeftStyle: \"none\",\n borderLeftRadius: 0,\n padding: 0,\n backgroundColor: `${menuIsOpen ? \"rgb(27, 75, 95)\" : \"var(--chakra-colors-background_primary)\"}`,\n _focus: {\n boxShadow: \"var(--chakra-shadows-outline)\"\n }\n }),\n valueContainer: (base) => ({\n ...base,\n paddingEnd: 0,\n cursor: \"pointer\"\n }),\n dropdownIndicator: (base, { selectProps: { menuIsOpen } }) => ({\n ...base,\n paddingStart: 0,\n backgroundColor: `${menuIsOpen ? \"rgb(27, 75, 95)\" : \"var(--chakra-colors-background_primary)\"}`\n }),\n option: (base) => ({\n ...base,\n _focus: {\n background: \"var(--chakra-colors-trails-300)\"\n }\n }),\n indicatorSeparator: (base, { selectProps: { menuIsOpen } }) => ({\n ...base,\n backgroundColor: `${menuIsOpen ? \"rgb(27, 75, 95)\" : \"var(--chakra-colors-background_primary)\"}`,\n borderColor: `${menuIsOpen ? \"rgb(27, 75, 95)\" : \"var(--chakra-colors-background_primary)\"}`\n })\n }}\n ariaLiveMessages={ariaMessages}\n onChange={(e) => {\n if (e?.value !== undefined) {\n onProjectionChange(e);\n }\n }}\n onKeyDown={keyDown}\n menuIsOpen={isOpen}\n onMenuOpen={() => setIsOpen(true)}\n onMenuClose={() => setIsOpen(false)}\n />\n );\n});\n\n/**\n * Provides custom aria messages for select of the coordinate input component.\n */\nfunction useAriaMessages(\n intl: PackageIntl\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n): AriaLiveMessages<any, false, any> {\n return useMemo(() => {\n /**\n * Method to create Aria-String for focus-Event\n */\n const onFocus: AriaOnFocus<unknown> = () => {\n // no aria string for focus-events because in some screen readers (NVDA) and browsers (Chrome) updating the aria string causes the instructions to be read out again each time a select option is focused\n return \"\";\n };\n\n /**\n * Method to create Aria-String for value-change-Event\n */\n const onChange: AriaOnChange<unknown, boolean> = (props) => {\n if (props.action == \"select-option\" || props.action == \"initial-input-focus\")\n return props.label + \" \" + intl.formatMessage({ id: \"selected\" });\n else return \"\";\n };\n\n /**\n * Method to create Aria-String for instruction\n */\n const guidance = () => {\n return \"\";\n };\n\n /**\n * Method to create Aria-String for result length\n */\n const onFilter = () => {\n return \"\";\n };\n\n return {\n onFocus,\n onChange,\n guidance,\n onFilter\n };\n }, [intl]);\n}\n"],"names":["ProjectionSelect"],"mappings":";;;;;;AASO,MAAM,gBAAmB,GAAA,IAAA,CAAK,SAASA,iBAAAA,CAAiB,KAK5D,EAAA;AACC,EAAA,MAAM,EAAE,iBAAA,EAAmB,WAAa,EAAA,aAAA,EAAe,oBAAuB,GAAA,KAAA
|
|
1
|
+
{"version":3,"file":"ProjectionSelect.js","sources":["ProjectionSelect.tsx"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { useEvent } from \"@open-pioneer/react-utils\";\nimport { PackageIntl } from \"@open-pioneer/runtime\";\nimport { AriaLiveMessages, AriaOnChange, AriaOnFocus, Select } from \"chakra-react-select\";\nimport { useIntl } from \"open-pioneer:react-hooks\";\nimport { KeyboardEvent, memo, useMemo, useState } from \"react\";\nimport { ProjectionItem } from \"./CoordinateInput\";\n\nexport const ProjectionSelect = memo(function ProjectionSelect(props: {\n currentProjection: ProjectionItem;\n projections: ProjectionItem[];\n portalElement: React.RefObject<HTMLDivElement | null>;\n onProjectionChange: (proj: ProjectionItem) => void;\n}) {\n const { currentProjection, projections, portalElement, onProjectionChange } = props;\n const intl = useIntl();\n const ariaMessages = useAriaMessages(intl);\n const [isOpen, setIsOpen] = useState(false);\n\n const keyDown = useEvent((event: KeyboardEvent<HTMLDivElement>) => {\n // if the menu is already open, do nothing\n if (!isOpen && event.key === \"Enter\") {\n setIsOpen(true);\n }\n });\n\n return (\n <Select<ProjectionItem>\n value={currentProjection}\n defaultValue={currentProjection}\n options={projections}\n menuPlacement=\"auto\"\n menuPortalTarget={portalElement.current}\n aria-label={intl.formatMessage({\n id: \"coordinateInput.ariaLabel\"\n })}\n classNamePrefix=\"coordinate-input-select\"\n isSearchable={false}\n chakraStyles={{\n menu: (base) => {\n return {\n ...base,\n width: \"max-content\",\n minWidth: \"100%\"\n };\n },\n control: (base, { selectProps: { menuIsOpen } }) => ({\n ...base,\n width: \"max-content\",\n minWidth: \"100%\",\n color: \"white\",\n borderLeftStyle: \"none\",\n borderLeftRadius: 0,\n padding: 0,\n backgroundColor: `${menuIsOpen ? \"rgb(27, 75, 95)\" : \"var(--chakra-colors-background_primary)\"}`,\n _focus: {\n boxShadow: \"var(--chakra-shadows-outline)\"\n }\n }),\n valueContainer: (base) => ({\n ...base,\n paddingEnd: 0,\n cursor: \"pointer\"\n }),\n dropdownIndicator: (base, { selectProps: { menuIsOpen } }) => ({\n ...base,\n paddingStart: 0,\n backgroundColor: `${menuIsOpen ? \"rgb(27, 75, 95)\" : \"var(--chakra-colors-background_primary)\"}`\n }),\n option: (base) => ({\n ...base,\n _focus: {\n background: \"var(--chakra-colors-trails-300)\"\n }\n }),\n indicatorSeparator: (base, { selectProps: { menuIsOpen } }) => ({\n ...base,\n backgroundColor: `${menuIsOpen ? \"rgb(27, 75, 95)\" : \"var(--chakra-colors-background_primary)\"}`,\n borderColor: `${menuIsOpen ? \"rgb(27, 75, 95)\" : \"var(--chakra-colors-background_primary)\"}`\n })\n }}\n ariaLiveMessages={ariaMessages}\n onChange={(e) => {\n if (e?.value !== undefined) {\n onProjectionChange(e);\n }\n }}\n onKeyDown={keyDown}\n menuIsOpen={isOpen}\n onMenuOpen={() => setIsOpen(true)}\n onMenuClose={() => setIsOpen(false)}\n />\n );\n});\n\n/**\n * Provides custom aria messages for select of the coordinate input component.\n */\nfunction useAriaMessages(\n intl: PackageIntl\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n): AriaLiveMessages<any, false, any> {\n return useMemo(() => {\n /**\n * Method to create Aria-String for focus-Event\n */\n const onFocus: AriaOnFocus<unknown> = () => {\n // no aria string for focus-events because in some screen readers (NVDA) and browsers (Chrome) updating the aria string causes the instructions to be read out again each time a select option is focused\n return \"\";\n };\n\n /**\n * Method to create Aria-String for value-change-Event\n */\n const onChange: AriaOnChange<unknown, boolean> = (props) => {\n if (props.action == \"select-option\" || props.action == \"initial-input-focus\")\n return props.label + \" \" + intl.formatMessage({ id: \"selected\" });\n else return \"\";\n };\n\n /**\n * Method to create Aria-String for instruction\n */\n const guidance = () => {\n return \"\";\n };\n\n /**\n * Method to create Aria-String for result length\n */\n const onFilter = () => {\n return \"\";\n };\n\n return {\n onFocus,\n onChange,\n guidance,\n onFilter\n };\n }, [int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AAmB,CAAC,CAAA;AAAA;AACxB,OACJ;AAAA,MACA,SAAW,EAAA,OAAA;AAAA,MACX,UAAY,EAAA,MAAA;AAAA,MACZ,UAAA,EAAY,MAAM,SAAA,CAAU,IAAI,CAAA;AAAA,MAChC,WAAA,EAAa,MAAM,SAAA,CAAU,KAAK;AAAA;AAAA,GACtC;AAER,CAAC;AAKD,SAAS,gBACL,IAEiC,EAAA;AACjC,EAAA,OAAO,QAAQ,MAAM;AAIjB,IAAA,MAAM,UAAgC,MAAM;AAExC,MAAO,OAAA,EAAA;AAAA,KACX;AAKA,IAAM,MAAA,QAAA,GAA2C,CAAC,KAAU,KAAA;AACxD,MAAA,IAAI,KAAM,CAAA,MAAA,IAAU,eAAmB,IAAA,KAAA,CAAM,MAAU,IAAA,qBAAA;AACnD,QAAO,OAAA,KAAA,CAAM,QAAQ,GAAM,GAAA,IAAA,CAAK,cAAc,EAAE,EAAA,EAAI,YAAY,CAAA;AAAA,WACxD,OAAA,EAAA;AAAA,KAChB;AAKA,IAAA,MAAM,WAAW,MAAM;AACnB,MAAO,OAAA,EAAA;AAAA,KACX;AAKA,IAAA,MAAM,WAAW,MAAM;AACnB,MAAO,OAAA,EAAA;AAAA,KACX;AAEA,IAAO,OAAA;AAAA,MACH,OAAA;AAAA,MACA,QAAA;AAAA,MACA,QAAA;AAAA,MACA;AAAA,KACJ;AAAA,GACJ,EAAG,CAAC,IAAI,CAAC,CAAA;AACb;;;;"}
|
package/coordinates.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"coordinates.js","sources":["coordinates.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023 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.length != 2 || splitCoords[0] == \"\" || splitCoords[1] == \"\") {\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(projection: Projection, coords: number[]): 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 extent[0]! <= coords[0]! &&\n extent[1]! <= coords[1]! &&\n extent[2]! >= coords[0]! &&\n extent[3]! >= coords[1]!\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":";;;AAKA,MAAM,GAAA,GAAM,aAAa,mBAAmB,CAAA
|
|
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.length != 2 || splitCoords[0] == \"\" || splitCoords[1] == \"\") {\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(projection: Projection, coords: number[]): 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 extent[0]! <= coords[0]! &&\n extent[1]! <= coords[1]! &&\n extent[2]! >= coords[0]! &&\n extent[3]! >= coords[1]!\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":";;;AAKA,MAAM,G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AAC,CAAI,GAAA,WAAA;AAEf,EAAM,MAAA,OAAA,GAAU,IAAK,CAAA,YAAA,CAAa,CAAG,EAAA;AAAA,IACjC,qBAAuB,EAAA,SAAA;AAAA,IACvB,qBAAuB,EAAA;AAAA,GAC1B,CAAA;AACD,EAAM,MAAA,OAAA,GAAU,IAAK,CAAA,YAAA,CAAa,CAAG,EAAA;AAAA,IACjC,qBAAuB,EAAA,SAAA;AAAA,IACvB,qBAAuB,EAAA;AAAA,GAC1B,CAAA;AAED,EAAA,OAAO,UAAU,GAAM,GAAA,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": "0.9.0
|
|
4
|
+
"version": "0.9.0",
|
|
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"
|
|
@@ -15,16 +15,16 @@
|
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"@conterra/reactivity-core": "^0.4.3",
|
|
18
|
-
"@open-pioneer/core": "^
|
|
19
|
-
"@open-pioneer/chakra-integration": "^
|
|
20
|
-
"@open-pioneer/runtime": "^
|
|
21
|
-
"@open-pioneer/react-utils": "^
|
|
22
|
-
"@open-pioneer/reactivity": "^
|
|
23
|
-
"chakra-react-select": "^5.0.
|
|
18
|
+
"@open-pioneer/core": "^3.0.0",
|
|
19
|
+
"@open-pioneer/chakra-integration": "^3.0.0",
|
|
20
|
+
"@open-pioneer/runtime": "^3.0.0",
|
|
21
|
+
"@open-pioneer/react-utils": "^3.0.0",
|
|
22
|
+
"@open-pioneer/reactivity": "^3.0.0",
|
|
23
|
+
"chakra-react-select": "^5.0.4",
|
|
24
24
|
"@chakra-ui/icons": "^2.2.4",
|
|
25
|
-
"ol": "^10.
|
|
26
|
-
"react": "^
|
|
27
|
-
"@open-pioneer/map": "^0.9.0
|
|
25
|
+
"ol": "^10.4.0",
|
|
26
|
+
"react": "^19.0.0",
|
|
27
|
+
"@open-pioneer/map": "^0.9.0"
|
|
28
28
|
},
|
|
29
29
|
"exports": {
|
|
30
30
|
"./package.json": "./package.json",
|
package/usePlaceholder.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePlaceholder.js","sources":["usePlaceholder.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { Coordinate } from \"ol/coordinate\";\nimport { Projection, transform } from \"ol/proj\";\nimport { useIntl } from \"open-pioneer:react-hooks\";\nimport { useMemo } from \"react\";\nimport { ProjectionItem } from \"./CoordinateInput\";\nimport { formatCoordinates } from \"./coordinates\";\n\n/**\n * Returns the current placeholder string.\n */\n//In a different file for HMR.\nexport function usePlaceholder(\n placeholderProp: string | Coordinate,\n mapProjection: Projection | undefined,\n selectedProjection: ProjectionItem\n) {\n const intl = useIntl();\n\n return useMemo(() => {\n let placeholder: string;\n if (typeof placeholderProp === \"string\") {\n placeholder = placeholderProp;\n } else if (!mapProjection) {\n placeholder = \"\";\n } else {\n const coords = transform(\n placeholderProp as Coordinate,\n mapProjection,\n selectedProjection.value\n );\n placeholder = formatCoordinates(coords, selectedProjection.precision, intl);\n }\n return placeholder;\n }, [placeholderProp, mapProjection, selectedProjection, intl]);\n}\n"],"names":[],"mappings":";;;;;AAagB,SAAA,cAAA,CACZ,eACA,EAAA,aAAA,EACA,kBACF,EAAA;AACE,EAAA,MAAM,OAAO,OAAQ,EAAA
|
|
1
|
+
{"version":3,"file":"usePlaceholder.js","sources":["usePlaceholder.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { Coordinate } from \"ol/coordinate\";\nimport { Projection, transform } from \"ol/proj\";\nimport { useIntl } from \"open-pioneer:react-hooks\";\nimport { useMemo } from \"react\";\nimport { ProjectionItem } from \"./CoordinateInput\";\nimport { formatCoordinates } from \"./coordinates\";\n\n/**\n * Returns the current placeholder string.\n */\n//In a different file for HMR.\nexport function usePlaceholder(\n placeholderProp: string | Coordinate,\n mapProjection: Projection | undefined,\n selectedProjection: ProjectionItem\n) {\n const intl = useIntl();\n\n return useMemo(() => {\n let placeholder: string;\n if (typeof placeholderProp === \"string\") {\n placeholder = placeholderProp;\n } else if (!mapProjection) {\n placeholder = \"\";\n } else {\n const coords = transform(\n placeholderProp as Coordinate,\n mapProjection,\n selectedProjection.value\n );\n placeholder = formatCoordinates(coords, selectedProjection.precision, intl);\n }\n return placeholder;\n }, [placeholderProp, mapProjection, selectedProjection, intl]);\n}\n"],"names":[],"mappings":";;;;;AAagB,SAAA,cAAA,CACZ,eACA,EAAA,aAAA,EACA,kBACF,EAAA;AACE,EAAA,MAAM,OAAO,OAAQ,EAAA;AAErB,EAAA,OAAO,QAAQ,MAAM;AACjB,IAAI,IAAA,WAAA;AACJ,IAAI,IAAA,OAAO,oBAAoB,QAAU,EAAA;AACrC,MAAc,WAAA,GAAA,eAAA;AAAA,KAClB,MAAA,IAAW,CAAC,aAAe,EAAA;AACvB,MAAc,WAAA,GAAA,EAAA;AAAA,KACX,MAAA;AACH,MAAA,MAAM,MAAS,GAAA,SAAA;AAAA,QACX,eAAA;AAAA,QACA,aAAA;AAAA,QACA,kBAAmB,CAAA;AAAA,OACvB;AACA,MAAA,WAAA,GAAc,iBAAkB,CAAA,MAAA,EAAQ,kBAAmB,CAAA,SAAA,EAAW,IAAI,CAAA;AAAA;AAE9E,IAAO,OAAA,WAAA;AAAA,KACR,CAAC,eAAA,EAAiB,aAAe,EAAA,kBAAA,EAAoB,IAAI,CAAC,CAAA;AACjE;;;;"}
|