@open-pioneer/measurement 0.4.4 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +30 -0
- package/Measurement.d.ts +2 -5
- package/Measurement.js +1 -2
- package/Measurement.js.map +1 -1
- package/README.md +1 -1
- package/package.json +7 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,35 @@
|
|
|
1
1
|
# @open-pioneer/measurement
|
|
2
2
|
|
|
3
|
+
## 0.7.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 310800c: Switch from `peerDependencies` to normal `dependencies`. Peer dependencies have some usability problems when used at scale.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- 310800c: Update core packages version.
|
|
12
|
+
- 583f1d6: The `mapId` or `map` properties are now optional on individual components.
|
|
13
|
+
You can use the `DefaultMapProvider` to configure an implicit default value.
|
|
14
|
+
|
|
15
|
+
Note that configuring _neither_ a default _nor_ an explicit `map` or `mapId` will trigger a runtime error.
|
|
16
|
+
|
|
17
|
+
- 583f1d6: All UI components in this project now accept the `mapId` (a `string`) _or_ the `map` (a `MapModel`) directly.
|
|
18
|
+
- a8b3449: Switch to a new versioning strategy.
|
|
19
|
+
From now on, packages released by this repository share a common version number.
|
|
20
|
+
- 900eb11: Update dependencies.
|
|
21
|
+
- Updated dependencies [310800c]
|
|
22
|
+
- Updated dependencies [2502050]
|
|
23
|
+
- Updated dependencies [583f1d6]
|
|
24
|
+
- Updated dependencies [583f1d6]
|
|
25
|
+
- Updated dependencies [397d617]
|
|
26
|
+
- Updated dependencies [a8b3449]
|
|
27
|
+
- Updated dependencies [310800c]
|
|
28
|
+
- Updated dependencies [900eb11]
|
|
29
|
+
- Updated dependencies [583f1d6]
|
|
30
|
+
- Updated dependencies [397d617]
|
|
31
|
+
- @open-pioneer/map@0.7.0
|
|
32
|
+
|
|
3
33
|
## 0.4.4
|
|
4
34
|
|
|
5
35
|
### Patch Changes
|
package/Measurement.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { MapModelProps } from "@open-pioneer/map";
|
|
1
2
|
import { CommonComponentProps } from "@open-pioneer/react-utils";
|
|
2
3
|
import { StyleLike } from "ol/style/Style";
|
|
3
4
|
import { FC } from "react";
|
|
@@ -26,11 +27,7 @@ export type MeasurementGeometry = LineString | Polygon;
|
|
|
26
27
|
/**
|
|
27
28
|
* This is for special properties of the Measurement.
|
|
28
29
|
*/
|
|
29
|
-
export interface MeasurementProps extends CommonComponentProps {
|
|
30
|
-
/**
|
|
31
|
-
* The id of the map.
|
|
32
|
-
*/
|
|
33
|
-
mapId: string;
|
|
30
|
+
export interface MeasurementProps extends CommonComponentProps, MapModelProps {
|
|
34
31
|
/**
|
|
35
32
|
* The style for the active drawing feature's geometry.
|
|
36
33
|
*/
|
package/Measurement.js
CHANGED
|
@@ -9,11 +9,10 @@ import { MeasurementController } from './MeasurementController.js';
|
|
|
9
9
|
|
|
10
10
|
const Measurement = (props) => {
|
|
11
11
|
const intl = useIntl();
|
|
12
|
-
const { mapId } = props;
|
|
13
12
|
const { containerProps } = useCommonComponentProps("measurement", props);
|
|
14
13
|
const [selectedMeasurement, setMeasurement] = useState("distance");
|
|
15
14
|
const label = (id) => intl.formatMessage({ id });
|
|
16
|
-
const mapState = useMapModel(
|
|
15
|
+
const mapState = useMapModel(props);
|
|
17
16
|
const controller = useController(mapState.map, props, intl);
|
|
18
17
|
useEffect(() => {
|
|
19
18
|
if (!controller) {
|
package/Measurement.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Measurement.js","sources":["Measurement.tsx"],"sourcesContent":["// SPDX-FileCopyrightText: 2023 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport {\n Box,\n Button,\n FormControl,\n FormLabel,\n HStack,\n Select,\n Text\n} from \"@open-pioneer/chakra-integration\";\nimport { MapModel, useMapModel } from \"@open-pioneer/map\";\nimport { CommonComponentProps, useCommonComponentProps } from \"@open-pioneer/react-utils\";\nimport { PackageIntl } from \"@open-pioneer/runtime\";\nimport { Circle as CircleStyle, Fill, Stroke, Style } from \"ol/style\";\nimport { StyleLike } from \"ol/style/Style\";\nimport { useIntl } from \"open-pioneer:react-hooks\";\nimport { FC, useEffect, useState } from \"react\";\nimport { MeasurementController, MeasurementType } from \"./MeasurementController\";\nimport LineString from \"ol/geom/LineString\";\nimport Polygon from \"ol/geom/Polygon\";\n\n/** Emitted when a new measurement is being added to the map. */\nexport interface MeasurementsAddEvent {\n kind: \"add-measurement\";\n geometry: MeasurementGeometry;\n}\n\n/** Emitted when a measurement is being removed from the map. */\nexport interface MeasurementsRemoveEvent {\n kind: \"remove-measurement\";\n geometry: MeasurementGeometry;\n}\n\n/**\n * A change event emitted by {@link Measurement} when measurements change.\n *\n * NOTE: Non-exhaustive. More event types may be added in a future version.\n **/\nexport type MeasurementsChangeEvent = MeasurementsAddEvent | MeasurementsRemoveEvent;\n\n/**\n * Represents the geometry of a measurement.\n */\nexport type MeasurementGeometry = LineString | Polygon;\n\n/**\n * This is for special properties of the Measurement.\n */\nexport interface MeasurementProps extends CommonComponentProps {\n /**\n * The id of the map.\n */\n mapId: string;\n\n /**\n * The style for the active drawing feature's geometry.\n */\n activeFeatureStyle?: StyleLike;\n\n /**\n * The style for the finished drawn feature's geometry.\n */\n finishedFeatureStyle?: StyleLike;\n\n /**\n * List of measurements to be rendered when the component is initialized.\n */\n predefinedMeasurements?: MeasurementGeometry[];\n\n /**\n * Event handler that is called whenever a measurement is added or removed.\n */\n onMeasurementsChange?: (event: MeasurementsChangeEvent) => void;\n}\n\n/**\n * The `Measurement` component can be used in an app to measure geometries (areas or lines) on the map.\n */\nexport const Measurement: FC<MeasurementProps> = (props) => {\n const intl = useIntl();\n const { mapId } = props;\n const { containerProps } = useCommonComponentProps(\"measurement\", props);\n const [selectedMeasurement, setMeasurement] = useState<MeasurementType>(\"distance\");\n const label = (id: string) => intl.formatMessage({ id: id });\n const mapState = useMapModel(mapId);\n const controller = useController(mapState.map, props, intl);\n\n // Start / Stop measurement on selection change\n useEffect(() => {\n if (!controller) {\n return;\n }\n\n controller.startMeasurement(selectedMeasurement);\n return () => {\n controller.stopMeasurement();\n };\n }, [controller, selectedMeasurement]);\n\n function changeMeasurement(measurementType: string) {\n if (measurementType === \"distance\" || measurementType === \"area\") {\n setMeasurement(measurementType);\n } else {\n throw new Error(`Unexpected measurement type: '${measurementType}'.`);\n }\n }\n\n function removeMeasurements() {\n controller?.clearMeasurements();\n }\n\n return (\n <Box {...containerProps}>\n <Text mb={3}>{intl.formatMessage({ id: \"measurementInfoText\" })}</Text>\n <FormControl mb={4} alignItems=\"center\">\n <HStack mb={2}>\n <FormLabel mb={1}>{label(\"measurementLabel\")}</FormLabel>\n <Select\n value={selectedMeasurement}\n onChange={(e) => changeMeasurement(e.target.value)}\n className=\"measurement-select\"\n >\n <option value={\"distance\"}>{label(\"distance\")}</option>\n <option value={\"area\"}>{label(\"area\")}</option>\n </Select>\n </HStack>\n </FormControl>\n <Button\n padding={2}\n className=\"measurement-delete-button\"\n onClick={removeMeasurements}\n width=\"100%\"\n >\n {label(\"deleteMeasurementLabel\")}\n </Button>\n </Box>\n );\n};\n\n/** Creates a MeasurementController instance for the given map. */\nfunction useController(map: MapModel | undefined, props: MeasurementProps, intl: PackageIntl) {\n const {\n activeFeatureStyle,\n finishedFeatureStyle,\n onMeasurementsChange,\n predefinedMeasurements\n } = props;\n const [controller, setController] = useState<MeasurementController | undefined>(undefined);\n useEffect(() => {\n if (!map) {\n return;\n }\n const controller = new MeasurementController(map.olMap, {\n getContinueMessage() {\n return intl.formatMessage({ id: \"tooltips.continue\" });\n },\n getHelpMessage() {\n return intl.formatMessage({ id: \"tooltips.help\" });\n },\n formatNumber(value) {\n return intl.formatNumber(value, {\n maximumFractionDigits: 2\n });\n }\n });\n\n setController(controller);\n return () => {\n controller.destroy();\n setController(undefined);\n };\n }, [map, intl]);\n\n // Synchronize styles with controller\n useEffect(() => {\n controller?.setActiveFeatureStyle(activeFeatureStyle ?? getDefaultActiveFeatureStyle());\n }, [controller, activeFeatureStyle]);\n useEffect(() => {\n controller?.setFinishedFeatureStyle(\n finishedFeatureStyle ?? getDefaultFinishedFeatureStyle()\n );\n }, [controller, finishedFeatureStyle]);\n useEffect(() => {\n controller?.setMeasurementSourceChangedHandler(onMeasurementsChange);\n }, [controller, onMeasurementsChange]);\n\n useEffect(() => {\n controller?.setPredefinedMeasurements(predefinedMeasurements ?? []);\n }, [controller, predefinedMeasurements]);\n return controller;\n}\n\nfunction getDefaultActiveFeatureStyle() {\n return [\n new Style({\n stroke: new Stroke({\n color: \"#fff\",\n lineDash: [10, 10],\n width: 5\n })\n }),\n new Style({\n fill: new Fill({\n color: \"rgba(0,0,0,0.15)\"\n }),\n stroke: new Stroke({\n color: \"rgba(0, 0, 0, 0.7)\",\n lineDash: [10, 10],\n width: 3\n }),\n image: new CircleStyle({\n radius: 5,\n stroke: new Stroke({\n color: \"rgba(0, 0, 0, 0.7)\",\n width: 2\n }),\n fill: new Fill({\n color: \"rgba(255, 255, 255, 0.2)\"\n })\n })\n })\n ];\n}\n\nfunction getDefaultFinishedFeatureStyle() {\n return [\n new Style({\n stroke: new Stroke({\n color: \"#fff\",\n width: 5\n })\n }),\n new Style({\n stroke: new Stroke({\n color: \"#0b96fc\",\n width: 3\n }),\n fill: new Fill({\n color: \"rgba(11,150,252,0.15)\"\n })\n })\n ];\n}\n"],"names":["controller","CircleStyle"],"mappings":";;;;;;;;;AA+Ea,MAAA,WAAA,GAAoC,CAAC,KAAU,KAAA;AACxD,EAAA,MAAM,OAAO,OAAQ,EAAA,CAAA;AACrB,EAAM,MAAA,EAAE,OAAU,GAAA,KAAA,CAAA;AAClB,EAAA,MAAM,EAAE,cAAA,EAAmB,GAAA,uBAAA,CAAwB,eAAe,KAAK,CAAA,CAAA;AACvE,EA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iC,GAAA;AACtC,EAAO,OAAA;AAAA,IACH,IAAI,KAAM,CAAA;AAAA,MACN,MAAA,EAAQ,IAAI,MAAO,CAAA;AAAA,QACf,KAAO,EAAA,MAAA;AAAA,QACP,KAAO,EAAA,CAAA;AAAA,OACV,CAAA;AAAA,KACJ,CAAA;AAAA,IACD,IAAI,KAAM,CAAA;AAAA,MACN,MAAA,EAAQ,IAAI,MAAO,CAAA;AAAA,QACf,KAAO,EAAA,SAAA;AAAA,QACP,KAAO,EAAA,CAAA;AAAA,OACV,CAAA;AAAA,MACD,IAAA,EAAM,IAAI,IAAK,CAAA;AAAA,QACX,KAAO,EAAA,uBAAA;AAAA,OACV,CAAA;AAAA,KACJ,CAAA;AAAA,GACL,CAAA;AACJ;;;;"}
|
|
1
|
+
{"version":3,"file":"Measurement.js","sources":["Measurement.tsx"],"sourcesContent":["// SPDX-FileCopyrightText: 2023 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport {\n Box,\n Button,\n FormControl,\n FormLabel,\n HStack,\n Select,\n Text\n} from \"@open-pioneer/chakra-integration\";\nimport { MapModel, MapModelProps, useMapModel } from \"@open-pioneer/map\";\nimport { CommonComponentProps, useCommonComponentProps } from \"@open-pioneer/react-utils\";\nimport { PackageIntl } from \"@open-pioneer/runtime\";\nimport { Circle as CircleStyle, Fill, Stroke, Style } from \"ol/style\";\nimport { StyleLike } from \"ol/style/Style\";\nimport { useIntl } from \"open-pioneer:react-hooks\";\nimport { FC, useEffect, useState } from \"react\";\nimport { MeasurementController, MeasurementType } from \"./MeasurementController\";\nimport LineString from \"ol/geom/LineString\";\nimport Polygon from \"ol/geom/Polygon\";\n\n/** Emitted when a new measurement is being added to the map. */\nexport interface MeasurementsAddEvent {\n kind: \"add-measurement\";\n geometry: MeasurementGeometry;\n}\n\n/** Emitted when a measurement is being removed from the map. */\nexport interface MeasurementsRemoveEvent {\n kind: \"remove-measurement\";\n geometry: MeasurementGeometry;\n}\n\n/**\n * A change event emitted by {@link Measurement} when measurements change.\n *\n * NOTE: Non-exhaustive. More event types may be added in a future version.\n **/\nexport type MeasurementsChangeEvent = MeasurementsAddEvent | MeasurementsRemoveEvent;\n\n/**\n * Represents the geometry of a measurement.\n */\nexport type MeasurementGeometry = LineString | Polygon;\n\n/**\n * This is for special properties of the Measurement.\n */\nexport interface MeasurementProps extends CommonComponentProps, MapModelProps {\n /**\n * The style for the active drawing feature's geometry.\n */\n activeFeatureStyle?: StyleLike;\n\n /**\n * The style for the finished drawn feature's geometry.\n */\n finishedFeatureStyle?: StyleLike;\n\n /**\n * List of measurements to be rendered when the component is initialized.\n */\n predefinedMeasurements?: MeasurementGeometry[];\n\n /**\n * Event handler that is called whenever a measurement is added or removed.\n */\n onMeasurementsChange?: (event: MeasurementsChangeEvent) => void;\n}\n\n/**\n * The `Measurement` component can be used in an app to measure geometries (areas or lines) on the map.\n */\nexport const Measurement: FC<MeasurementProps> = (props) => {\n const intl = useIntl();\n const { containerProps } = useCommonComponentProps(\"measurement\", props);\n const [selectedMeasurement, setMeasurement] = useState<MeasurementType>(\"distance\");\n const label = (id: string) => intl.formatMessage({ id: id });\n const mapState = useMapModel(props);\n const controller = useController(mapState.map, props, intl);\n\n // Start / Stop measurement on selection change\n useEffect(() => {\n if (!controller) {\n return;\n }\n\n controller.startMeasurement(selectedMeasurement);\n return () => {\n controller.stopMeasurement();\n };\n }, [controller, selectedMeasurement]);\n\n function changeMeasurement(measurementType: string) {\n if (measurementType === \"distance\" || measurementType === \"area\") {\n setMeasurement(measurementType);\n } else {\n throw new Error(`Unexpected measurement type: '${measurementType}'.`);\n }\n }\n\n function removeMeasurements() {\n controller?.clearMeasurements();\n }\n\n return (\n <Box {...containerProps}>\n <Text mb={3}>{intl.formatMessage({ id: \"measurementInfoText\" })}</Text>\n <FormControl mb={4} alignItems=\"center\">\n <HStack mb={2}>\n <FormLabel mb={1}>{label(\"measurementLabel\")}</FormLabel>\n <Select\n value={selectedMeasurement}\n onChange={(e) => changeMeasurement(e.target.value)}\n className=\"measurement-select\"\n >\n <option value={\"distance\"}>{label(\"distance\")}</option>\n <option value={\"area\"}>{label(\"area\")}</option>\n </Select>\n </HStack>\n </FormControl>\n <Button\n padding={2}\n className=\"measurement-delete-button\"\n onClick={removeMeasurements}\n width=\"100%\"\n >\n {label(\"deleteMeasurementLabel\")}\n </Button>\n </Box>\n );\n};\n\n/** Creates a MeasurementController instance for the given map. */\nfunction useController(map: MapModel | undefined, props: MeasurementProps, intl: PackageIntl) {\n const {\n activeFeatureStyle,\n finishedFeatureStyle,\n onMeasurementsChange,\n predefinedMeasurements\n } = props;\n const [controller, setController] = useState<MeasurementController | undefined>(undefined);\n useEffect(() => {\n if (!map) {\n return;\n }\n const controller = new MeasurementController(map.olMap, {\n getContinueMessage() {\n return intl.formatMessage({ id: \"tooltips.continue\" });\n },\n getHelpMessage() {\n return intl.formatMessage({ id: \"tooltips.help\" });\n },\n formatNumber(value) {\n return intl.formatNumber(value, {\n maximumFractionDigits: 2\n });\n }\n });\n\n setController(controller);\n return () => {\n controller.destroy();\n setController(undefined);\n };\n }, [map, intl]);\n\n // Synchronize styles with controller\n useEffect(() => {\n controller?.setActiveFeatureStyle(activeFeatureStyle ?? getDefaultActiveFeatureStyle());\n }, [controller, activeFeatureStyle]);\n useEffect(() => {\n controller?.setFinishedFeatureStyle(\n finishedFeatureStyle ?? getDefaultFinishedFeatureStyle()\n );\n }, [controller, finishedFeatureStyle]);\n useEffect(() => {\n controller?.setMeasurementSourceChangedHandler(onMeasurementsChange);\n }, [controller, onMeasurementsChange]);\n\n useEffect(() => {\n controller?.setPredefinedMeasurements(predefinedMeasurements ?? []);\n }, [controller, predefinedMeasurements]);\n return controller;\n}\n\nfunction getDefaultActiveFeatureStyle() {\n return [\n new Style({\n stroke: new Stroke({\n color: \"#fff\",\n lineDash: [10, 10],\n width: 5\n })\n }),\n new Style({\n fill: new Fill({\n color: \"rgba(0,0,0,0.15)\"\n }),\n stroke: new Stroke({\n color: \"rgba(0, 0, 0, 0.7)\",\n lineDash: [10, 10],\n width: 3\n }),\n image: new CircleStyle({\n radius: 5,\n stroke: new Stroke({\n color: \"rgba(0, 0, 0, 0.7)\",\n width: 2\n }),\n fill: new Fill({\n color: \"rgba(255, 255, 255, 0.2)\"\n })\n })\n })\n ];\n}\n\nfunction getDefaultFinishedFeatureStyle() {\n return [\n new Style({\n stroke: new Stroke({\n color: \"#fff\",\n width: 5\n })\n }),\n new Style({\n stroke: new Stroke({\n color: \"#0b96fc\",\n width: 3\n }),\n fill: new Fill({\n color: \"rgba(11,150,252,0.15)\"\n })\n })\n ];\n}\n"],"names":["controller","CircleStyle"],"mappings":";;;;;;;;;AA0Ea,MAAA,WAAA,GAAoC,CAAC,KAAU,KAAA;AACxD,EAAA,MAAM,OAAO,OAAQ,EAAA,CAAA;AACrB,EAAA,MAAM,EAAE,cAAA,EAAmB,GAAA,uBAAA,CAAwB,eAAe,KAAK,CAAA,CAAA;AACvE,EAAA,MAAM,CAAC,mBAAA,EAAqB,cAAc,CAAA,GAAI,SAA0B,UAAU,CAAA,CAAA;AAClF,EAAA,MAAM,QAAQ,CAAC,EAAA,KAAe,KAAK,aAAc,CAAA,EAAE,IAAQ,CAAA,CAAA;AAC3D,EAAM,MAAA,QAAA,GAAW,YAAY,KAAK,CAAA,CAAA;AAClC,EAAA,MAAM,UAAa,GAAA,aAAA,CAAc,QAAS,CAAA,GAAA,EAAK,OAAO,IAAI,CAAA,CAAA;AAG1D,EAAA,SAAA,CAAU,MAAM;AACZ,IAAA,IAAI,CAAC,UAAY,EAAA;AACb,MAAA,OAAA;AAAA,KACJ;AAEA,IAAA,UAAA,CAAW,iBAAiB,mBAAmB,CAAA,CAAA;AAC/C,IAAA,OAAO,MAAM;AACT,MAAA,UAAA,CAAW,eAAgB,EAAA,CAAA;AAAA,KAC/B,CAAA;AAAA,GACD,EAAA,CAAC,UAAY,EAAA,mBAAmB,CAAC,CAAA,CAAA;AAEpC,EAAA,SAAS,kBAAkB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AAM,IAAI,IAAK,CAAA;AAAA,QACX,KAAO,EAAA,kBAAA;AAAA,OACV,CAAA;AAAA,MACD,MAAA,EAAQ,IAAI,MAAO,CAAA;AAAA,QACf,KAAO,EAAA,oBAAA;AAAA,QACP,QAAA,EAAU,CAAC,EAAA,EAAI,EAAE,CAAA;AAAA,QACjB,KAAO,EAAA,CAAA;AAAA,OACV,CAAA;AAAA,MACD,KAAA,EAAO,IAAIC,MAAY,CAAA;AAAA,QACnB,MAAQ,EAAA,CAAA;AAAA,QACR,MAAA,EAAQ,IAAI,MAAO,CAAA;AAAA,UACf,KAAO,EAAA,oBAAA;AAAA,UACP,KAAO,EAAA,CAAA;AAAA,SACV,CAAA;AAAA,QACD,IAAA,EAAM,IAAI,IAAK,CAAA;AAAA,UACX,KAAO,EAAA,0BAAA;AAAA,SACV,CAAA;AAAA,OACJ,CAAA;AAAA,KACJ,CAAA;AAAA,GACL,CAAA;AACJ,CAAA;AAEA,SAAS,8BAAiC,GAAA;AACtC,EAAO,OAAA;AAAA,IACH,IAAI,KAAM,CAAA;AAAA,MACN,MAAA,EAAQ,IAAI,MAAO,CAAA;AAAA,QACf,KAAO,EAAA,MAAA;AAAA,QACP,KAAO,EAAA,CAAA;AAAA,OACV,CAAA;AAAA,KACJ,CAAA;AAAA,IACD,IAAI,KAAM,CAAA;AAAA,MACN,MAAA,EAAQ,IAAI,MAAO,CAAA;AAAA,QACf,KAAO,EAAA,SAAA;AAAA,QACP,KAAO,EAAA,CAAA;AAAA,OACV,CAAA;AAAA,MACD,IAAA,EAAM,IAAI,IAAK,CAAA;AAAA,QACX,KAAO,EAAA,uBAAA;AAAA,OACV,CAAA;AAAA,KACJ,CAAA;AAAA,GACL,CAAA;AACJ;;;;"}
|
package/README.md
CHANGED
|
@@ -70,7 +70,7 @@ To prevent accidental updates, wrap the array in a `useMemo` hook or store it so
|
|
|
70
70
|
|
|
71
71
|
```tsx
|
|
72
72
|
import LineString from "ol/geom/LineString";
|
|
73
|
-
import { MeasurementGeometry } from "@open-pioneer/measurement
|
|
73
|
+
import { MeasurementGeometry } from "@open-pioneer/measurement";
|
|
74
74
|
|
|
75
75
|
const measurements = useMemo(
|
|
76
76
|
() => [
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@open-pioneer/measurement",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.7.0",
|
|
5
5
|
"description": "This package provides a UI component that allows the user to perform area and distance measurements on the map.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"open-pioneer-trails"
|
|
@@ -13,15 +13,15 @@
|
|
|
13
13
|
"url": "https://github.com/open-pioneer/trails-openlayers-base-packages",
|
|
14
14
|
"directory": "src/packages/measurement"
|
|
15
15
|
},
|
|
16
|
-
"
|
|
17
|
-
"@open-pioneer/chakra-integration": "^
|
|
18
|
-
"@open-pioneer/core": "^
|
|
19
|
-
"@open-pioneer/react-utils": "^
|
|
20
|
-
"@open-pioneer/runtime": "^2.
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@open-pioneer/chakra-integration": "^2.3.0",
|
|
18
|
+
"@open-pioneer/core": "^2.3.0",
|
|
19
|
+
"@open-pioneer/react-utils": "^2.3.0",
|
|
20
|
+
"@open-pioneer/runtime": "^2.3.0",
|
|
21
21
|
"classnames": "^2.3.2",
|
|
22
22
|
"ol": "^9.2.4",
|
|
23
23
|
"react": "^18.3.1",
|
|
24
|
-
"@open-pioneer/map": "^0.
|
|
24
|
+
"@open-pioneer/map": "^0.7.0"
|
|
25
25
|
},
|
|
26
26
|
"exports": {
|
|
27
27
|
"./package.json": "./package.json",
|