Skip to content

Commit

Permalink
refactor: area value presentation
Browse files Browse the repository at this point in the history
the areas shown for isochrones is shown as square meters when below
1 square kilometer even if settings are specified to square kilometers as
area units.
As this results in some rather large area values the method is adjusted
to only resort to showing as square meters when below 10000
  • Loading branch information
TheGreatRefrigerator committed May 8, 2023
1 parent 165b0a4 commit 8e11046
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/support/geo-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,18 @@ const geoUtils = {
* @param {String} unit
*/
readableArea(latlngs, unit) {
let area = Leaflet.GeometryUtil.geodesicArea(latlngs)
return Leaflet.GeometryUtil.readableArea(area, unit)
// see https://github.com/Leaflet/Leaflet.draw/blob/33ea262678bbfc3da7e92c226f70c017bd328434/src/ext/GeometryUtil.js#L66-L99
let precision = precision || 2
let area = this.geodesicArea(latlngs)
let areaStr
if (area >= 10000 && unit === 'km') {
areaStr = Leaflet.GeometryUtil.formattedNumber(area * 0.000001, precision) + ' km²'
} else if (area >= 10000 && unit === 'ha') {
areaStr = Leaflet.GeometryUtil.formattedNumber(area * 0.0001, precision) + ' ha'
} else {
areaStr = Leaflet.GeometryUtil.formattedNumber(area, 0) + ' m²'
}
return areaStr
},

/**
Expand Down

0 comments on commit 8e11046

Please sign in to comment.