@open-pioneer/measurement 0.4.4 → 0.8.0-dev.20241120115147

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 CHANGED
@@ -1,5 +1,58 @@
1
1
  # @open-pioneer/measurement
2
2
 
3
+ ## 0.8.0-dev.20241120115147
4
+
5
+ ### Minor Changes
6
+
7
+ - b717121: Update from OL 9 to OL 10.
8
+ - 2fa8020: Update trails core package dependencies.
9
+
10
+ - Also updates Chakra UI to the latest 2.x version and Chakra React Select to version 5.
11
+ - Removes any obsolete references to `@chakra-ui/system`.
12
+ This dependency seems to be no longer required and may lead to duplicate packages in your dependency tree.
13
+
14
+ ### Patch Changes
15
+
16
+ - Updated dependencies [b717121]
17
+ - Updated dependencies [e7978a8]
18
+ - Updated dependencies [7ae9f90]
19
+ - Updated dependencies [d8337a6]
20
+ - Updated dependencies [b2127df]
21
+ - Updated dependencies [2fa8020]
22
+ - Updated dependencies [7ae9f90]
23
+ - Updated dependencies [d8337a6]
24
+ - @open-pioneer/map@0.8.0-dev.20241120115147
25
+
26
+ ## 0.7.0
27
+
28
+ ### Minor Changes
29
+
30
+ - 310800c: Switch from `peerDependencies` to normal `dependencies`. Peer dependencies have some usability problems when used at scale.
31
+
32
+ ### Patch Changes
33
+
34
+ - 310800c: Update core packages version.
35
+ - 583f1d6: The `mapId` or `map` properties are now optional on individual components.
36
+ You can use the `DefaultMapProvider` to configure an implicit default value.
37
+
38
+ Note that configuring _neither_ a default _nor_ an explicit `map` or `mapId` will trigger a runtime error.
39
+
40
+ - 583f1d6: All UI components in this project now accept the `mapId` (a `string`) _or_ the `map` (a `MapModel`) directly.
41
+ - a8b3449: Switch to a new versioning strategy.
42
+ From now on, packages released by this repository share a common version number.
43
+ - 900eb11: Update dependencies.
44
+ - Updated dependencies [310800c]
45
+ - Updated dependencies [2502050]
46
+ - Updated dependencies [583f1d6]
47
+ - Updated dependencies [583f1d6]
48
+ - Updated dependencies [397d617]
49
+ - Updated dependencies [a8b3449]
50
+ - Updated dependencies [310800c]
51
+ - Updated dependencies [900eb11]
52
+ - Updated dependencies [583f1d6]
53
+ - Updated dependencies [397d617]
54
+ - @open-pioneer/map@0.7.0
55
+
3
56
  ## 0.4.4
4
57
 
5
58
  ### 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(mapId);
15
+ const mapState = useMapModel(props);
17
16
  const controller = useController(mapState.map, props, intl);
