Skip to content

Commit

Permalink
Merge pull request #1003 from geoadmin/fix-PB-792-measuring-area-roun…
Browse files Browse the repository at this point in the history
…ding-issue

PB-792: Change rounding and decimal places threshold - #patch
  • Loading branch information
LukasJoss authored Jul 16, 2024
2 parents 572c38f + 080cd0b commit c6598cb
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 15 deletions.
21 changes: 9 additions & 12 deletions src/modules/infobox/components/FeatureAreaInfo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { useStore } from 'vuex'
import { useTippyTooltip } from '@/utils/composables/useTippyTooltip'
import { WGS84 } from '@/utils/coordinates/coordinateSystems'
import { reprojectGeoJsonData, transformIntoTurfEquivalent } from '@/utils/geoJsonUtils'
import { round } from '@/utils/numberUtils'
const props = defineProps({
geometry: {
Expand Down Expand Up @@ -34,22 +33,20 @@ const humanReadableArea = computed(() => {
const calculatedArea = area(transformIntoTurfEquivalent(geometryWgs84.value))
let result = ''
if (calculatedArea) {
result += roundValueIfGreaterThan(calculatedArea, 1000, 1000000)
if (calculatedArea > 10000) {
result += ' km'
} else {
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 += ' m'
} else {
result += ' km'
}
}
return result
})
function roundValueIfGreaterThan(value, threshold, divider) {
if (value > threshold) {
return `${round(value / divider, 2)}`
}
return `${round(value, 2)}`
}
</script>
<template>
Expand Down
32 changes: 29 additions & 3 deletions tests/cypress/tests-e2e/drawing.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -586,9 +586,6 @@ describe('Drawing module tests', () => {
const [polygonCoordinates] = polygon.getGeometry().getCoordinates()
expect(polygonCoordinates).to.be.an('Array').lengthOf(4)
})
cy.get('[data-cy="feature-area-information"]')
.should('be.visible')
.contains('187.22 km')

// Changing the color of the polygon and checking that the KMl was updated accordingly
cy.get('[data-cy="drawing-style-line-button"]').click()
Expand Down Expand Up @@ -628,6 +625,35 @@ describe('Drawing module tests', () => {
const line = features[1]
expect(line.getGeometry().getCoordinates().length).to.eq(2)
})

cy.goToMapView(
{
zoom: 6,
},
false
)

cy.log('Feature Area Info should be in meters below unit threshold')
cy.goToDrawing()
cy.clickDrawingTool(EditableFeatureTypes.LINEPOLYGON)

cy.get('[data-cy="ol-map"]').click(100, 200)
cy.get('[data-cy="ol-map"]').click(150, 200)
cy.get('[data-cy="ol-map"]').click(150, 230)
cy.get('[data-cy="ol-map"]').click(100, 200)
cy.get('[data-cy="feature-area-information"]').should('be.visible').contains('74802 m2')

cy.log('Feature Area Info should be in kilometers above unit threshold')
cy.clickDrawingTool(EditableFeatureTypes.LINEPOLYGON)

cy.get('[data-cy="ol-map"]').click(200, 200)
cy.get('[data-cy="ol-map"]').click(150, 200)
cy.get('[data-cy="ol-map"]').click(150, 300)
cy.get('[data-cy="ol-map"]').click(200, 200)

cy.get('[data-cy="feature-area-information"]')
.should('be.visible')
.contains('0.24935 km2')
})
})
context('KML management', () => {
Expand Down

0 comments on commit c6598cb

Please sign in to comment.