From 694202455a651087d9c5f9cc2ab87bf2d46ce837 Mon Sep 17 00:00:00 2001 From: Fritz Hoeing Date: Thu, 23 Nov 2023 13:16:43 +0100 Subject: [PATCH 1/3] feat: adds a radius property to the measure circle button --- src/Button/MeasureButton/MeasureButton.tsx | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/Button/MeasureButton/MeasureButton.tsx b/src/Button/MeasureButton/MeasureButton.tsx index 70e94ed5d6..fb5d107a09 100644 --- a/src/Button/MeasureButton/MeasureButton.tsx +++ b/src/Button/MeasureButton/MeasureButton.tsx @@ -121,6 +121,10 @@ interface OwnProps { * Whether the measure is using geodesic or cartesian mode. Geodesic is used by default. */ geodesic: boolean; + /** + * If set true, instead of the area, the radius will be measured. + */ + measureRadius?: boolean; } export type MeasureType = 'line' | 'polygon' | 'angle' | 'circle'; @@ -156,7 +160,8 @@ class MeasureButton extends React.Component { }, pressed: false, onToggle: () => undefined, - geodesic: true + geodesic: true, + measureRadius: false }; /** @@ -831,7 +836,8 @@ class MeasureButton extends React.Component { measureType, decimalPlacesInTooltips, map, - geodesic + geodesic, + measureRadius } = this.props; if (!this._measureTooltipElement) { @@ -852,7 +858,13 @@ class MeasureButton extends React.Component { if (geom instanceof OlGeomCircle) { measureTooltipCoord = geom.getLastCoordinate(); - output = MeasureUtil.formatArea(geom, map, decimalPlacesInTooltips, geodesic); + if (!measureRadius) { + output = MeasureUtil.formatArea(geom, map, decimalPlacesInTooltips, geodesic); + } else { + const decimalHelper = Math.pow(10, decimalPlacesInTooltips); + const radius = Math.round(geom.getRadius() * decimalHelper) / decimalHelper; + output = `${radius.toString()} m`; + } } else if (geom instanceof OlGeomPolygon) { output = MeasureUtil.formatArea(geom, map, decimalPlacesInTooltips, geodesic); // attach area at interior point From 72b0e63f0ba7c6aee7ef7b336db359742e476de4 Mon Sep 17 00:00:00 2001 From: Fritz Hoeing Date: Thu, 23 Nov 2023 13:46:32 +0100 Subject: [PATCH 2/3] feat: adds readable unit based on actual distance --- src/Button/MeasureButton/MeasureButton.tsx | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Button/MeasureButton/MeasureButton.tsx b/src/Button/MeasureButton/MeasureButton.tsx index fb5d107a09..e23f631410 100644 --- a/src/Button/MeasureButton/MeasureButton.tsx +++ b/src/Button/MeasureButton/MeasureButton.tsx @@ -861,9 +861,14 @@ class MeasureButton extends React.Component { if (!measureRadius) { output = MeasureUtil.formatArea(geom, map, decimalPlacesInTooltips, geodesic); } else { + const area = MeasureUtil.getAreaOfCircle(geom, map); const decimalHelper = Math.pow(10, decimalPlacesInTooltips); const radius = Math.round(geom.getRadius() * decimalHelper) / decimalHelper; output = `${radius.toString()} m`; + if (area > (Math.PI * 1000000)) { + output = (Math.round(geom.getRadius() / 100 * decimalHelper) / + decimalHelper) + ' km'; + } } } else if (geom instanceof OlGeomPolygon) { output = MeasureUtil.formatArea(geom, map, decimalPlacesInTooltips, geodesic); From 14fc3e8d898266a7117e0220ab8a9a287feae651 Mon Sep 17 00:00:00 2001 From: Fritz Hoeing Date: Thu, 23 Nov 2023 13:49:37 +0100 Subject: [PATCH 3/3] fix: fixing number typo --- src/Button/MeasureButton/MeasureButton.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Button/MeasureButton/MeasureButton.tsx b/src/Button/MeasureButton/MeasureButton.tsx index e23f631410..2af9473107 100644 --- a/src/Button/MeasureButton/MeasureButton.tsx +++ b/src/Button/MeasureButton/MeasureButton.tsx @@ -866,7 +866,7 @@ class MeasureButton extends React.Component { const radius = Math.round(geom.getRadius() * decimalHelper) / decimalHelper; output = `${radius.toString()} m`; if (area > (Math.PI * 1000000)) { - output = (Math.round(geom.getRadius() / 100 * decimalHelper) / + output = (Math.round(geom.getRadius() / 1000 * decimalHelper) / decimalHelper) + ' km'; } }