18
17
  useEffect(() => {
19
18
  if (!controller) {
@@ -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,EAAA,MAAM,CAAC,mBAAA,EAAqB,cAAc,CAAA,GAAI,SAA0B,UAAU,CAAA,CAAA;AAClF,EAAA,MAAM,QAAQ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A;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,eAAyB,EAAA;AAChD,IAAI,IAAA,eAAA,KAAoB,UAAc,IAAA,eAAA,KAAoB,MAAQ,EAAA;AAC9D,MAAA,cAAA,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O,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;;;;"}
@@ -1,6 +1,7 @@
1
1
  import Feature from "ol/Feature";
2
2
  import OlMap from "ol/Map";
3
3
  import { Vector as VectorLayer } from "ol/layer";
4
+ import { Vector as VectorSource } from "ol/source";
4
5
  import { StyleLike } from "ol/style/Style";
5
6
  import type { MeasurementGeometry, MeasurementProps } from "./Measurement";
6
7
  type MeasurementsChangeHandler = NonNullable<MeasurementProps["onMeasurementsChange"]>;
@@ -56,7 +57,7 @@ export declare class MeasurementController {
56
57
  constructor(olMap: OlMap, messages: Messages);
57
58
  destroy(): void;
58
59
  /** Returns the vector layer used for finished features. */
59
- getVectorLayer(): VectorLayer<Feature<import("ol/geom").Geometry>>;
60
+ getVectorLayer(): VectorLayer<VectorSource<Feature<import("ol/geom").Geometry>>, Feature<import("ol/geom").Geometry>>;
60
61
  /** Updates the style used for finished features. */
61
62
  setFinishedFeatureStyle(style: StyleLike): void;
62
63
  setMeasurementSourceChangedHandler(handler: MeasurementsChangeHandler | undefined): void;
@@ -1 +1 @@
1
- {"version":3,"file":"MeasurementController.js","sources":["MeasurementController.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { destroyResource, Resource } from \"@open-pioneer/core\";\nimport { TOPMOST_LAYER_Z } from \"@open-pioneer/map\";\nimport Feature from \"ol/Feature\";\nimport OlMap from \"ol/Map\";\nimport MapBrowserEvent from \"ol/MapBrowserEvent\";\nimport { unByKey } from \"ol/Observable\";\nimport Overlay from \"ol/Overlay\";\nimport { Coordinate } from \"ol/coordinate\";\nimport { EventsKey } from \"ol/events\";\nimport { LineString, Polygon } from \"ol/geom\";\nimport Draw from \"ol/interaction/Draw\";\nimport { Vector as VectorLayer } from \"ol/layer\";\nimport { Projection } from \"ol/proj\";\nimport { Vector as VectorSource } from \"ol/source\";\nimport { getArea, getLength } from \"ol/sphere\";\nimport { StyleFunction, StyleLike, toFunction as toStyleFunction } from \"ol/style/Style\";\nimport type { MeasurementsChangeEvent, MeasurementGeometry, MeasurementProps } from \"./Measurement\";\n\ntype MeasurementsChangeHandler = NonNullable<MeasurementProps[\"onMeasurementsChange\"]>;\n\nexport type MeasurementType = \"area\" | \"distance\";\n\nexport interface Messages {\n getContinueMessage(): string;\n getHelpMessage(): string;\n formatNumber(value: number): string;\n}\n\nexport class MeasurementController {\n readonly olMap: OlMap;\n readonly messages: Messages;\n\n private activeFeatureStyle: StyleFunction | undefined;\n /**\n * The layer rendering the measurement \"features\".\n */\n private layer: VectorLayer<Feature>;\n\n /**\n * Source of {@link layer}.\n */\n private source: VectorSource;\n\n /**\n * Stores the current `Draw` interaction.\n */\n private draw: Draw | undefined = undefined;\n\n /**\n * The active measurement manipulated by the `draw` interaction.\n */\n private activeMeasurement: MeasurementInstance | undefined;\n\n /**\n * Map that is used to track all predefined measurements currently added to the source.\n * It associates the measurement geometry (key) with the corresponding measurement instance.\n *\n * The measurement instances here must also be contained in `finishedMeasurements`.\n */\n private predefinedMeasurements = new Map<MeasurementGeometry, MeasurementInstance>();\n\n /**\n * Measurement instances that were finished.\n */\n private finishedMeasurements = new Set<MeasurementInstance>();\n\n /**\n * The help tooltip element.\n */\n private helpTooltip: Tooltip;\n\n /**\n * Keeps track of registered event handlers.\n */\n private resources: Resource[] = [];\n\n /**\n * Called when a measurement is added to or removed from the source.\n */\n private measurementChangedHandler: MeasurementsChangeHandler | undefined;\n\n constructor(olMap: OlMap, messages: Messages) {\n this.olMap = olMap;\n this.messages = messages;\n const source = (this.source = new VectorSource());\n this.layer = new VectorLayer({\n source: source,\n zIndex: TOPMOST_LAYER_Z,\n properties: {\n name: \"measurement-layer\"\n }\n });\n olMap.addLayer(this.layer);\n\n const pointerMoveKey = olMap.on(\"pointermove\", this.handlePointerMove.bind(this));\n this.resources.push({\n destroy() {\n unByKey(pointerMoveKey);\n }\n });\n\n const mouseOutHandler = () => {\n this.helpTooltip.element.classList.add(\"hidden\");\n };\n olMap.getViewport().addEventListener(\"mouseout\", mouseOutHandler);\n this.resources.push({\n destroy() {\n olMap.getViewport().removeEventListener(\"mouseout\", mouseOutHandler);\n }\n });\n\n this.helpTooltip = createHelpTooltip(this.olMap);\n }\n\n destroy() {\n this.stopMeasurement();\n\n // Cleanup registered event handlers etc.\n for (const resource of this.resources) {\n resource.destroy();\n }\n this.resources = [];\n\n // Cleanup measurements and tooltips.\n this.activeMeasurement = destroyResource(this.activeMeasurement);\n for (const measurement of this.finishedMeasurements) {\n measurement.destroy();\n }\n this.finishedMeasurements.clear();\n this.helpTooltip.destroy();\n\n // Cleanup layer\n this.olMap.removeLayer(this.layer);\n this.layer.dispose();\n this.source.dispose();\n\n this.measurementChangedHandler = undefined;\n this.predefinedMeasurements.clear();\n }\n\n /** Returns the vector layer used for finished features. */\n getVectorLayer() {\n return this.layer;\n }\n\n /** Updates the style used for finished features. */\n setFinishedFeatureStyle(style: StyleLike) {\n this.layer.setStyle(style);\n }\n\n setMeasurementSourceChangedHandler(handler: MeasurementsChangeHandler | undefined) {\n this.measurementChangedHandler = handler;\n }\n\n setPredefinedMeasurements(geometries: MeasurementGeometry[]) {\n this.updatePredefinedMeasurements(geometries);\n }\n\n /** Updates the style used for active measurements. */\n setActiveFeatureStyle(style: StyleLike) {\n const styleFunction = toStyleFunction(style);\n this.activeFeatureStyle = (feature, ...args) => {\n const ft = feature?.getGeometry()?.getType();\n if (ft === \"Polygon\" || ft === \"LineString\" || ft === \"Point\") {\n return styleFunction(feature, ...args);\n }\n };\n // Update style on current draw instance (if any)\n this.draw?.getOverlay().setStyle(this.activeFeatureStyle);\n }\n\n /** Removes all finished measurements. */\n clearMeasurements() {\n const currentFeatures = this.source.getFeatures(); //returns snapshot copy of the features on the source\n this.source.clear();\n currentFeatures.forEach((feature) => {\n //raise remove-measurement event for each measurement after the source was cleared\n this.raiseMeasurementsChangeEvent(\"remove-measurement\", feature);\n });\n this.predefinedMeasurements.clear();\n for (const measurement of this.finishedMeasurements) {\n measurement.destroy();\n }\n this.finishedMeasurements.clear();\n }\n\n /** Starts measuring using the provided type. */\n startMeasurement(type: MeasurementType) {\n if (this.draw) {\n throw new Error(\"Internal error: another measurement interaction is still active.\");\n }\n\n const geometryType = type === \"area\" ? \"Polygon\" : \"LineString\";\n const draw = (this.draw = new Draw({\n source: this.source,\n type: geometryType,\n style: this.activeFeatureStyle\n }));\n this.olMap.addInteraction(draw);\n\n let measurement: MeasurementInstance | undefined;\n let changeListenerKey: EventsKey | undefined = undefined;\n draw.on(\"drawstart\", (evt) => {\n // set sketch\n const sketch = evt.feature;\n if (!sketch) {\n return;\n }\n\n measurement = this.activeMeasurement = new MeasurementInstance(\"active\", sketch, this);\n changeListenerKey = sketch.getGeometry()?.on(\"change\", () => {\n measurement?.updateTooltipContent();\n measurement?.updateTooltipPosition();\n });\n });\n\n draw.on(\"drawend\", () => {\n if (measurement && measurement === this.activeMeasurement) {\n const newMeasurement = measurement;\n newMeasurement.updateState(\"finished\");\n this.finishedMeasurements.add(newMeasurement);\n this.raiseMeasurementsChangeEvent(\"add-measurement\", newMeasurement.feature);\n this.activeMeasurement = measurement = undefined;\n }\n\n measurement = undefined;\n if (changeListenerKey) {\n unByKey(changeListenerKey);\n }\n });\n\n draw.on(\"drawabort\", () => {\n if (measurement) {\n measurement.destroy();\n if (measurement === this.activeMeasurement) {\n this.activeMeasurement = undefined;\n }\n measurement = undefined;\n }\n if (changeListenerKey) {\n unByKey(changeListenerKey);\n }\n });\n }\n\n /** Stops the current measuring started by `startMeasurement`. */\n stopMeasurement() {\n if (this.draw) {\n this.olMap.removeInteraction(this.draw);\n this.draw.abortDrawing();\n this.draw.dispose();\n this.draw = undefined;\n }\n\n this.activeMeasurement = destroyResource(this.activeMeasurement);\n }\n\n private handlePointerMove(evt: MapBrowserEvent<UIEvent>) {\n if (evt.dragging) {\n return;\n }\n\n const tooltip = this.helpTooltip;\n const helpMessage = getHelpMessage(this.messages, this.activeMeasurement);\n tooltip.setText(helpMessage);\n tooltip.overlay.setPosition(evt.coordinate);\n tooltip.element.classList.remove(\"hidden\");\n }\n\n private updatePredefinedMeasurements(geometries: MeasurementGeometry[]) {\n const addedMeasurements = geometries.filter(\n (geom) => !this.predefinedMeasurements.has(geom)\n );\n const removedMeasurements: MeasurementGeometry[] = [];\n for (const geom of this.predefinedMeasurements.keys()) {\n if (!geometries.includes(geom)) {\n removedMeasurements.push(geom);\n }\n }\n\n addedMeasurements.forEach((geom) => {\n const measurementFeature = new Feature(geom);\n this.source.addFeature(measurementFeature);\n\n const measurement = new MeasurementInstance(\"finished\", measurementFeature, this);\n this.finishedMeasurements.add(measurement);\n this.predefinedMeasurements.set(geom, measurement);\n this.raiseMeasurementsChangeEvent(\"add-measurement\", measurementFeature);\n });\n\n removedMeasurements.forEach((geom) => {\n const measurement = this.predefinedMeasurements.get(geom);\n if (measurement) {\n //remove measurement feature from source and destroy associated tooltip\n this.source.removeFeature(measurement.feature);\n this.finishedMeasurements.delete(measurement);\n measurement.destroy();\n this.raiseMeasurementsChangeEvent(\"remove-measurement\", measurement.feature);\n }\n this.predefinedMeasurements.delete(geom);\n });\n }\n\n private raiseMeasurementsChangeEvent(\n kind: MeasurementsChangeEvent[\"kind\"],\n measurementFeature: Feature\n ) {\n const measurementGeom = measurementFeature.getGeometry();\n if (this.measurementChangedHandler && measurementGeom) {\n this.measurementChangedHandler({\n kind: kind,\n geometry:\n measurementGeom instanceof Polygon\n ? (measurementGeom as Polygon)\n : (measurementGeom as LineString)\n });\n }\n }\n}\n\n// Encapsulates the display state of a measurement.\n//\n// More ideas for further improvements:\n// - Resolve duplicate source of truths (feature source and map of measurements).\n// - Add and remove the feature here as well (instead of in the controller).\n// - Perhaps use reactivity API and watch for state consistency.\n// The current implementations relies on the update*() functions being called at the correct time.\nclass MeasurementInstance {\n readonly controller: MeasurementController;\n readonly feature: Feature;\n\n private _state: \"active\" | \"finished\";\n private readonly tooltip: ReturnType<typeof createMeasureTooltip>;\n\n constructor(state: \"active\" | \"finished\", feature: Feature, controller: MeasurementController) {\n this.controller = controller;\n this._state = state;\n this.feature = feature;\n this.tooltip = createMeasureTooltip(this.olMap);\n this.updateTooltipContent();\n this.updateTooltipPosition();\n this.tooltip.setActive(state === \"active\");\n }\n\n destroy() {\n this.tooltip.destroy();\n }\n\n get state(): \"active\" | \"finished\" {\n return this._state;\n }\n\n updateState(state: \"active\" | \"finished\") {\n if (this._state === state) {\n return;\n }\n\n this._state = state;\n this.tooltip.setActive(state === \"active\");\n }\n\n // Updates the tooltip content based on the current state and the feature's geometry.\n updateTooltipContent() {\n const geometry = this.feature.getGeometry();\n if (!geometry) {\n return;\n }\n\n const projection = this.olMap.getView().getProjection();\n let outputHtml;\n if (geometry instanceof Polygon) {\n outputHtml = formatArea(geometry, projection, this.messages);\n } else if (geometry instanceof LineString) {\n outputHtml = formatLength(geometry, projection, this.messages);\n }\n if (outputHtml) {\n this.tooltip.setHtml(outputHtml);\n }\n }\n\n // Updates the tooltip's position.\n updateTooltipPosition() {\n const geometry = this.feature.getGeometry();\n if (!geometry) {\n return;\n }\n\n let tooltipCoord: Coordinate;\n if (geometry instanceof Polygon) {\n tooltipCoord = geometry.getInteriorPoint().getCoordinates() || null;\n } else if (geometry instanceof LineString) {\n tooltipCoord = geometry.getLastCoordinate() || null;\n } else {\n return;\n }\n this.tooltip.overlay.setPosition(tooltipCoord);\n }\n\n private get olMap(): OlMap {\n return this.controller.olMap;\n }\n\n private get messages(): Messages {\n return this.controller.messages;\n }\n}\n\nconst DEFAULT_MEASUREMENT_OFFSET = [0, -15];\nconst FINISHED_MEASUREMENT_OFFSET = [0, -7];\n\n/** Represents a tooltip rendered on the OpenLayers map. */\ninterface Tooltip extends Resource {\n overlay: Overlay;\n element: HTMLDivElement;\n\n setText(value: string): void;\n setHtml(value: string): void;\n}\n\nfunction createHelpTooltip(olMap: OlMap): Tooltip {\n const element = document.createElement(\"div\");\n element.className = \"measurement-tooltip printing-hide hidden\";\n element.role = \"tooltip\";\n\n const content = document.createElement(\"span\");\n element.appendChild(content);\n\n const overlay = new Overlay({\n element: element,\n offset: [15, 0],\n positioning: \"center-left\"\n });\n\n olMap.addOverlay(overlay);\n return {\n overlay,\n element,\n destroy() {\n olMap.removeOverlay(overlay);\n },\n setText(value) {\n content.textContent = value;\n },\n setHtml(value) {\n content.innerHTML = value;\n }\n };\n}\n\nfunction createMeasureTooltip(olMap: OlMap): Tooltip & { setActive(active: boolean): void } {\n const element = document.createElement(\"div\");\n element.role = \"tooltip\";\n element.className = \"measurement-tooltip measurement-active-tooltip printing-hide\";\n\n const content = document.createElement(\"span\");\n element.appendChild(content);\n\n const overlay = new Overlay({\n element: element,\n offset: DEFAULT_MEASUREMENT_OFFSET,\n positioning: \"bottom-center\",\n stopEvent: false,\n insertFirst: false\n });\n\n olMap.addOverlay(overlay);\n return {\n overlay,\n element,\n destroy() {\n olMap.removeOverlay(overlay);\n },\n setActive(active) {\n if (active) {\n element.className = \"measurement-tooltip measurement-active-tooltip printing-hide\";\n overlay.setOffset(DEFAULT_MEASUREMENT_OFFSET);\n } else {\n element.className = \"measurement-tooltip measurement-finished-tooltip\";\n overlay.setOffset(FINISHED_MEASUREMENT_OFFSET);\n }\n },\n setText(value) {\n content.textContent = value;\n },\n setHtml(value) {\n content.innerHTML = value;\n }\n };\n}\n\nfunction getHelpMessage(messages: Messages, activeMeasurement: MeasurementInstance | undefined) {\n if (activeMeasurement) {\n const geom = activeMeasurement.feature.getGeometry();\n if (geom instanceof Polygon || geom instanceof LineString) {\n return messages.getContinueMessage();\n }\n }\n return messages.getHelpMessage();\n}\n\nfunction formatArea(polygon: Polygon, projection: Projection, messages: Messages) {\n const area = getArea(polygon, { projection });\n let output;\n if (area >= 1000000) {\n output = `${messages.formatNumber(area / 1000000)} km<sup>2</sup>`;\n } else {\n output = `${messages.formatNumber(area)} m<sup>2</sup>`;\n }\n return output;\n}\n\nfunction formatLength(line: LineString, projection: Projection, messages: Messages) {\n const length = getLength(line, { projection });\n let output;\n if (length >= 1000) {\n output = `${messages.formatNumber(length / 1000)} km`;\n } else {\n output = `${messages.formatNumber(length)} m`;\n }\n return output;\n}\n"],"names":["VectorSource","VectorLayer","toStyleFunction"],"mappings":";;;;;;;;;;;;AA8BO,MAAM,qBAAsB,CAAA;AAAA,EACtB,KAAA,CAAA;AAAA,EACA,QAAA,CAAA;AAAA,EAED,kBAAA,CAAA;AAAA;AAAA;AAAA;AAAA,EAIA,KAAA,CAAA;AAAA;AAAA;AAAA;AAA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,"file":"MeasurementController.js","sources":["MeasurementController.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { destroyResource, Resource } from \"@open-pioneer/core\";\nimport { TOPMOST_LAYER_Z } from \"@open-pioneer/map\";\nimport Feature from \"ol/Feature\";\nimport OlMap from \"ol/Map\";\nimport MapBrowserEvent from \"ol/MapBrowserEvent\";\nimport { unByKey } from \"ol/Observable\";\nimport Overlay from \"ol/Overlay\";\nimport { Coordinate } from \"ol/coordinate\";\nimport { EventsKey } from \"ol/events\";\nimport { LineString, Polygon } from \"ol/geom\";\nimport Draw from \"ol/interaction/Draw\";\nimport { Vector as VectorLayer } from \"ol/layer\";\nimport { Projection } from \"ol/proj\";\nimport { Vector as VectorSource } from \"ol/source\";\nimport { getArea, getLength } from \"ol/sphere\";\nimport { StyleFunction, StyleLike, toFunction as toStyleFunction } from \"ol/style/Style\";\nimport type { MeasurementsChangeEvent, MeasurementGeometry, MeasurementProps } from \"./Measurement\";\n\ntype MeasurementsChangeHandler = NonNullable<MeasurementProps[\"onMeasurementsChange\"]>;\n\nexport type MeasurementType = \"area\" | \"distance\";\n\nexport interface Messages {\n getContinueMessage(): string;\n getHelpMessage(): string;\n formatNumber(value: number): string;\n}\n\nexport class MeasurementController {\n readonly olMap: OlMap;\n readonly messages: Messages;\n\n private activeFeatureStyle: StyleFunction | undefined;\n /**\n * The layer rendering the measurement \"features\".\n */\n private layer: VectorLayer<VectorSource, Feature>;\n\n /**\n * Source of {@link layer}.\n */\n private source: VectorSource;\n\n /**\n * Stores the current `Draw` interaction.\n */\n private draw: Draw | undefined = undefined;\n\n /**\n * The active measurement manipulated by the `draw` interaction.\n */\n private activeMeasurement: MeasurementInstance | undefined;\n\n /**\n * Map that is used to track all predefined measurements currently added to the source.\n * It associates the measurement geometry (key) with the corresponding measurement instance.\n *\n * The measurement instances here must also be contained in `finishedMeasurements`.\n */\n private predefinedMeasurements = new Map<MeasurementGeometry, MeasurementInstance>();\n\n /**\n * Measurement instances that were finished.\n */\n private finishedMeasurements = new Set<MeasurementInstance>();\n\n /**\n * The help tooltip element.\n */\n private helpTooltip: Tooltip;\n\n /**\n * Keeps track of registered event handlers.\n */\n private resources: Resource[] = [];\n\n /**\n * Called when a measurement is added to or removed from the source.\n */\n private measurementChangedHandler: MeasurementsChangeHandler | undefined;\n\n constructor(olMap: OlMap, messages: Messages) {\n this.olMap = olMap;\n this.messages = messages;\n const source = (this.source = new VectorSource());\n this.layer = new VectorLayer({\n source: source,\n zIndex: TOPMOST_LAYER_Z,\n properties: {\n name: \"measurement-layer\"\n }\n });\n olMap.addLayer(this.layer);\n\n const pointerMoveKey = olMap.on(\"pointermove\", this.handlePointerMove.bind(this));\n this.resources.push({\n destroy() {\n unByKey(pointerMoveKey);\n }\n });\n\n const mouseOutHandler = () => {\n this.helpTooltip.element.classList.add(\"hidden\");\n };\n olMap.getViewport().addEventListener(\"mouseout\", mouseOutHandler);\n this.resources.push({\n destroy() {\n olMap.getViewport().removeEventListener(\"mouseout\", mouseOutHandler);\n }\n });\n\n this.helpTooltip = createHelpTooltip(this.olMap);\n }\n\n destroy() {\n this.stopMeasurement();\n\n // Cleanup registered event handlers etc.\n for (const resource of this.resources) {\n resource.destroy();\n }\n this.resources = [];\n\n // Cleanup measurements and tooltips.\n this.activeMeasurement = destroyResource(this.activeMeasurement);\n for (const measurement of this.finishedMeasurements) {\n measurement.destroy();\n }\n this.finishedMeasurements.clear();\n this.helpTooltip.destroy();\n\n // Cleanup layer\n this.olMap.removeLayer(this.layer);\n this.layer.dispose();\n this.source.dispose();\n\n this.measurementChangedHandler = undefined;\n this.predefinedMeasurements.clear();\n }\n\n /** Returns the vector layer used for finished features. */\n getVectorLayer() {\n return this.layer;\n }\n\n /** Updates the style used for finished features. */\n setFinishedFeatureStyle(style: StyleLike) {\n this.layer.setStyle(style);\n }\n\n setMeasurementSourceChangedHandler(handler: MeasurementsChangeHandler | undefined) {\n this.measurementChangedHandler = handler;\n }\n\n setPredefinedMeasurements(geometries: MeasurementGeometry[]) {\n this.updatePredefinedMeasurements(geometries);\n }\n\n /** Updates the style used for active measurements. */\n setActiveFeatureStyle(style: StyleLike) {\n const styleFunction = toStyleFunction(style);\n this.activeFeatureStyle = (feature, ...args) => {\n const ft = feature?.getGeometry()?.getType();\n if (ft === \"Polygon\" || ft === \"LineString\" || ft === \"Point\") {\n return styleFunction(feature, ...args);\n }\n };\n // Update style on current draw instance (if any)\n this.draw?.getOverlay().setStyle(this.activeFeatureStyle);\n }\n\n /** Removes all finished measurements. */\n clearMeasurements() {\n const currentFeatures = this.source.getFeatures(); //returns snapshot copy of the features on the source\n this.source.clear();\n currentFeatures.forEach((feature) => {\n //raise remove-measurement event for each measurement after the source was cleared\n this.raiseMeasurementsChangeEvent(\"remove-measurement\", feature);\n });\n this.predefinedMeasurements.clear();\n for (const measurement of this.finishedMeasurements) {\n measurement.destroy();\n }\n this.finishedMeasurements.clear();\n }\n\n /** Starts measuring using the provided type. */\n startMeasurement(type: MeasurementType) {\n if (this.draw) {\n throw new Error(\"Internal error: another measurement interaction is still active.\");\n }\n\n const geometryType = type === \"area\" ? \"Polygon\" : \"LineString\";\n const draw = (this.draw = new Draw({\n source: this.source,\n type: geometryType,\n style: this.activeFeatureStyle\n }));\n this.olMap.addInteraction(draw);\n\n let measurement: MeasurementInstance | undefined;\n let changeListenerKey: EventsKey | undefined = undefined;\n draw.on(\"drawstart\", (evt) => {\n // set sketch\n const sketch = evt.feature;\n if (!sketch) {\n return;\n }\n\n measurement = this.activeMeasurement = new MeasurementInstance(\"active\", sketch, this);\n changeListenerKey = sketch.getGeometry()?.on(\"change\", () => {\n measurement?.updateTooltipContent();\n measurement?.updateTooltipPosition();\n });\n });\n\n draw.on(\"drawend\", () => {\n if (measurement && measurement === this.activeMeasurement) {\n const newMeasurement = measurement;\n newMeasurement.updateState(\"finished\");\n this.finishedMeasurements.add(newMeasurement);\n this.raiseMeasurementsChangeEvent(\"add-measurement\", newMeasurement.feature);\n this.activeMeasurement = measurement = undefined;\n }\n\n measurement = undefined;\n if (changeListenerKey) {\n unByKey(changeListenerKey);\n }\n });\n\n draw.on(\"drawabort\", () => {\n if (measurement) {\n measurement.destroy();\n if (measurement === this.activeMeasurement) {\n this.activeMeasurement = undefined;\n }\n measurement = undefined;\n }\n if (changeListenerKey) {\n unByKey(changeListenerKey);\n }\n });\n }\n\n /** Stops the current measuring started by `startMeasurement`. */\n stopMeasurement() {\n if (this.draw) {\n this.olMap.removeInteraction(this.draw);\n this.draw.abortDrawing();\n this.draw.dispose();\n this.draw = undefined;\n }\n\n this.activeMeasurement = destroyResource(this.activeMeasurement);\n }\n\n private handlePointerMove(evt: MapBrowserEvent<UIEvent>) {\n if (evt.dragging) {\n return;\n }\n\n const tooltip = this.helpTooltip;\n const helpMessage = getHelpMessage(this.messages, this.activeMeasurement);\n tooltip.setText(helpMessage);\n tooltip.overlay.setPosition(evt.coordinate);\n tooltip.element.classList.remove(\"hidden\");\n }\n\n private updatePredefinedMeasurements(geometries: MeasurementGeometry[]) {\n const addedMeasurements = geometries.filter(\n (geom) => !this.predefinedMeasurements.has(geom)\n );\n const removedMeasurements: MeasurementGeometry[] = [];\n for (const geom of this.predefinedMeasurements.keys()) {\n if (!geometries.includes(geom)) {\n removedMeasurements.push(geom);\n }\n }\n\n addedMeasurements.forEach((geom) => {\n const measurementFeature = new Feature(geom);\n this.source.addFeature(measurementFeature);\n\n const measurement = new MeasurementInstance(\"finished\", measurementFeature, this);\n this.finishedMeasurements.add(measurement);\n this.predefinedMeasurements.set(geom, measurement);\n this.raiseMeasurementsChangeEvent(\"add-measurement\", measurementFeature);\n });\n\n removedMeasurements.forEach((geom) => {\n const measurement = this.predefinedMeasurements.get(geom);\n if (measurement) {\n //remove measurement feature from source and destroy associated tooltip\n this.source.removeFeature(measurement.feature);\n this.finishedMeasurements.delete(measurement);\n measurement.destroy();\n this.raiseMeasurementsChangeEvent(\"remove-measurement\", measurement.feature);\n }\n this.predefinedMeasurements.delete(geom);\n });\n }\n\n private raiseMeasurementsChangeEvent(\n kind: MeasurementsChangeEvent[\"kind\"],\n measurementFeature: Feature\n ) {\n const measurementGeom = measurementFeature.getGeometry();\n if (this.measurementChangedHandler && measurementGeom) {\n this.measurementChangedHandler({\n kind: kind,\n geometry:\n measurementGeom instanceof Polygon\n ? (measurementGeom as Polygon)\n : (measurementGeom as LineString)\n });\n }\n }\n}\n\n// Encapsulates the display state of a measurement.\n//\n// More ideas for further improvements:\n// - Resolve duplicate source of truths (feature source and map of measurements).\n// - Add and remove the feature here as well (instead of in the controller).\n// - Perhaps use reactivity API and watch for state consistency.\n// The current implementations relies on the update*() functions being called at the correct time.\nclass MeasurementInstance {\n readonly controller: MeasurementController;\n readonly feature: Feature;\n\n private _state: \"active\" | \"finished\";\n private readonly tooltip: ReturnType<typeof createMeasureTooltip>;\n\n constructor(state: \"active\" | \"finished\", feature: Feature, controller: MeasurementController) {\n this.controller = controller;\n this._state = state;\n this.feature = feature;\n this.tooltip = createMeasureTooltip(this.olMap);\n this.updateTooltipContent();\n this.updateTooltipPosition();\n this.tooltip.setActive(state === \"active\");\n }\n\n destroy() {\n this.tooltip.destroy();\n }\n\n get state(): \"active\" | \"finished\" {\n return this._state;\n }\n\n updateState(state: \"active\" | \"finished\") {\n if (this._state === state) {\n return;\n }\n\n this._state = state;\n this.tooltip.setActive(state === \"active\");\n }\n\n // Updates the tooltip content based on the current state and the feature's geometry.\n updateTooltipContent() {\n const geometry = this.feature.getGeometry();\n if (!geometry) {\n return;\n }\n\n const projection = this.olMap.getView().getProjection();\n let outputHtml;\n if (geometry instanceof Polygon) {\n outputHtml = formatArea(geometry, projection, this.messages);\n } else if (geometry instanceof LineString) {\n outputHtml = formatLength(geometry, projection, this.messages);\n }\n if (outputHtml) {\n this.tooltip.setHtml(outputHtml);\n }\n }\n\n // Updates the tooltip's position.\n updateTooltipPosition() {\n const geometry = this.feature.getGeometry();\n if (!geometry) {\n return;\n }\n\n let tooltipCoord: Coordinate;\n if (geometry instanceof Polygon) {\n tooltipCoord = geometry.getInteriorPoint().getCoordinates() || null;\n } else if (geometry instanceof LineString) {\n tooltipCoord = geometry.getLastCoordinate() || null;\n } else {\n return;\n }\n this.tooltip.overlay.setPosition(tooltipCoord);\n }\n\n private get olMap(): OlMap {\n return this.controller.olMap;\n }\n\n private get messages(): Messages {\n return this.controller.messages;\n }\n}\n\nconst DEFAULT_MEASUREMENT_OFFSET = [0, -15];\nconst FINISHED_MEASUREMENT_OFFSET = [0, -7];\n\n/** Represents a tooltip rendered on the OpenLayers map. */\ninterface Tooltip extends Resource {\n overlay: Overlay;\n element: HTMLDivElement;\n\n setText(value: string): void;\n setHtml(value: string): void;\n}\n\nfunction createHelpTooltip(olMap: OlMap): Tooltip {\n const element = document.createElement(\"div\");\n element.className = \"measurement-tooltip printing-hide hidden\";\n element.role = \"tooltip\";\n\n const content = document.createElement(\"span\");\n element.appendChild(content);\n\n const overlay = new Overlay({\n element: element,\n offset: [15, 0],\n positioning: \"center-left\"\n });\n\n olMap.addOverlay(overlay);\n return {\n overlay,\n element,\n destroy() {\n olMap.removeOverlay(overlay);\n },\n setText(value) {\n content.textContent = value;\n },\n setHtml(value) {\n content.innerHTML = value;\n }\n };\n}\n\nfunction createMeasureTooltip(olMap: OlMap): Tooltip & { setActive(active: boolean): void } {\n const element = document.createElement(\"div\");\n element.role = \"tooltip\";\n element.className = \"measurement-tooltip measurement-active-tooltip printing-hide\";\n\n const content = document.createElement(\"span\");\n element.appendChild(content);\n\n const overlay = new Overlay({\n element: element,\n offset: DEFAULT_MEASUREMENT_OFFSET,\n positioning: \"bottom-center\",\n stopEvent: false,\n insertFirst: false\n });\n\n olMap.addOverlay(overlay);\n return {\n overlay,\n element,\n destroy() {\n olMap.removeOverlay(overlay);\n },\n setActive(active) {\n if (active) {\n element.className = \"measurement-tooltip measurement-active-tooltip printing-hide\";\n overlay.setOffset(DEFAULT_MEASUREMENT_OFFSET);\n } else {\n element.className = \"measurement-tooltip measurement-finished-tooltip\";\n overlay.setOffset(FINISHED_MEASUREMENT_OFFSET);\n }\n },\n setText(value) {\n content.textContent = value;\n },\n setHtml(value) {\n content.innerHTML = value;\n }\n };\n}\n\nfunction getHelpMessage(messages: Messages, activeMeasurement: MeasurementInstance | undefined) {\n if (activeMeasurement) {\n const geom = activeMeasurement.feature.getGeometry();\n if (geom instanceof Polygon || geom instanceof LineString) {\n return messages.getContinueMessage();\n }\n }\n return messages.getHelpMessage();\n}\n\nfunction formatArea(polygon: Polygon, projection: Projection, messages: Messages) {\n const area = getArea(polygon, { projection });\n let output;\n if (area >= 1000000) {\n output = `${messages.formatNumber(area / 1000000)} km<sup>2</sup>`;\n } else {\n output = `${messages.formatNumber(area)} m<sup>2</sup>`;\n }\n return output;\n}\n\nfunction formatLength(line: LineString, projection: Projection, messages: Messages) {\n const length = getLength(line, { projection });\n let output;\n if (length >= 1000) {\n output = `${messages.formatNumber(length / 1000)} km`;\n } else {\n output = `${messages.formatNumber(length)} m`;\n }\n return output;\n}\n"],"names":["VectorSource","VectorLayer","toStyleFunction"],"mappings":";;;;;;;;;;;;AA8BO,MAAM,qBAAsB,CAAA;AAAA,EACtB,KAAA,CAAA;AAAA,EACA,QAAA,CAAA;AAAA,EAED,kBAAA,CAAA;AAAA;AAAA;AAAA;AAAA,EAIA,KAAA,CAAA;AAAA;AAAA;AAAA;AAAA,EAKA,MAAA,CAAA;AAAA;AAAA;AAAA;AAAA,EAKA,IAAyB,GAAA,KAAA,CAAA,CAAA;AAAA;AAAA;AAAA;AAAA,EAKzB,iBAAA,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,sBAAA,uBAA6B,GAA8C,EAAA,CAAA;AAAA;AAAA;AAAA;AAAA,EAK3E,oBAAA,uBAA2B,GAAyB,EAAA,CAAA;AAAA;AAAA;AAAA;AAAA,EAKpD,WAAA,CAAA;AAAA;AAAA;AAAA;AAAA,EAKA,YAAwB,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AAS,EAAA,EAAE,YAAY,CAAA,CAAA;AAC5C,EAAI,IAAA,MAAA,CAAA;AACJ,EAAA,IAAI,QAAQ,GAAS,EAAA;AACjB,IAAA,MAAA,GAAS,CAAG,EAAA,QAAA,CAAS,YAAa,CAAA,IAAA,GAAO,GAAO,CAAC,CAAA,eAAA,CAAA,CAAA;AAAA,GAC9C,MAAA;AACH,IAAA,MAAA,GAAS,CAAG,EAAA,QAAA,CAAS,YAAa,CAAA,IAAI,CAAC,CAAA,cAAA,CAAA,CAAA;AAAA,GAC3C;AACA,EAAO,OAAA,MAAA,CAAA;AACX,CAAA;AAEA,SAAS,YAAA,CAAa,IAAkB,EAAA,UAAA,EAAwB,QAAoB,EAAA;AAChF,EAAA,MAAM,MAAS,GAAA,SAAA,CAAU,IAAM,EAAA,EAAE,YAAY,CAAA,CAAA;AAC7C,EAAI,IAAA,MAAA,CAAA;AACJ,EAAA,IAAI,UAAU,GAAM,EAAA;AAChB,IAAA,MAAA,GAAS,CAAG,EAAA,QAAA,CAAS,YAAa,CAAA,MAAA,GAAS,GAAI,CAAC,CAAA,GAAA,CAAA,CAAA;AAAA,GAC7C,MAAA;AACH,IAAA,MAAA,GAAS,CAAG,EAAA,QAAA,CAAS,YAAa,CAAA,MAAM,CAAC,CAAA,EAAA,CAAA,CAAA;AAAA,GAC7C;AACA,EAAO,OAAA,MAAA,CAAA;AACX;;;;"}
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/MeasurementController";
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.4",
4
+ "version": "0.8.0-dev.20241120115147",
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
- "peerDependencies": {
17
- "@open-pioneer/chakra-integration": "^1.1.4",
18
- "@open-pioneer/core": "^1.3.0",
19
- "@open-pioneer/react-utils": "^1.0.1",
20
- "@open-pioneer/runtime": "^2.1.7",
16
+ "dependencies": {
17
+ "@open-pioneer/chakra-integration": "^2.4.0-dev.20241120092632",
18
+ "@open-pioneer/core": "^2.4.0-dev.20241120092632",
19
+ "@open-pioneer/react-utils": "^2.4.0-dev.20241120092632",
20
+ "@open-pioneer/runtime": "^2.4.0-dev.20241120092632",
21
21
  "classnames": "^2.3.2",
22
- "ol": "^9.2.4",
22
+ "ol": "^10.2.1",
23
23
  "react": "^18.3.1",
24
- "@open-pioneer/map": "^0.6.1"
24
+ "@open-pioneer/map": "^0.8.0-dev.20241120115147"
25
25
  },
26
26
  "exports": {
27
27
  "./package.json": "./package.json",