X-Git-Url: https://git.openstreetmap.org./nominatim-ui.git/blobdiff_plain/19f626c2a6f4bb6b1b86c640b49a37c6faa1eb3e..621fbc3ae3d560335fde771907bb0fe80a134734:/src/handlebar_helpers.js diff --git a/src/handlebar_helpers.js b/src/handlebar_helpers.js index 4d1889f..3ece852 100644 --- a/src/handlebar_helpers.js +++ b/src/handlebar_helpers.js @@ -184,16 +184,25 @@ Handlebars.registerHelper({ coverageType: function (aPlace) { return (aPlace.isarea ? 'Polygon' : 'Point'); }, - // fDistance is in meters - formatDistance: function (fDistanceMeters) { - if (fDistanceMeters < 1) return '0'; + formatDistance: function (fDistance, bInMeters) { + if (bInMeters) { + if (fDistance < 1) return '0'; + var sFormatted = (fDistance >= 1000) + ? Math.round(fDistance / 1000, 1) + ' km' + : Math.round(fDistance, 0) + ' m'; - var formatted = (fDistanceMeters >= 1000) - ? Math.round(fDistanceMeters / 1000, 1) + ' km' - : Math.round(fDistanceMeters, 0) + ' m'; + return new Handlebars.SafeString( + '~' + sFormatted + '' + ); + } + + // spheric distance, http://postgis.net/docs/ST_Distance_Spheroid.html + if (fDistance === 0) return '0'; return new Handlebars.SafeString( - '~' + formatted + '' + '~' + + (Math.round(fDistance * 1000, 4) / 1000) + + '' ); }, // mark partial tokens (those starting with a space) with a star for readability