From 622c40a28adfe075ceab23b1364a0596d2d71b39 Mon Sep 17 00:00:00 2001 From: bdachary Date: Tue, 12 Sep 2023 10:53:34 +0200 Subject: [PATCH 1/3] fix: added getLength decimal precision for non geodesic map BREAKING CHANGE: change default decimal precision to 10^6 --- src/MeasureUtil/MeasureUtil.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/MeasureUtil/MeasureUtil.ts b/src/MeasureUtil/MeasureUtil.ts index 2a85e35a6..2f8f83c19 100644 --- a/src/MeasureUtil/MeasureUtil.ts +++ b/src/MeasureUtil/MeasureUtil.ts @@ -27,6 +27,7 @@ class MeasureUtil { * @return {number} The length of line in meters. */ static getLength(line: OlGeomLineString, map: OlMap, geodesic: boolean = true, radius: number = 6371008.8): number { + const decimalPrecision = Math.pow(10, 6); if (geodesic) { const opts = { projection: map.getView().getProjection().getCode(), @@ -34,7 +35,7 @@ class MeasureUtil { }; return getLength(line, opts); } else { - return Math.round(line.getLength() * 100) / 100; + return Math.round(line.getLength() * decimalPrecision) / decimalPrecision; } } From eadd2ff58acc3f9444542859ef3f787f07bc8eb9 Mon Sep 17 00:00:00 2001 From: bdachary Date: Tue, 12 Sep 2023 14:44:28 +0200 Subject: [PATCH 2/3] fix: set length decimal precision to function parameters BREAKING CHANGE: change default decimal precision to 10^6 --- src/MeasureUtil/MeasureUtil.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/MeasureUtil/MeasureUtil.ts b/src/MeasureUtil/MeasureUtil.ts index 2f8f83c19..c27987c65 100644 --- a/src/MeasureUtil/MeasureUtil.ts +++ b/src/MeasureUtil/MeasureUtil.ts @@ -22,12 +22,20 @@ class MeasureUtil { * @param {OlMap} map An OlMap. * @param {boolean} geodesic Is the measurement geodesic (default is true). * @param {number} radius Sphere radius. By default, the radius of the earth - * is used (Clarke 1866 Authalic Sphere, 6371008.8). + * is used (Clarke 1866 Authalic Sphere, 6371008.8). + * @param {number} decimalPrecision Set the decimal precision before rounding + * length value on non-geodesic map (default value 6) * * @return {number} The length of line in meters. */ - static getLength(line: OlGeomLineString, map: OlMap, geodesic: boolean = true, radius: number = 6371008.8): number { - const decimalPrecision = Math.pow(10, 6); + static getLength( + line: OlGeomLineString, + map: OlMap, + geodesic: boolean = true, + radius: number = 6371008.8, + decimalPrecision: number = 6 + ): number { + const decimalHelper = Math.pow(10, decimalPrecision); if (geodesic) { const opts = { projection: map.getView().getProjection().getCode(), @@ -35,7 +43,7 @@ class MeasureUtil { }; return getLength(line, opts); } else { - return Math.round(line.getLength() * decimalPrecision) / decimalPrecision; + return Math.round(line.getLength() * decimalHelper) / decimalHelper; } } From 868cd7b07c592ca942cb228e5f4dd5e7edbfacb7 Mon Sep 17 00:00:00 2001 From: bdachary Date: Tue, 12 Sep 2023 14:50:51 +0200 Subject: [PATCH 3/3] fix: add comment for the decimal precision parameter BREAKING CHANGE: change default decimal precision to 10^6 --- src/MeasureUtil/MeasureUtil.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/MeasureUtil/MeasureUtil.ts b/src/MeasureUtil/MeasureUtil.ts index c27987c65..b8e5f4b8d 100644 --- a/src/MeasureUtil/MeasureUtil.ts +++ b/src/MeasureUtil/MeasureUtil.ts @@ -22,9 +22,9 @@ class MeasureUtil { * @param {OlMap} map An OlMap. * @param {boolean} geodesic Is the measurement geodesic (default is true). * @param {number} radius Sphere radius. By default, the radius of the earth - * is used (Clarke 1866 Authalic Sphere, 6371008.8). - * @param {number} decimalPrecision Set the decimal precision before rounding - * length value on non-geodesic map (default value 6) + * is used (Clarke 1866 Authalic Sphere, 6371008.8). + * @param {number} decimalPrecision Set the decimal precision on length value + * for non-geodesic map (default value 6) * * @return {number} The length of line in meters. */