From 82e91fc4a10d3b81da15d802d6774650f1799933 Mon Sep 17 00:00:00 2001 From: Lukas Joss Date: Fri, 12 Jul 2024 09:36:51 +0200 Subject: [PATCH 1/2] PB-792: Change rounding and decimal places threshold --- .../infobox/components/FeatureAreaInfo.vue | 16 +++++++--------- tests/cypress/tests-e2e/drawing.cy.js | 2 +- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/modules/infobox/components/FeatureAreaInfo.vue b/src/modules/infobox/components/FeatureAreaInfo.vue index 7250de67b..dfd077960 100644 --- a/src/modules/infobox/components/FeatureAreaInfo.vue +++ b/src/modules/infobox/components/FeatureAreaInfo.vue @@ -34,8 +34,13 @@ const humanReadableArea = computed(() => { const calculatedArea = area(transformIntoTurfEquivalent(geometryWgs84.value)) let result = '' if (calculatedArea) { - result += roundValueIfGreaterThan(calculatedArea, 1000, 1000000) - if (calculatedArea > 10000) { + const unitThreshold = 1e5 + const divider = 1e6 + const precision = 5 + + const value = calculatedArea < unitThreshold ? calculatedArea : calculatedArea / divider + result += parseFloat(value.toPrecision(precision)) + if (calculatedArea >= unitThreshold) { result += ' km' } else { result += ' m' @@ -43,13 +48,6 @@ const humanReadableArea = computed(() => { } return result }) - -function roundValueIfGreaterThan(value, threshold, divider) { - if (value > threshold) { - return `${round(value / divider, 2)}` - } - return `${round(value, 2)}` -}