]> git.openstreetmap.org Git - nominatim-ui.git/blobdiff - dist/handlebar_helpers.js
/reverse.html should be reverse.html to app works in subdirectory
[nominatim-ui.git] / dist / handlebar_helpers.js
index 4d1889f324530b13371c7c3bca0930a8cf363c0e..bbb6e16d2aa2fcccc6d16d75881ab1bab0c4a2b2 100644 (file)
@@ -13,6 +13,13 @@ function formatOSMType(sType, bExcludeExternal) {
   return '';
 }
 
+function formatShortOSMType(sType) {
+  if (sType === 'node') return 'N';
+  if (sType === 'way') return 'W';
+  if (sType === 'relation') return 'R';
+  return '';
+}
+
 function getIcon(aPlace) {
   // equivalent to PHP Nominatim::ClassTypes::getIcon
   // covers 83 of 214 available icon filenames, e.g. transport_roundabout_anticlockwise
@@ -115,10 +122,7 @@ Handlebars.registerHelper({
     return formatOSMType(sType, bExcludeExternal);
   },
   shortOSMType: function (sType) {
-    if (sType === 'node') return 'N';
-    if (sType === 'way') return 'W';
-    if (sType === 'relation') return 'R';
-    return '';
+    return formatShortOSMType(sType);
   },
   // { osm_type: 'R', osm_id: 12345 }
   // <a href="https://www.openstreetmap.org/relation/12345">relation 12345</a
@@ -145,34 +149,23 @@ Handlebars.registerHelper({
       '<a href="https://' + sLanguage + '.wikipedia.org/wiki/' + sArticle + '" target="_blank">' + sTitle + '</a>'
     );
   },
-  // { osm_type: 'R', osm_id: 12345 }
-  // <a href="details.html?place_id=12345">details</a>
-  detailsLink: function (aFeature, sTitle) {
-    if (!aFeature) return '';
-    if (!aFeature.place_id) return '';
-
-    var sTitleEscaped = Handlebars.escapeExpression(sTitle || 'details >');
-
-    return new Handlebars.SafeString(
-      '<a href="details.html?place_id=' + aFeature.place_id + '">' + sTitleEscaped + '</a>'
-    );
-  },
-  detailsPermaLink: function (aFeature, sTitle) {
+  // 'details.html?osmtype=R&osmid=2181874&class=boundary'
+  detailsURL: function (aFeature) {
     if (!aFeature) return '';
 
-    var sOSMType = formatOSMType(aFeature.osm_type, false);
+    var sOSMType = aFeature.osm_type;
+    if (sOSMType && sOSMType.length !== 1) {
+      sOSMType = formatShortOSMType(aFeature.osm_type, false); // node => N
+    }
     if (!sOSMType) return '';
 
-    var sTitleEscaped = Handlebars.escapeExpression(sTitle || sOSMType + ' ' + aFeature.osm_id);
-
-    var sURL = 'details.html?osmtype=' + aFeature.osm_type + '&osmid=' + aFeature.osm_id;
-    if (aFeature.category) {
+    var sURL = 'details.html?osmtype=' + sOSMType + '&osmid=' + aFeature.osm_id;
+    if (aFeature.class) {
+      sURL = sURL + '&class=' + aFeature.class;
+    } else if (aFeature.category) {
       sURL = sURL + '&class=' + aFeature.category;
     }
-
-    return new Handlebars.SafeString(
-      '<a href="' + sURL + '">' + sTitleEscaped + '</a>'
-    );
+    return sURL;
   },
   formatPlaceType: function (aPlace) {
     var sOut = aPlace.class + ':' + aPlace.type;
@@ -184,16 +177,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';
+
+      return new Handlebars.SafeString(
+        '<abbr class="distance" title="' + fDistance + ' meters">~' + sFormatted + '</abbr>'
+      );
+    }
 
-    var formatted = (fDistanceMeters >= 1000)
-      ? Math.round(fDistanceMeters / 1000, 1) + ' km'
-      : Math.round(fDistanceMeters, 0) + ' m';
+    // 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
@@ -231,28 +233,26 @@ Handlebars.registerHelper({
     }
     return '';
   },
-  formatSearchRank: function (iRank) {
-    // same as
-    // https://github.com/osm-search/Nominatim/blob/master/sql/functions.sql
-    // get_searchrank_label()
-
-    if (iRank < 2) return 'continent';
-    if (iRank < 4) return 'sea';
-    if (iRank < 8) return 'country';
-    if (iRank < 12) return 'state';
-    if (iRank < 16) return 'county';
-    if (iRank === 16) return 'city';
-    if (iRank === 17) return 'town / island';
-    if (iRank === 18) return 'village / hamlet';
-    if (iRank === 20) return 'suburb';
-    if (iRank === 21) return 'postcode area';
-    if (iRank === 22) return 'croft / farm / locality / islet';
-    if (iRank === 23) return 'postcode area';
-    if (iRank === 25) return 'postcode point';
-    if (iRank === 26) return 'street / major landmark';
+  formatAddressRank: function (iRank) {
+    if (iRank < 4) return 'other';
+    if (iRank < 6) return 'country';
+    if (iRank < 8) return 'region';
+    if (iRank < 10) return 'state';
+    if (iRank < 12) return 'state district';
+    if (iRank < 14) return 'county';
+    if (iRank < 16) return 'municipality';
+    if (iRank < 18) return 'city / town / village';
+    if (iRank < 20) return 'city / village district';
+    if (iRank < 22) return 'suburb / hamlet';
+    if (iRank < 24) return 'neighbourhood';
+    if (iRank < 26) return 'city block / square';
+    if (iRank === 26) return 'major street';
     if (iRank === 27) return 'minory street / path';
-    if (iRank === 28) return 'house / building';
-    return 'other: ' + iRank;
+    if (iRank <= 30) return 'house / building';
+    return 'other';
+  },
+  isAdminBoundary: function (aPlace) {
+    return aPlace.category === 'boundary' && aPlace.type === 'administrative';
   },
   tooManyHierarchyLinesWarning: function (aPlace) {
     if (!aPlace.hierarchy) return '';