]> git.openstreetmap.org Git - nominatim-ui.git/blobdiff - dist/assets/js/nominatim-ui.js
Merge pull request #31 from lonvia/bigger-map
[nominatim-ui.git] / dist / assets / js / nominatim-ui.js
index c3ffd1bed2b9c2114763d2f39de2471097839ce1..e36e866610a056b0bf8c07fe52e4371c1422e61a 100644 (file)
@@ -80,7 +80,7 @@ function map_viewbox_as_string() {
 // PAGE HELPERS
 // *********************************************************
 
-function fetch_from_api(endpoint_name, params, callback) {
+function generate_full_api_url(endpoint_name, params) {
   //
   // `&a=&b=&c=1` => '&c=1'
   var param_names = Object.keys(params);
@@ -93,6 +93,11 @@ function fetch_from_api(endpoint_name, params, callback) {
 
   var api_url = get_config_value('Nominatim_API_Endpoint') + endpoint_name + '.php?'
                   + $.param(params);
+  return api_url;
+}
+
+function fetch_from_api(endpoint_name, params, callback) {
+  var api_url = generate_full_api_url(endpoint_name, params);
   if (endpoint_name !== 'status') {
     $('#api-request-link').attr('href', api_url);
   }
@@ -581,6 +586,11 @@ function search_page_load() {
       format: 'jsonv2'
     };
 
+    if (search_params.get('debug') === '1') {
+      window.location.href = generate_full_api_url('reverse', api_request_params);
+      return;
+    }
+
     context = {
       // aPlace: aPlace,
       fLat: api_request_params.lat,
@@ -645,6 +655,11 @@ function search_page_load() {
       format: 'jsonv2'
     };
 
+    if (search_params.get('debug') === '1') {
+      window.location.href = generate_full_api_url('search', api_request_params);
+      return;
+    }
+
     context = {
       sQuery: api_request_params.q,
       sViewBox: search_params.get('viewbox'),
@@ -670,19 +685,20 @@ function search_page_load() {
         context.bSearchRan = true;
         context.aSearchResults = aResults;
 
-        if (aResults.length >= 10) {
-          var aExcludePlaceIds = [];
-          if (search_params.has('exclude_place_ids')) {
-            aExcludePlaceIds = search_params.get('exclude_place_ids').split(',');
-          }
-          for (var i = 0; i < aResults.length; i += 1) {
-            aExcludePlaceIds.push(aResults[i].place_id);
-          }
-
-          var parsed_url = new URLSearchParams(window.location.search);
-          parsed_url.set('exclude_place_ids', aExcludePlaceIds.join(','));
-          context.sMoreURL = '?' + parsed_url.toString();
+        // lonvia wrote: https://github.com/osm-search/nominatim-ui/issues/24
+        // I would suggest to remove the guessing and always show the link. Nominatim only returns
+        // one or two results when it believes the result to be a good enough match.
+        // if (aResults.length >= 10) {
+        var aExcludePlaceIds = [];
+        if (search_params.has('exclude_place_ids')) {
+          aExcludePlaceIds = search_params.get('exclude_place_ids').split(',');
+        }
+        for (var i = 0; i < aResults.length; i += 1) {
+          aExcludePlaceIds.push(aResults[i].place_id);
         }
+        var parsed_url = new URLSearchParams(window.location.search);
+        parsed_url.set('exclude_place_ids', aExcludePlaceIds.join(','));
+        context.sMoreURL = '?' + parsed_url.toString();
 
         render_template($('main'), 'searchpage-template', context);
         update_html_title('Result for ' + api_request_params.q);
@@ -757,7 +773,9 @@ jQuery(document).ready(function () {
 
   function parse_url_and_load_page() {
     // 'search', 'reverse', 'details'
-    var pagename = window.location.pathname.replace('.html', '').replace(/^\//, '');
+    var pagename = window.location.pathname.replace('.html', '').replace(/^.*\//, '');
+
+    if (pagename === '') pagename = 'search';
 
     $('body').attr('id', pagename + '-page');