]> git.openstreetmap.org Git - nominatim-ui.git/commitdiff
Merge pull request #22 from mtmail/distance-in-meters-or-spheric
authormtmail <mtmail@gmx.net>
Fri, 31 Jul 2020 12:56:21 +0000 (14:56 +0200)
committerGitHub <noreply@github.com>
Fri, 31 Jul 2020 12:56:21 +0000 (14:56 +0200)
API returns some distance in spheric, not meters

dist/deletable.html
dist/details.html
dist/handlebar_helpers.js
dist/polygons.html
dist/reverse.html
dist/search.html
src/handlebar_helpers.js
src/templates/detailspage.hbs

index 1b809687c0820f8b19f71b40e5e8746da623155a..11a824dd35ed88285e467d387d6ef5a53dd7cd9e 100644 (file)
     <td>{{osmLink this}}</td>
     <td>{{this.rank_address}}</td>
     <td>{{formatAdminLevel this.admin_level}}</td>
-    <td>{{formatDistance this.distance}}</td>
+    <td>{{formatDistance this.distance bDistanceInMeters}}</td>
     <td>{{detailsPermaLink this 'details >'}}</td>
   </tr>
 {{/inline}}
         <tbody>
           {{#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}}
 
             {{#each aPlace.hierarchy as |lines type|}}
               {{> partial_h3 type}}
               {{#each lines}}
-                {{> partial_details_one_row}}
+                {{> partial_details_one_row bDistanceInMeters=true}}
               {{/each}}
             {{/each}}
           {{else}}
index 1b809687c0820f8b19f71b40e5e8746da623155a..11a824dd35ed88285e467d387d6ef5a53dd7cd9e 100644 (file)
     <td>{{osmLink this}}</td>
     <td>{{this.rank_address}}</td>
     <td>{{formatAdminLevel this.admin_level}}</td>
-    <td>{{formatDistance this.distance}}</td>
+    <td>{{formatDistance this.distance bDistanceInMeters}}</td>
     <td>{{detailsPermaLink this 'details >'}}</td>
   </tr>
 {{/inline}}
         <tbody>
           {{#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}}
 
             {{#each aPlace.hierarchy as |lines type|}}
               {{> partial_h3 type}}
               {{#each lines}}
-                {{> partial_details_one_row}}
+                {{> partial_details_one_row bDistanceInMeters=true}}
               {{/each}}
             {{/each}}
           {{else}}
index 4d1889f324530b13371c7c3bca0930a8cf363c0e..3ece852a9d0fa13788ee40e5e41707e11c670cd3 100644 (file)
@@ -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(
+        '<abbr class="distance" title="' + fDistance + ' meters">~' + sFormatted + '</abbr>'
+      );
+    }
+
+    // spheric distance, http://postgis.net/docs/ST_Distance_Spheroid.html
+    if (fDistance === 0) return '0';
 
     return new Handlebars.SafeString(
-      '<abbr class="distance" title="' + fDistanceMeters + '">~' + formatted + '</abbr>'
+      '<abbr class="distance" title="spheric distance ' + fDistance + '">~'
+        + (Math.round(fDistance * 1000, 4) / 1000)
+        + '</abbr>'
     );
   },
   // mark partial tokens (those starting with a space) with a star for readability
index 1b809687c0820f8b19f71b40e5e8746da623155a..11a824dd35ed88285e467d387d6ef5a53dd7cd9e 100644 (file)
     <td>{{osmLink this}}</td>
     <td>{{this.rank_address}}</td>
     <td>{{formatAdminLevel this.admin_level}}</td>
-    <td>{{formatDistance this.distance}}</td>
+    <td>{{formatDistance this.distance bDistanceInMeters}}</td>
     <td>{{detailsPermaLink this 'details >'}}</td>
   </tr>
 {{/inline}}
         <tbody>
           {{#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}}
 
             {{#each aPlace.hierarchy as |lines type|}}
               {{> partial_h3 type}}
               {{#each lines}}
-                {{> partial_details_one_row}}
+                {{> partial_details_one_row bDistanceInMeters=true}}
               {{/each}}
             {{/each}}
           {{else}}
index 1b809687c0820f8b19f71b40e5e8746da623155a..11a824dd35ed88285e467d387d6ef5a53dd7cd9e 100644 (file)
     <td>{{osmLink this}}</td>
     <td>{{this.rank_address}}</td>
     <td>{{formatAdminLevel this.admin_level}}</td>
-    <td>{{formatDistance this.distance}}</td>
+    <td>{{formatDistance this.distance bDistanceInMeters}}</td>
     <td>{{detailsPermaLink this 'details >'}}</td>
   </tr>
 {{/inline}}
         <tbody>
           {{#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}}
 
             {{#each aPlace.hierarchy as |lines type|}}
               {{> partial_h3 type}}
               {{#each lines}}
-                {{> partial_details_one_row}}
+                {{> partial_details_one_row bDistanceInMeters=true}}
               {{/each}}
             {{/each}}
           {{else}}
index 1b809687c0820f8b19f71b40e5e8746da623155a..11a824dd35ed88285e467d387d6ef5a53dd7cd9e 100644 (file)
     <td>{{osmLink this}}</td>
     <td>{{this.rank_address}}</td>
     <td>{{formatAdminLevel this.admin_level}}</td>
-    <td>{{formatDistance this.distance}}</td>
+    <td>{{formatDistance this.distance bDistanceInMeters}}</td>
     <td>{{detailsPermaLink this 'details >'}}</td>
   </tr>
 {{/inline}}
         <tbody>
           {{#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}}
 
             {{#each aPlace.hierarchy as |lines type|}}
               {{> partial_h3 type}}
               {{#each lines}}
-                {{> partial_details_one_row}}
+                {{> partial_details_one_row bDistanceInMeters=true}}
               {{/each}}
             {{/each}}
           {{else}}
index 4d1889f324530b13371c7c3bca0930a8cf363c0e..3ece852a9d0fa13788ee40e5e41707e11c670cd3 100644 (file)
@@ -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(
+        '<abbr class="distance" title="' + fDistance + ' meters">~' + sFormatted + '</abbr>'
+      );
+    }
+
+    // spheric distance, http://postgis.net/docs/ST_Distance_Spheroid.html
+    if (fDistance === 0) return '0';
 
     return new Handlebars.SafeString(
-      '<abbr class="distance" title="' + fDistanceMeters + '">~' + formatted + '</abbr>'
+      '<abbr class="distance" title="spheric distance ' + fDistance + '">~'
+        + (Math.round(fDistance * 1000, 4) / 1000)
+        + '</abbr>'
     );
   },
   // mark partial tokens (those starting with a space) with a star for readability
index 48ecde95c3aabf3d3609bc0748809a4e363e3360..783865a03dc724a806e94dec3c2ad91d5daf1818 100644 (file)
@@ -12,7 +12,7 @@
     <td>{{osmLink this}}</td>
     <td>{{this.rank_address}}</td>
     <td>{{formatAdminLevel this.admin_level}}</td>
-    <td>{{formatDistance this.distance}}</td>
+    <td>{{formatDistance this.distance bDistanceInMeters}}</td>
     <td>{{detailsPermaLink this 'details >'}}</td>
   </tr>
 {{/inline}}
         <tbody>
           {{#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}}
 
             {{#each aPlace.hierarchy as |lines type|}}
               {{> partial_h3 type}}
               {{#each lines}}
-                {{> partial_details_one_row}}
+                {{> partial_details_one_row bDistanceInMeters=true}}
               {{/each}}
             {{/each}}
           {{else}}