From 9a38e38a0e02c4dd0a17368f2eb341a75266cd5d Mon Sep 17 00:00:00 2001 From: "SYSTEMPLUS\\tle" Date: Wed, 7 Dec 2022 18:28:44 +0100 Subject: [PATCH 1/2] terrestris#503 add mm to formatLength and formatArea --- src/MeasureUtil/MeasureUtil.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/MeasureUtil/MeasureUtil.ts b/src/MeasureUtil/MeasureUtil.ts index 56aa8687c..ea8752e7e 100644 --- a/src/MeasureUtil/MeasureUtil.ts +++ b/src/MeasureUtil/MeasureUtil.ts @@ -55,9 +55,12 @@ class MeasureUtil { if (length > 1000) { output = (Math.round(length / 1000 * decimalHelper) / decimalHelper) + ' km'; - } else { + } else if (length > 1) { output = (Math.round(length * decimalHelper) / decimalHelper) + ' m'; + } else { + output = (Math.round(length * 1000 * decimalHelper) / decimalHelper) + + ' mm'; } return output; } @@ -107,9 +110,12 @@ class MeasureUtil { if (area > 10000) { output = (Math.round(area / 1000000 * decimalHelper) / decimalHelper) + ' km2'; - } else { + } else if (area > 0.01) { output = (Math.round(area * decimalHelper) / decimalHelper) + ' m2'; + } else { + output = (Math.round(area * 1000000 * decimalHelper) / decimalHelper) + + ' mm2'; } return output; } From a08f8579ebc820ccf966cd353cf4f7c3f60b8bab Mon Sep 17 00:00:00 2001 From: "SYSTEMPLUS\\tle" Date: Thu, 22 Dec 2022 00:35:16 +0100 Subject: [PATCH 2/2] terrestris#503 add a test, update api doc --- src/MeasureUtil/MeasureUtil.spec.ts | 8 ++++++++ src/MeasureUtil/MeasureUtil.ts | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/MeasureUtil/MeasureUtil.spec.ts b/src/MeasureUtil/MeasureUtil.spec.ts index ce4e5c988..879daeeb1 100644 --- a/src/MeasureUtil/MeasureUtil.spec.ts +++ b/src/MeasureUtil/MeasureUtil.spec.ts @@ -60,17 +60,21 @@ describe('MeasureUtil', () => { const start = [0, 0]; const end = [0, 100]; const end2 = [0, 100550]; + const end3 = [0, 0.1]; const shortLine = new OlGeomLineString([start, end]); const longLine = new OlGeomLineString([start, end2]); + const veryShortLine = new OlGeomLineString([start, end3]); map = TestUtil.createMap(); const expectedShortLength = MeasureUtil.formatLength(shortLine, map, 2); const expectedLongLength = MeasureUtil.formatLength(longLine, map, 2); + const expectedVeryShortLength = MeasureUtil.formatLength(veryShortLine, map, 2); expect(expectedShortLength).toBe('99.89 m'); expect(expectedLongLength).toBe('100.43 km'); + expect(expectedVeryShortLength).toBe('99.89 mm'); TestUtil.removeMap(map); }); @@ -104,17 +108,21 @@ describe('MeasureUtil', () => { }); it('formats the area of a polygon as expected', () => { const bigPolyCoords = smallPolyCoords.map(coord => [coord[0] * 100, coord[1] * 100]); + const verySmallPolyCoords = smallPolyCoords.map(coord => [coord[0] / 100, coord[1] / 100]); const smallPoly = new OlGeomPolygon([smallPolyCoords]); const bigPoly = new OlGeomPolygon([bigPolyCoords]); + const verySmallPoly = new OlGeomPolygon([verySmallPolyCoords]); map = TestUtil.createMap(); const expectedSmallArea = MeasureUtil.formatArea(smallPoly, map, 2); const expectedBigArea = MeasureUtil.formatArea(bigPoly, map, 2); + const expectedVerySmallArea = MeasureUtil.formatArea(verySmallPoly, map, 2); expect(expectedSmallArea).toBe('99.78 m2'); expect(expectedBigArea).toBe('1 km2'); + expect(expectedVerySmallArea).toBe('9977.66 mm2'); TestUtil.removeMap(map); }); diff --git a/src/MeasureUtil/MeasureUtil.ts b/src/MeasureUtil/MeasureUtil.ts index ea8752e7e..6450de2f6 100644 --- a/src/MeasureUtil/MeasureUtil.ts +++ b/src/MeasureUtil/MeasureUtil.ts @@ -44,7 +44,7 @@ class MeasureUtil { * allowed for the measure tooltips * @param {boolean} geodesic Is the measurement geodesic (default is true). * - * @return {string} The formatted length of the line. + * @return {string} The formatted length of the line (units: km, m or mm). */ static formatLength( line: OlGeomLineString, map: OlMap, decimalPlacesInToolTips: number, geodesic = true