From 693b32c0ee172d433f0138e3c32de2a9ef449f0a Mon Sep 17 00:00:00 2001 From: Philip Beelmann Date: Thu, 27 Apr 2023 09:13:13 +0000 Subject: [PATCH] refactor getMeasure function --- umap/static/umap/js/umap.controls.js | 4 +++- umap/static/umap/js/umap.features.js | 29 ++++++---------------------- 2 files changed, 9 insertions(+), 24 deletions(-) diff --git a/umap/static/umap/js/umap.controls.js b/umap/static/umap/js/umap.controls.js index de8d540b..3f61c09a 100644 --- a/umap/static/umap/js/umap.controls.js +++ b/umap/static/umap/js/umap.controls.js @@ -1262,7 +1262,9 @@ L.U.Editable = L.Editable.extend({ content = L._('Click to start drawing a line'); } } else { - var readableDistance = e.layer.getMeasure(e.latlng); + var tmpLatLngs = this.editor._drawnLatLngs.slice(); + tmpLatLngs.push(e.latlng); + var readableDistance = e.layer.getMeasure(tmpLatLngs); if (e.layer.editor._drawnLatLngs.length < e.layer.editor.MIN_VERTEX) { // when drawing second point content = L._('Click to continue drawing ({distance})', { distance: readableDistance }); diff --git a/umap/static/umap/js/umap.features.js b/umap/static/umap/js/umap.features.js index 8934ed85..d9fc87d2 100644 --- a/umap/static/umap/js/umap.features.js +++ b/umap/static/umap/js/umap.features.js @@ -853,17 +853,9 @@ L.U.Polyline = L.Polyline.extend({ return 'polyline'; }, - getMeasure: function (extraPoint) { - var polyline; - if (extraPoint){ - var tmpLatLngs = this.editor._drawnLatLngs.slice(); - tmpLatLngs.push(extraPoint); - polyline = tmpLatLngs; - } else { - polyline = this._defaultShape(); - } - var length = L.GeoUtil.lineLength(this.map, polyline); - return L.GeoUtil.readableDistance(length, this.map.measureTools.getMeasureUnit()); + getMeasure: function (shape) { + var measure = L.GeoUtil.lineLength(this.map, shape | this._defaultShape()); + return L.GeoUtil.readableDistance(measure, this.map.measureTools.getMeasureUnit()); }, getContextMenuEditItems: function (e) { @@ -1012,18 +1004,9 @@ L.U.Polygon = L.Polygon.extend({ return options.concat(L.U.FeatureMixin.getInteractionOptions()); }, - getMeasure: function (extraPoint) { - var polygon; - if (extraPoint){ - var tmpLatLngs = this.editor._drawnLatLngs.slice(); - tmpLatLngs.push(extraPoint); - polygon = tmpLatLngs; - } else { - polygon = this._defaultShape(); - } - - var area = L.GeoUtil.geodesicArea(polygon); - return L.GeoUtil.readableArea(area, this.map.measureTools.getMeasureUnit()); + getMeasure: function (shape) { + var measure = L.GeoUtil.lineLength(this.map, shape | this._defaultShape()); + return L.GeoUtil.readableArea(measure, this.map.measureTools.getMeasureUnit()); }, getContextMenuEditItems: function (e) {