]> git.openstreetmap.org Git - nominatim-ui.git/commitdiff
Merge pull request #27 from mtmail/always-display-more-url
authormtmail <mtmail@gmx.net>
Mon, 10 Aug 2020 12:47:34 +0000 (14:47 +0200)
committerGitHub <noreply@github.com>
Mon, 10 Aug 2020 12:47:34 +0000 (14:47 +0200)
Always display more-results button below search results

1  2 
dist/assets/js/nominatim-ui.js
src/assets/js/searchpage.js

index d16de70e48b3d9edf37319a0582b5696f6d759a2,1069b3e33d974962086ca453bb8a62cbc122b5d1..e36e866610a056b0bf8c07fe52e4371c1422e61a
@@@ -80,7 -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);
  
    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);
    }
@@@ -586,11 -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,
        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'),
          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);
@@@ -772,7 -758,7 +773,7 @@@ 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';
  
index 914d864af95a582cf2323bed752e29c9d7f487c1,95d842d5d176f3fd3a29c84e7a25559ca38b39b2..ee76ba83fcd98a3a184984e0bcf329a2eaad251a
@@@ -321,11 -321,6 +321,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,
        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'),
          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);