From 2d04ebbd7dd3f76783f1d1595504921292614beb Mon Sep 17 00:00:00 2001 From: marc tobias Date: Fri, 31 Jul 2020 14:55:39 +0200 Subject: [PATCH] API returns some distance in spheric, not meters --- dist/deletable.html | 8 ++++---- dist/details.html | 8 ++++---- dist/handlebar_helpers.js | 23 ++++++++++++++++------- dist/polygons.html | 8 ++++---- dist/reverse.html | 8 ++++---- dist/search.html | 8 ++++---- src/handlebar_helpers.js | 23 ++++++++++++++++------- src/templates/detailspage.hbs | 8 ++++---- 8 files changed, 56 insertions(+), 38 deletions(-) diff --git a/dist/deletable.html b/dist/deletable.html index 1b80968..11a824d 100644 --- a/dist/deletable.html +++ b/dist/deletable.html @@ -329,7 +329,7 @@ {{osmLink this}} {{this.rank_address}} {{formatAdminLevel this.admin_level}} - {{formatDistance this.distance}} + {{formatDistance this.distance bDistanceInMeters}} {{detailsPermaLink this 'details >'}} {{/inline}} @@ -477,14 +477,14 @@ {{#if aPlace.address}} {{#each aPlace.address}} - {{> partial_details_one_row}} + {{> partial_details_one_row bDistanceInMeters=false}} {{/each}} {{/if}} {{#if aPlace.linked_places}} {{> partial_h2 'Linked Places'}} {{#each aPlace.linked_places}} - {{> partial_details_one_row}} + {{> partial_details_one_row bDistanceInMeters=true}} {{/each}} {{/if}} @@ -506,7 +506,7 @@ {{#each aPlace.hierarchy as |lines type|}} {{> partial_h3 type}} {{#each lines}} - {{> partial_details_one_row}} + {{> partial_details_one_row bDistanceInMeters=true}} {{/each}} {{/each}} {{else}} diff --git a/dist/details.html b/dist/details.html index 1b80968..11a824d 100644 --- a/dist/details.html +++ b/dist/details.html @@ -329,7 +329,7 @@ {{osmLink this}} {{this.rank_address}} {{formatAdminLevel this.admin_level}} - {{formatDistance this.distance}} + {{formatDistance this.distance bDistanceInMeters}} {{detailsPermaLink this 'details >'}} {{/inline}} @@ -477,14 +477,14 @@ {{#if aPlace.address}} {{#each aPlace.address}} - {{> partial_details_one_row}} + {{> partial_details_one_row bDistanceInMeters=false}} {{/each}} {{/if}} {{#if aPlace.linked_places}} {{> partial_h2 'Linked Places'}} {{#each aPlace.linked_places}} - {{> partial_details_one_row}} + {{> partial_details_one_row bDistanceInMeters=true}} {{/each}} {{/if}} @@ -506,7 +506,7 @@ {{#each aPlace.hierarchy as |lines type|}} {{> partial_h3 type}} {{#each lines}} - {{> partial_details_one_row}} + {{> partial_details_one_row bDistanceInMeters=true}} {{/each}} {{/each}} {{else}} diff --git a/dist/handlebar_helpers.js b/dist/handlebar_helpers.js index 4d1889f..3ece852 100644 --- a/dist/handlebar_helpers.js +++ b/dist/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 diff --git a/dist/polygons.html b/dist/polygons.html index 1b80968..11a824d 100644 --- a/dist/polygons.html +++ b/dist/polygons.html @@ -329,7 +329,7 @@ {{osmLink this}} {{this.rank_address}} {{formatAdminLevel this.admin_level}} - {{formatDistance this.distance}} + {{formatDistance this.distance bDistanceInMeters}} {{detailsPermaLink this 'details >'}} {{/inline}} @@ -477,14 +477,14 @@ {{#if aPlace.address}} {{#each aPlace.address}} - {{> partial_details_one_row}} + {{> partial_details_one_row bDistanceInMeters=false}} {{/each}} {{/if}} {{#if aPlace.linked_places}} {{> partial_h2 'Linked Places'}} {{#each aPlace.linked_places}} - {{> partial_details_one_row}} + {{> partial_details_one_row bDistanceInMeters=true}} {{/each}} {{/if}} @@ -506,7 +506,7 @@ {{#each aPlace.hierarchy as |lines type|}} {{> partial_h3 type}} {{#each lines}} - {{> partial_details_one_row}} + {{> partial_details_one_row bDistanceInMeters=true}} {{/each}} {{/each}} {{else}} diff --git a/dist/reverse.html b/dist/reverse.html index 1b80968..11a824d 100644 --- a/dist/reverse.html +++ b/dist/reverse.html @@ -329,7 +329,7 @@ {{osmLink this}} {{this.rank_address}} {{formatAdminLevel this.admin_level}} - {{formatDistance this.distance}} + {{formatDistance this.distance bDistanceInMeters}} {{detailsPermaLink this 'details >'}} {{/inline}} @@ -477,14 +477,14 @@ {{#if aPlace.address}} {{#each aPlace.address}} - {{> partial_details_one_row}} + {{> partial_details_one_row bDistanceInMeters=false}} {{/each}} {{/if}} {{#if aPlace.linked_places}} {{> partial_h2 'Linked Places'}} {{#each aPlace.linked_places}} - {{> partial_details_one_row}} + {{> partial_details_one_row bDistanceInMeters=true}} {{/each}} {{/if}} @@ -506,7 +506,7 @@ {{#each aPlace.hierarchy as |lines type|}} {{> partial_h3 type}} {{#each lines}} - {{> partial_details_one_row}} + {{> partial_details_one_row bDistanceInMeters=true}} {{/each}} {{/each}} {{else}} diff --git a/dist/search.html b/dist/search.html index 1b80968..11a824d 100644 --- a/dist/search.html +++ b/dist/search.html @@ -329,7 +329,7 @@ {{osmLink this}} {{this.rank_address}} {{formatAdminLevel this.admin_level}} - {{formatDistance this.distance}} + {{formatDistance this.distance bDistanceInMeters}} {{detailsPermaLink this 'details >'}} {{/inline}} @@ -477,14 +477,14 @@ {{#if aPlace.address}} {{#each aPlace.address}} - {{> partial_details_one_row}} + {{> partial_details_one_row bDistanceInMeters=false}} {{/each}} {{/if}} {{#if aPlace.linked_places}} {{> partial_h2 'Linked Places'}} {{#each aPlace.linked_places}} - {{> partial_details_one_row}} + {{> partial_details_one_row bDistanceInMeters=true}} {{/each}} {{/if}} @@ -506,7 +506,7 @@ {{#each aPlace.hierarchy as |lines type|}} {{> partial_h3 type}} {{#each lines}} - {{> partial_details_one_row}} + {{> partial_details_one_row bDistanceInMeters=true}} {{/each}} {{/each}} {{else}} 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 diff --git a/src/templates/detailspage.hbs b/src/templates/detailspage.hbs index 48ecde9..783865a 100644 --- a/src/templates/detailspage.hbs +++ b/src/templates/detailspage.hbs @@ -12,7 +12,7 @@ {{osmLink this}} {{this.rank_address}} {{formatAdminLevel this.admin_level}} - {{formatDistance this.distance}} + {{formatDistance this.distance bDistanceInMeters}} {{detailsPermaLink this 'details >'}} {{/inline}} @@ -160,14 +160,14 @@ {{#if aPlace.address}} {{#each aPlace.address}} - {{> partial_details_one_row}} + {{> partial_details_one_row bDistanceInMeters=false}} {{/each}} {{/if}} {{#if aPlace.linked_places}} {{> partial_h2 'Linked Places'}} {{#each aPlace.linked_places}} - {{> partial_details_one_row}} + {{> partial_details_one_row bDistanceInMeters=true}} {{/each}} {{/if}} @@ -189,7 +189,7 @@ {{#each aPlace.hierarchy as |lines type|}} {{> partial_h3 type}} {{#each lines}} - {{> partial_details_one_row}} + {{> partial_details_one_row bDistanceInMeters=true}} {{/each}} {{/each}} {{else}} -- 2.39.5