]> git.openstreetmap.org Git - nominatim-ui.git/commitdiff
javascript: indent 2 space, not 4 space
authormarc tobias <mtmail@gmx.net>
Sat, 30 Nov 2019 14:56:58 +0000 (15:56 +0100)
committermarc tobias <mtmail@gmx.net>
Sat, 30 Nov 2019 14:56:58 +0000 (15:56 +0100)
src/assets/js/base.js
src/assets/js/detailpage.js
src/assets/js/searchpage.js
src/config.js
src/handlebar_helpers.js

index 5754e3dcd916340a9b871c838d7e61eb52b58d1f..8c7696d99e3f4496317176cf66eb0e0a454b1a6f 100644 (file)
@@ -7,47 +7,47 @@ var last_click_latlng;
 *********************************************************/
 
 function get_config_value(str, default_val) {
-    return (typeof Nominatim_Config[str] !== 'undefined' ? Nominatim_Config[str] :  default_val);
+  return (typeof Nominatim_Config[str] !== 'undefined' ? Nominatim_Config[str] :  default_val);
 }
 
 function parse_and_normalize_geojson_string(part){
-    // normalize places the geometry into a featurecollection, similar to
-    // https://github.com/mapbox/geojson-normalize
-    var parsed_geojson = {
-        type: "FeatureCollection",
-        features: [
-            {
-                type: "Feature",
-                geometry: part,
-                properties: {}
-            }
-        ]
-    };
-    return parsed_geojson;
+  // normalize places the geometry into a featurecollection, similar to
+  // https://github.com/mapbox/geojson-normalize
+  var parsed_geojson = {
+    type: "FeatureCollection",
+    features: [
+      {
+        type: "Feature",
+        geometry: part,
+        properties: {}
+      }
+    ]
+  };
+  return parsed_geojson;
 }
 
 function map_link_to_osm(){
-    return "https://openstreetmap.org/#map=" + map.getZoom() + "/" + map.getCenter().lat + "/" + map.getCenter().lng;
+  return "https://openstreetmap.org/#map=" + map.getZoom() + "/" + map.getCenter().lat + "/" + map.getCenter().lng;
 }
 
 function map_viewbox_as_string() {
-    var bounds = map.getBounds();
-    var west = bounds.getWest();
-    var east = bounds.getEast();
-
-    if ((east - west) >= 360) { // covers more than whole planet
-        west = map.getCenter().lng-179.999;
-        east = map.getCenter().lng+179.999;
-    }
-    east = L.latLng(77, east).wrap().lng;
-    west = L.latLng(77, west).wrap().lng;
-
-    return [
-        west.toFixed(5), // left
-        bounds.getNorth().toFixed(5), // top
-        east.toFixed(5), // right
-        bounds.getSouth().toFixed(5) // bottom
-    ].join(',');
+  var bounds = map.getBounds();
+  var west = bounds.getWest();
+  var east = bounds.getEast();
+
+  if ((east - west) >= 360) { // covers more than whole planet
+    west = map.getCenter().lng-179.999;
+    east = map.getCenter().lng+179.999;
+  }
+  east = L.latLng(77, east).wrap().lng;
+  west = L.latLng(77, west).wrap().lng;
+
+  return [
+    west.toFixed(5), // left
+    bounds.getNorth().toFixed(5), // top
+    east.toFixed(5), // right
+    bounds.getSouth().toFixed(5) // bottom
+  ].join(',');
 }
 
 
@@ -57,50 +57,50 @@ function map_viewbox_as_string() {
 
 function fetch_from_api(endpoint_name, params, callback) {
 
-    // `&a=&b=&c=1` => '&c='
-    for(var k in params) {
-        if (typeof(params[k]) === 'undefined' || params[k] === '' || params[k] === null ) delete params[k];
-    }
-
-    var api_url = get_config_value('Nominatim_API_Endpoint') + endpoint_name + '.php?' + $.param(params);
-    if (endpoint_name !== 'status') {
-        $('#api-request-link').attr('href', api_url);
-    }
-    $.get(api_url, function(data){
-        callback(data);
-    });
+  // `&a=&b=&c=1` => '&c='
+  for(var k in params) {
+    if (typeof(params[k]) === 'undefined' || params[k] === '' || params[k] === null ) delete params[k];
+  }
+
+  var api_url = get_config_value('Nominatim_API_Endpoint') + endpoint_name + '.php?' + $.param(params);
+  if (endpoint_name !== 'status') {
+    $('#api-request-link').attr('href', api_url);
+  }
+  $.get(api_url, function(data){
+    callback(data);
+  });
 }
 
 function update_data_date() {
-    fetch_from_api('status', {format: 'json'}, function(data){
-        $('#data-date').text(data.data_updated);
-    });
+  fetch_from_api('status', {format: 'json'}, function(data){
+    $('#data-date').text(data.data_updated);
+  });
 }
 
 function render_template(el, template_name, page_context) {
-    var template_source = $('#' + template_name).text();
-    var template = Handlebars.compile(template_source);
-    var html    = template(page_context);
-    el.html(html);
+  var template_source = $('#' + template_name).text();
+  var template = Handlebars.compile(template_source);
+  var html    = template(page_context);
+  el.html(html);
 }
 
 function show_error(html) {
-    $('#error-overlay').html(html).show();   
+  $('#error-overlay').html(html).show();   
 }
 
 function hide_error() {
-    $('#error-overlay').empty().hide();    
+  $('#error-overlay').empty().hide();    
 }
 
 
 $(document).ajaxError(function(event, jqXHR, ajaxSettings, thrownError) {
-    // console.log(thrownError);
-    // console.log(ajaxSettings);
-    show_error('Error fetching results from <a href="' + ajaxSettings.url + '">' + ajaxSettings.url + '</a>');
+  // console.log(thrownError);
+  // console.log(ajaxSettings);
+  show_error('Error fetching results from <a href="' + ajaxSettings.url + '">' + ajaxSettings.url + '</a>');
 });
 
 
 jQuery(document).ready(function(){
-    hide_error();
+  hide_error();
 });
 
index 65b2dc06591ad8130bb57fafae53e5f551d3ed9b..d1803459bd0f3c32aaedf4f98fde06f47ce8e130 100644 (file)
@@ -5,99 +5,99 @@
 
 
 function init_map_on_detail_page(lat, lon, geojson) {
-    map = new L.map('map', {
-        // center: [nominatim_map_init.lat, nominatim_map_init.lon],
-        // zoom:   nominatim_map_init.zoom,
-        attributionControl: (get_config_value('Map_Tile_Attribution') && get_config_value('Map_Tile_Attribution').length),
-        scrollWheelZoom:    true, // !L.Browser.touch,
-        touchZoom:          false,
-    });
-
-    L.tileLayer(get_config_value('Map_Tile_URL'), {
-        // moved to footer
-        attribution: (get_config_value('Map_Tile_Attribution') || null ) //'&copy; <a href="https://osm.org/copyright">OpenStreetMap</a> contributors'
-    }).addTo(map);
-
-    var layerGroup = new L.layerGroup().addTo(map);
-
-    var circle = L.circleMarker([lat,lon], { radius: 10, weight: 2, fillColor: '#ff7800', color: 'blue', opacity: 0.75});
-    map.addLayer(circle);
-
-    if (geojson) {
-        var geojson_layer = L.geoJson(
-            // https://leafletjs.com/reference-1.0.3.html#path-option
-            parse_and_normalize_geojson_string(geojson),
-            {
-                style: function(feature) {
-                    return { interactive: false, color: 'blue' }; 
-                }
-            }
-        );
-        map.addLayer(geojson_layer);
-        map.fitBounds(geojson_layer.getBounds());
-    } else {
-        map.setView([lat,lon],10);
-    }
-
-    var osm2 = new L.TileLayer(get_config_value('Map_Tile_URL'), {minZoom: 0, maxZoom: 13, attribution: (get_config_value('Map_Tile_Attribution') || null )});
-    var miniMap = new L.Control.MiniMap(osm2, {toggleDisplay: true}).addTo(map);
+  map = new L.map('map', {
+    // center: [nominatim_map_init.lat, nominatim_map_init.lon],
+    // zoom:   nominatim_map_init.zoom,
+    attributionControl: (get_config_value('Map_Tile_Attribution') && get_config_value('Map_Tile_Attribution').length),
+    scrollWheelZoom:    true, // !L.Browser.touch,
+    touchZoom:          false,
+  });
+
+  L.tileLayer(get_config_value('Map_Tile_URL'), {
+    // moved to footer
+    attribution: (get_config_value('Map_Tile_Attribution') || null ) //'&copy; <a href="https://osm.org/copyright">OpenStreetMap</a> contributors'
+  }).addTo(map);
+
+  var layerGroup = new L.layerGroup().addTo(map);
+
+  var circle = L.circleMarker([lat,lon], { radius: 10, weight: 2, fillColor: '#ff7800', color: 'blue', opacity: 0.75});
+  map.addLayer(circle);
+
+  if (geojson) {
+    var geojson_layer = L.geoJson(
+      // https://leafletjs.com/reference-1.0.3.html#path-option
+      parse_and_normalize_geojson_string(geojson),
+      {
+        style: function(feature) {
+          return { interactive: false, color: 'blue' }; 
+        }
+      }
+    );
+    map.addLayer(geojson_layer);
+    map.fitBounds(geojson_layer.getBounds());
+  } else {
+    map.setView([lat,lon],10);
+  }
+
+  var osm2 = new L.TileLayer(get_config_value('Map_Tile_URL'), {minZoom: 0, maxZoom: 13, attribution: (get_config_value('Map_Tile_Attribution') || null )});
+  var miniMap = new L.Control.MiniMap(osm2, {toggleDisplay: true}).addTo(map);
 }
 
 
 
 jQuery(document).ready(function(){
 
-    if ( !$('#details-page').length ){ return; }
+  if ( !$('#details-page').length ){ return; }
 
-    var search_params = new URLSearchParams(location.search);
-    // var place_id = search_params.get('place_id');
+  var search_params = new URLSearchParams(location.search);
+  // var place_id = search_params.get('place_id');
 
-    var api_request_params = {
-        place_id: search_params.get('place_id'),
-        osmtype: search_params.get('osmtype'),
-        osmid: search_params.get('osmid'),
-        keywords: search_params.get('keywords'),
-        addressdetails: 1,
-        hierarchy: 1,
-        group_hierarchy: 1,
-        polygon_geojson: 1,
-        format: 'json'
-    };
+  var api_request_params = {
+    place_id: search_params.get('place_id'),
+    osmtype: search_params.get('osmtype'),
+    osmid: search_params.get('osmid'),
+    keywords: search_params.get('keywords'),
+    addressdetails: 1,
+    hierarchy: 1,
+    group_hierarchy: 1,
+    polygon_geojson: 1,
+    format: 'json'
+  };
 
-    if (api_request_params.place_id || (api_request_params.osmtype && api_request_params.osmid )){
-        fetch_from_api('details', api_request_params, function(aFeature){
+  if (api_request_params.place_id || (api_request_params.osmtype && api_request_params.osmid )){
+    fetch_from_api('details', api_request_params, function(aFeature){
 
-            var context = { aPlace: aFeature };
+      var context = { aPlace: aFeature };
 
-            render_template($('main'), 'detailspage-template', context);
+      render_template($('main'), 'detailspage-template', context);
 
-            update_data_date();
+      update_data_date();
 
-            var lat = aFeature.centroid.coordinates[1];
-            var lon = aFeature.centroid.coordinates[0];
-            init_map_on_detail_page(lat, lon, aFeature.geometry);
-        });
-    } else {
-        render_template($('main'), 'detailspage-index-template');
-    }
+      var lat = aFeature.centroid.coordinates[1];
+      var lon = aFeature.centroid.coordinates[0];
+      init_map_on_detail_page(lat, lon, aFeature.geometry);
+    });
+  } else {
+    render_template($('main'), 'detailspage-index-template');
+  }
 
-    $('#form-by-type-and-id,#form-by-osm-url').on('submit', function(e){
-        e.preventDefault();
+  $('#form-by-type-and-id,#form-by-osm-url').on('submit', function(e){
+    e.preventDefault();
 
-        var val = $(this).find('input[type=edit]').val();
-        var matches = val.match(/^\s*([NWR])(\d+)\s*$/i);
+    var val = $(this).find('input[type=edit]').val();
+    var matches = val.match(/^\s*([NWR])(\d+)\s*$/i);
 
-        if (!matches) {
-            matches = val.match(/\/(relation|way|node)\/(\d+)\s*$/);
-        }
+    if (!matches) {
+      matches = val.match(/\/(relation|way|node)\/(\d+)\s*$/);
+    }
 
-        if (matches) {
-            $(this).find('input[name=osmtype]').val(matches[1].charAt(0).toUpperCase());
-            $(this).find('input[name=osmid]').val(matches[2]);
-            $(this).get(0).submit();
-        } else {
-            alert('invalid input');
-        }
-    });
+    if (matches) {
+      $(this).find('input[name=osmtype]').val(matches[1].charAt(0).toUpperCase());
+      $(this).find('input[name=osmid]').val(matches[2]);
+      $(this).get(0).submit();
+    } else {
+      alert('invalid input');
+    }
+  });
 
 });
\ No newline at end of file
index a0a8a1732fd5207b64a8ec0b84239cfd8cd06ff6..0b2ad41d36f305ccd1f094ce8816ceb9f5c8f1c1 100755 (executable)
@@ -6,34 +6,34 @@
 
 function display_map_position(mouse_lat_lng){
 
-    if (mouse_lat_lng) {
-        mouse_lat_lng = map.wrapLatLng(mouse_lat_lng);
-    }
+  if (mouse_lat_lng) {
+    mouse_lat_lng = map.wrapLatLng(mouse_lat_lng);
+  }
 
-    html_mouse = "mouse position " + (mouse_lat_lng ? [mouse_lat_lng.lat.toFixed(5), mouse_lat_lng.lng.toFixed(5)].join(',') : '-');
-    html_click = "last click: " + (last_click_latlng ? [last_click_latlng.lat.toFixed(5),last_click_latlng.lng.toFixed(5)].join(',') : '-');
+  html_mouse = "mouse position " + (mouse_lat_lng ? [mouse_lat_lng.lat.toFixed(5), mouse_lat_lng.lng.toFixed(5)].join(',') : '-');
+  html_click = "last click: " + (last_click_latlng ? [last_click_latlng.lat.toFixed(5),last_click_latlng.lng.toFixed(5)].join(',') : '-');
 
-    html_center = 
-        "map center: " + 
-        map.getCenter().lat.toFixed(5) + ',' + map.getCenter().lng.toFixed(5) +
-        " <a target='_blank' href='" + map_link_to_osm() + "'>view on osm.org</a>";
+  html_center = 
+    "map center: " + 
+    map.getCenter().lat.toFixed(5) + ',' + map.getCenter().lng.toFixed(5) +
+    " <a target='_blank' href='" + map_link_to_osm() + "'>view on osm.org</a>";
 
-    html_zoom = "map zoom: " + map.getZoom();
+  html_zoom = "map zoom: " + map.getZoom();
 
-    html_viewbox = "viewbox: " + map_viewbox_as_string();
+  html_viewbox = "viewbox: " + map_viewbox_as_string();
 
-    $('#map-position-inner').html([html_center,html_zoom,html_viewbox,html_click,html_mouse].join('<br/>'));
+  $('#map-position-inner').html([html_center,html_zoom,html_viewbox,html_click,html_mouse].join('<br/>'));
 
-    var center_lat_lng = map.wrapLatLng(map.getCenter());
-    var reverse_params = {
-        lat: center_lat_lng.lat.toFixed(5),
-        lon: center_lat_lng.lng.toFixed(5)
-        // zoom: 2,
-        // format: 'html'
-    }
-    $('#switch-to-reverse').attr('href', 'reverse.html?' + $.param(reverse_params));
+  var center_lat_lng = map.wrapLatLng(map.getCenter());
+  var reverse_params = {
+    lat: center_lat_lng.lat.toFixed(5),
+    lon: center_lat_lng.lng.toFixed(5)
+    // zoom: 2,
+    // format: 'html'
+  }
+  $('#switch-to-reverse').attr('href', 'reverse.html?' + $.param(reverse_params));
 
-    $('input#use_viewbox').trigger('change');
+  $('input#use_viewbox').trigger('change');
 }
 
 
@@ -41,199 +41,199 @@ function display_map_position(mouse_lat_lng){
 
 function init_map_on_search_page(is_reverse_search, nominatim_results, request_lat, request_lon, init_zoom) {
 
-    map = new L.map('map', {
-        // center: [nominatim_map_init.lat, nominatim_map_init.lon],
-        // zoom:   nominatim_map_init.zoom,
-        attributionControl: (get_config_value('Map_Tile_Attribution') && get_config_value('Map_Tile_Attribution').length),
-        scrollWheelZoom:    true, // !L.Browser.touch,
-        touchZoom:          false,
-    });
+  map = new L.map('map', {
+    // center: [nominatim_map_init.lat, nominatim_map_init.lon],
+    // zoom:   nominatim_map_init.zoom,
+    attributionControl: (get_config_value('Map_Tile_Attribution') && get_config_value('Map_Tile_Attribution').length),
+    scrollWheelZoom:    true, // !L.Browser.touch,
+    touchZoom:          false,
+  });
+
+
+  L.tileLayer(get_config_value('Map_Tile_URL'), {
+    // moved to footer
+    attribution: (get_config_value('Map_Tile_Attribution') || null ) //'&copy; <a href="https://osm.org/copyright">OpenStreetMap</a> contributors'
+  }).addTo(map);
+
+  // console.log(Nominatim_Config);
+
+  map.setView([request_lat, request_lon], init_zoom);
+
+  var osm2 = new L.TileLayer(get_config_value('Map_Tile_URL'), {minZoom: 0, maxZoom: 13, attribution: (get_config_value('Map_Tile_Attribution') || null )});
+  var miniMap = new L.Control.MiniMap(osm2, {toggleDisplay: true}).addTo(map);
+
+  if (is_reverse_search) {
+    // We don't need a marker, but an L.circle instance changes radius once you zoom in/out
+    var cm = L.circleMarker([request_lat, request_lon], { radius: 5, weight: 2, fillColor: '#ff7800', color: 'red', opacity: 0.75, clickable: false});
+    cm.addTo(map);
+  }
+
+  var MapPositionControl = L.Control.extend({
+    options: {
+      position: 'topright'
+    },
+    onAdd: function (map) {
+      var container = L.DomUtil.create('div', 'my-custom-control');
+
+      $(container).text('show map bounds').addClass('leaflet-bar btn btn-sm btn-default').on('click', function(e){
+        e.preventDefault();
+        e.stopPropagation();
+        $('#map-position').show();
+        $(container).hide();
+      });
+      $('#map-position-close a').on('click', function(e){
+        e.preventDefault();
+        e.stopPropagation();
+        $('#map-position').hide();
+        $(container).show();
+      });
+
+      return container;
+    }
+  });
 
+  map.addControl(new MapPositionControl());
 
-    L.tileLayer(get_config_value('Map_Tile_URL'), {
-        // moved to footer
-        attribution: (get_config_value('Map_Tile_Attribution') || null ) //'&copy; <a href="https://osm.org/copyright">OpenStreetMap</a> contributors'
-    }).addTo(map);
 
-    // console.log(Nominatim_Config);
 
-    map.setView([request_lat, request_lon], init_zoom);
 
-    var osm2 = new L.TileLayer(get_config_value('Map_Tile_URL'), {minZoom: 0, maxZoom: 13, attribution: (get_config_value('Map_Tile_Attribution') || null )});
-    var miniMap = new L.Control.MiniMap(osm2, {toggleDisplay: true}).addTo(map);
 
-    if (is_reverse_search) {
-        // We don't need a marker, but an L.circle instance changes radius once you zoom in/out
-        var cm = L.circleMarker([request_lat, request_lon], { radius: 5, weight: 2, fillColor: '#ff7800', color: 'red', opacity: 0.75, clickable: false});
-        cm.addTo(map);
-    }
+  function update_viewbox_field(){
+    // hidden HTML field
+    $('input[name=viewbox]').val( $('input#use_viewbox').prop('checked') ? map_viewbox_as_string() : '');
+  }
 
-    var MapPositionControl = L.Control.extend({
-        options: {
-            position: 'topright'
-        },
-        onAdd: function (map) {
-            var container = L.DomUtil.create('div', 'my-custom-control');
-
-            $(container).text('show map bounds').addClass('leaflet-bar btn btn-sm btn-default').on('click', function(e){
-                e.preventDefault();
-                e.stopPropagation();
-                $('#map-position').show();
-                $(container).hide();
-            });
-            $('#map-position-close a').on('click', function(e){
-                e.preventDefault();
-                e.stopPropagation();
-                $('#map-position').hide();
-                $(container).show();
-            });
-
-            return container;
-        }
-    });
+  map.on('move', function(e) {
+    display_map_position();
+    update_viewbox_field();
+  });
 
-    map.addControl(new MapPositionControl());
+  map.on('mousemove', function(e) {
+    display_map_position(e.latlng);
+  });
 
+  map.on('click', function(e) {
+    last_click_latlng = e.latlng;
+    display_map_position();
+  });
 
+  map.on('load', function(e){
+    display_map_position();
+  });
 
 
+  $('input#use_viewbox').on('change', function(){
+    update_viewbox_field();
+  });
 
-    function update_viewbox_field(){
-        // hidden HTML field
-        $('input[name=viewbox]').val( $('input#use_viewbox').prop('checked') ? map_viewbox_as_string() : '');
-    }
 
-    map.on('move', function(e) {
-        display_map_position();
-        update_viewbox_field();
-    });
 
-    map.on('mousemove', function(e) {
-        display_map_position(e.latlng);
-    });
 
-    map.on('click', function(e) {
-        last_click_latlng = e.latlng;
-        display_map_position();
-    });
-
-    map.on('load', function(e){
-        display_map_position();
-    });
-
-
-    $('input#use_viewbox').on('change', function(){
-        update_viewbox_field();
-    });
+  function get_result_element(position){
+    return $('.result').eq(position);
+  }
+  function marker_for_result(result){
+    return L.marker([result.lat,result.lon], {riseOnHover:true,title:result.name });
+  }
+  function circle_for_result(result){
+    return L.circleMarker([result.lat,result.lon], { radius: 10, weight: 2, fillColor: '#ff7800', color: 'blue', opacity: 0.75, clickable: !is_reverse_search});
+  }
 
+  var layerGroup = new L.layerGroup().addTo(map);
+  function highlight_result(position, bool_focus){
+    var result = nominatim_results[position];
+    if (!result){ return }
+    var result_el = get_result_element(position);
 
+    $('.result').removeClass('highlight');
+    result_el.addClass('highlight');
 
+    layerGroup.clearLayers();
 
-    function get_result_element(position){
-        return $('.result').eq(position);
+    if (result.lat){
+      var circle = circle_for_result(result);
+      circle.on('click', function(){
+        highlight_result(position);
+      });
+      layerGroup.addLayer(circle);            
     }
-    function marker_for_result(result){
-        return L.marker([result.lat,result.lon], {riseOnHover:true,title:result.name });
-    }
-    function circle_for_result(result){
-        return L.circleMarker([result.lat,result.lon], { radius: 10, weight: 2, fillColor: '#ff7800', color: 'blue', opacity: 0.75, clickable: !is_reverse_search});
-    }
-
-    var layerGroup = new L.layerGroup().addTo(map);
-    function highlight_result(position, bool_focus){
-        var result = nominatim_results[position];
-        if (!result){ return }
-        var result_el = get_result_element(position);
+    if (result.boundingbox){
 
-        $('.result').removeClass('highlight');
-        result_el.addClass('highlight');
+      var bounds = [[result.boundingbox[0]*1,result.boundingbox[2]*1], [result.boundingbox[1]*1,result.boundingbox[3]*1]];
+      map.fitBounds(bounds);
 
-        layerGroup.clearLayers();
+      if (result.geojson && result.geojson.type.match(/(Polygon)|(Line)/) ){
 
-        if (result.lat){
-            var circle = circle_for_result(result);
-            circle.on('click', function(){
-                highlight_result(position);
-            });
-            layerGroup.addLayer(circle);            
-        }
-        if (result.boundingbox){
-
-            var bounds = [[result.boundingbox[0]*1,result.boundingbox[2]*1], [result.boundingbox[1]*1,result.boundingbox[3]*1]];
-            map.fitBounds(bounds);
-
-            if (result.geojson && result.geojson.type.match(/(Polygon)|(Line)/) ){
-
-                var geojson_layer = L.geoJson(
-                    parse_and_normalize_geojson_string(result.geojson),
-                    {
-                        // https://leafletjs.com/reference-1.0.3.html#path-option
-                        style: function(feature) {
-                            return { interactive: false, color: 'blue' }; 
-                        }
-                    }
-                );
-                layerGroup.addLayer(geojson_layer);
+        var geojson_layer = L.geoJson(
+          parse_and_normalize_geojson_string(result.geojson),
+          {
+            // https://leafletjs.com/reference-1.0.3.html#path-option
+            style: function(feature) {
+              return { interactive: false, color: 'blue' }; 
             }
-            // else {
-            //     var layer = L.rectangle(bounds, {color: "#ff7800", weight: 1} );
-            //     layerGroup.addLayer(layer);
-            // }
+          }
+        );
+        layerGroup.addLayer(geojson_layer);
+      }
+      // else {
+      //     var layer = L.rectangle(bounds, {color: "#ff7800", weight: 1} );
+      //     layerGroup.addLayer(layer);
+      // }
+    }
+    else {
+      var result_coord = L.latLng(result.lat, result.lon);
+      if ( result_coord ){
+        if ( is_reverse_search ){
+          // console.dir([result_coord, [request_lat, request_lon]]);
+          // make sure the search coordinates are in the map view as well
+          map.fitBounds([result_coord, [request_lat, request_lon]], {padding: [50,50], maxZoom: map.getZoom()});
+
+          // better, but causes a leaflet warning
+          // map.panInsideBounds([[result.lat,result.lon], [nominatim_map_init.lat,nominatim_map_init.lon]], {animate: false});
         }
         else {
-            var result_coord = L.latLng(result.lat, result.lon);
-            if ( result_coord ){
-                if ( is_reverse_search ){
-                    // console.dir([result_coord, [request_lat, request_lon]]);
-                    // make sure the search coordinates are in the map view as well
-                    map.fitBounds([result_coord, [request_lat, request_lon]], {padding: [50,50], maxZoom: map.getZoom()});
-
-                    // better, but causes a leaflet warning
-                    // map.panInsideBounds([[result.lat,result.lon], [nominatim_map_init.lat,nominatim_map_init.lon]], {animate: false});
-                }
-                else {
-                    map.panTo(result_coord, result.zoom || get_config_value('Map_Default_Zoom'));
-                }
-            }
-        }
-        if (bool_focus){
-            $('#map').focus();
+          map.panTo(result_coord, result.zoom || get_config_value('Map_Default_Zoom'));
         }
+      }
+    }
+    if (bool_focus){
+      $('#map').focus();
     }
+  }
 
 
-    $('.result').on('click', function(e){
-        highlight_result($(this).data('position'), true);
+  $('.result').on('click', function(e){
+    highlight_result($(this).data('position'), true);
+  });
+
+  if ( is_reverse_search ){
+    map.on('click', function(e){
+      $('form input[name=lat]').val( e.latlng.lat);
+      $('form input[name=lon]').val( e.latlng.wrap().lng);
+      $('form').submit();
     });
 
-    if ( is_reverse_search ){
-        map.on('click', function(e){
-            $('form input[name=lat]').val( e.latlng.lat);
-            $('form input[name=lon]').val( e.latlng.wrap().lng);
-            $('form').submit();
-        });
-
-        $('#switch-coords').on('click', function(e){
-            e.preventDefault();
-            e.stopPropagation();
-            var lat = $('form input[name=lat]').val();
-            var lon = $('form input[name=lon]').val();
-            $('form input[name=lat]').val(lon);
-            $('form input[name=lon]').val(lat);
-            $('form').submit();
-        });
-    }
+    $('#switch-coords').on('click', function(e){
+      e.preventDefault();
+      e.stopPropagation();
+      var lat = $('form input[name=lat]').val();
+      var lon = $('form input[name=lon]').val();
+      $('form input[name=lat]').val(lon);
+      $('form input[name=lon]').val(lat);
+      $('form').submit();
+    });
+  }
 
-    highlight_result(0, false);
+  highlight_result(0, false);
 
-    // common mistake is to copy&paste latitude and longitude into the 'lat' search box
-    $('form input[name=lat]').on('change', function(){
-        var coords = $(this).val().split(',');
-        if (coords.length == 2) {
-            $(this).val(L.Util.trim(coords[0]));
-            $(this).siblings('input[name=lon]').val(L.Util.trim(coords[1]));
-        }
-    });
+  // common mistake is to copy&paste latitude and longitude into the 'lat' search box
+  $('form input[name=lat]').on('change', function(){
+    var coords = $(this).val().split(',');
+    if (coords.length == 2) {
+      $(this).val(L.Util.trim(coords[0]));
+      $(this).siblings('input[name=lon]').val(L.Util.trim(coords[1]));
+    }
+  });
 };
 
 
@@ -244,103 +244,103 @@ function init_map_on_search_page(is_reverse_search, nominatim_results, request_l
 
 jQuery(document).ready(function(){
 
-    if ( !$('#search-page,#reverse-page').length ){ return; }
-    
-    var is_reverse_search = !!( $('#reverse-page').length );
-    var endpoint = is_reverse_search ? 'reverse' : 'search';
-
-
-    var search_params = new URLSearchParams(location.search);
-
-    // return view('search', [
-    //     'sQuery' => $sQuery,
-    //     'bAsText' => '',
-    //     'sViewBox' => '',
-    //     'aSearchResults' => $aSearchResults,
-    //     'sMoreURL' => 'example.com',
-    //     'sDataDate' => $this->fetch_status_date(),
-    //     'sApiURL' => $url
-    // ]);
-
-
-    if (is_reverse_search) {
-        var api_request_params = {
-            // lat: typeof(search_params.get('lat') !== 'undefined') ? search_params.get('lat') : get_config_value('Map_Default_Lat'),
-            // lon: typeof(search_params.get('lon') !== 'undefined') ? search_params.get('lon') : get_config_value('Map_Default_Lon'),
-            lat: search_params.get('lat'),
-            lon: search_params.get('lon'),
-            zoom: (search_params.get('zoom') !== null ? search_params.get('zoom') : get_config_value('Reverse_Default_Search_Zoom')),
-            format: 'jsonv2'
-        }
-
-        var context = {
-            // aPlace: aPlace,
-            fLat: api_request_params.lat,
-            fLon: api_request_params.lon,
-            iZoom: (search_params.get('zoom') !== null ? api_request_params.zoom : get_config_value('Reverse_Default_Search_Zoom'))
-        };
-
+  if ( !$('#search-page,#reverse-page').length ){ return; }
+  
+  var is_reverse_search = !!( $('#reverse-page').length );
+  var endpoint = is_reverse_search ? 'reverse' : 'search';
+
+
+  var search_params = new URLSearchParams(location.search);
+
+  // return view('search', [
+  //     'sQuery' => $sQuery,
+  //     'bAsText' => '',
+  //     'sViewBox' => '',
+  //     'aSearchResults' => $aSearchResults,
+  //     'sMoreURL' => 'example.com',
+  //     'sDataDate' => $this->fetch_status_date(),
+  //     'sApiURL' => $url
+  // ]);
+
+
+  if (is_reverse_search) {
+    var api_request_params = {
+      // lat: typeof(search_params.get('lat') !== 'undefined') ? search_params.get('lat') : get_config_value('Map_Default_Lat'),
+      // lon: typeof(search_params.get('lon') !== 'undefined') ? search_params.get('lon') : get_config_value('Map_Default_Lon'),
+      lat: search_params.get('lat'),
+      lon: search_params.get('lon'),
+      zoom: (search_params.get('zoom') !== null ? search_params.get('zoom') : get_config_value('Reverse_Default_Search_Zoom')),
+      format: 'jsonv2'
+    }
 
-        if (api_request_params.lat && api_request_params.lon) {
+    var context = {
+      // aPlace: aPlace,
+      fLat: api_request_params.lat,
+      fLon: api_request_params.lon,
+      iZoom: (search_params.get('zoom') !== null ? api_request_params.zoom : get_config_value('Reverse_Default_Search_Zoom'))
+    };
 
-            fetch_from_api('reverse', api_request_params, function(aPlace){
 
-                if (aPlace.error) {
-                    aPlace = null;
-                }
+    if (api_request_params.lat && api_request_params.lon) {
 
-                context.aPlace = aPlace;
+      fetch_from_api('reverse', api_request_params, function(aPlace){
 
-                render_template($('main'), 'reversepage-template', context);
+        if (aPlace.error) {
+          aPlace = null;
+        }
 
-                init_map_on_search_page(is_reverse_search, [aPlace], api_request_params.lat, api_request_params.lon, api_request_params.zoom);
+        context.aPlace = aPlace;
 
-                update_data_date();
-            });
-        } else {
-            render_template($('main'), 'reversepage-template', context);
+        render_template($('main'), 'reversepage-template', context);
 
-            init_map_on_search_page(is_reverse_search, [], get_config_value('Map_Default_Lat'), get_config_value('Map_Default_Lon'), get_config_value('Map_Default_Zoom'));
-        }
+        init_map_on_search_page(is_reverse_search, [aPlace], api_request_params.lat, api_request_params.lon, api_request_params.zoom);
 
+        update_data_date();
+      });
     } else {
-        var api_request_params = {
-            q: search_params.get('q'),
-            polygon_geojson: search_params.get('polygon_geojson') ? 1 : 0,
-            viewbox: search_params.get('viewbox'),
-            format: 'jsonv2'
-        };
+      render_template($('main'), 'reversepage-template', context);
 
-        var context = {
-            // aSearchResults: aResults,
-            sQuery: api_request_params.q,
-            sViewBox: '',
-            env: Nominatim_Config,
-            sMoreURL: ''
-        };
+      init_map_on_search_page(is_reverse_search, [], get_config_value('Map_Default_Lat'), get_config_value('Map_Default_Lon'), get_config_value('Map_Default_Zoom'));
+    }
 
-        if (api_request_params.q) {
+  } else {
+    var api_request_params = {
+      q: search_params.get('q'),
+      polygon_geojson: search_params.get('polygon_geojson') ? 1 : 0,
+      viewbox: search_params.get('viewbox'),
+      format: 'jsonv2'
+    };
 
-            fetch_from_api('search', api_request_params, function(aResults){
+    var context = {
+      // aSearchResults: aResults,
+      sQuery: api_request_params.q,
+      sViewBox: '',
+      env: Nominatim_Config,
+      sMoreURL: ''
+    };
 
-                context.aSearchResults = aResults;
+    if (api_request_params.q) {
 
-                render_template($('main'), 'searchpage-template', context);
+      fetch_from_api('search', api_request_params, function(aResults){
 
-                init_map_on_search_page(is_reverse_search, aResults, get_config_value('Map_Default_Lat'), get_config_value('Map_Default_Lon'), get_config_value('Map_Default_Zoom'));
+        context.aSearchResults = aResults;
 
-                $('#q').focus();
+        render_template($('main'), 'searchpage-template', context);
 
-                update_data_date();
-            });
-        } else {
-            render_template($('main'), 'searchpage-template', context);
+        init_map_on_search_page(is_reverse_search, aResults, get_config_value('Map_Default_Lat'), get_config_value('Map_Default_Lon'), get_config_value('Map_Default_Zoom'));
 
-            init_map_on_search_page(is_reverse_search, [], get_config_value('Map_Default_Lat'), get_config_value('Map_Default_Lon'), get_config_value('Map_Default_Zoom'));
-        }
+        $('#q').focus();
 
+        update_data_date();
+      });
+    } else {
+      render_template($('main'), 'searchpage-template', context);
 
+      init_map_on_search_page(is_reverse_search, [], get_config_value('Map_Default_Lat'), get_config_value('Map_Default_Lon'), get_config_value('Map_Default_Zoom'));
     }
+
+
+  }
 });
 
 
index e1272bf16f37e09488fee03a8d9eaf42f50b1111..94253bc909c4d7fc4c3dc419849f1193c3b429c9 100644 (file)
@@ -1,12 +1,12 @@
 var Nominatim_Config = {
-    // "Nominatim_API_Endpoint": 'http://localhost:8089/nominatim/',
-    "Nominatim_API_Endpoint": 'https://nominatim.openstreetmap.org/',
-    "Images_Base_Url": 'http://localhost:8089/',
-    "Search_AreaPolygons": 1,
-    "Reverse_Default_Search_Zoom": 18,
-    "Map_Default_Lat": 20.0,
-    "Map_Default_Lon": 0.0,
-    "Map_Default_Zoom": 2,
-    "Map_Tile_URL": "https://{s}.tile.osm.org/{z}/{x}/{y}.png",
-    "Map_Tile_Attribution": ""
+  // "Nominatim_API_Endpoint": 'http://localhost:8089/nominatim/',
+  "Nominatim_API_Endpoint": 'https://nominatim.openstreetmap.org/',
+  "Images_Base_Url": 'http://localhost:8089/',
+  "Search_AreaPolygons": 1,
+  "Reverse_Default_Search_Zoom": 18,
+  "Map_Default_Lat": 20.0,
+  "Map_Default_Lon": 0.0,
+  "Map_Default_Zoom": 2,
+  "Map_Tile_URL": "https://{s}.tile.osm.org/{z}/{x}/{y}.png",
+  "Map_Tile_Attribution": ""
 };
index 20ecb7c132711815b073e94bc3e46ce36213adfe..7b69d63d9298d7f4819ad444ff7fb50ae9b51aa7 100644 (file)
 function formatOSMType(sType, bExcludeExternal)
 {
-    if (sType == 'N') return 'node';
-    if (sType == 'W') return 'way';
-    if (sType == 'R') return 'relation';
+  if (sType == 'N') return 'node';
+  if (sType == 'W') return 'way';
+  if (sType == 'R') return 'relation';
 
-    if (!bExcludeExternal) return '';
+  if (!bExcludeExternal) return '';
 
-    if (sType == 'T') return 'way';
-    if (sType == 'I') return 'way';
+  if (sType == 'T') return 'way';
+  if (sType == 'I') return 'way';
 
-    return '';
+  return '';
 }
 
 Handlebars.registerHelper({
-    isaddresses_unused: function(aAddressLine) {
-        return ((aAddressLine.isaddress && aAddressLine.isaddress == 'f') ? 'notused' : '');
-    },
-    // { osm_type: 'R', osm_id: 12345 }
-    // <a href="https://www.openstreetmap.org/relation/12345">relation 12345</a
-    osmLink: function(aPlace) {
-        if (!aPlace.osm_type) return '';
-        var sOSMType = formatOSMType(aPlace.osm_type, false);
-        if (!sOSMType) return '';
-
-        return new Handlebars.SafeString(
-            '<a href="https://www.openstreetmap.org/' + sOSMType + '/' + aPlace.osm_id + '">' + sOSMType + ' ' + aPlace.osm_id + '</a>'
-        );
-    },
-    /* en:London_Borough_of_Redbridge => https://en.wikipedia.org/wiki/London_Borough_of_Redbridge */
-    wikipediaLink: function(aPlace) {
-        if (! aPlace.calculated_wikipedia) return '';
-
-        var parts = aPlace.calculated_wikipedia.split(':', 2);
-
-        var sTitle = Handlebars.escapeExpression(aPlace.calculated_wikipedia),
-            sLanguage = Handlebars.escapeExpression(parts[0]),
-            sArticle = Handlebars.escapeExpression(parts[1]);
-
-        return new Handlebars.SafeString(
-            '<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 '';
-
-        sTitle = Handlebars.escapeExpression(sTitle || 'details >');
-
-        return new Handlebars.SafeString(
-            '<a href="details.html?place_id=' + aFeature.place_id + '">' + sTitle + '</a>'
-        );
-    },
-    detailsPermaLink: function(aFeature, sTitle) {
-        if (!aFeature) return '';
-
-        var sOSMType = formatOSMType(aFeature.osm_type, false);
-        if (!sOSMType) return '';
-
-        sTitle = Handlebars.escapeExpression(sTitle || sOSMType + ' ' + aFeature.osm_id);
-
-        return new Handlebars.SafeString(
-            '<a href="details.html?osmtype=' + aFeature.osm_type + '&osmid=' + aFeature.osm_id + '&class=' + aFeature.category + '">' + sTitle + '</a>'
-        );
-    },
-    coverageType: function(aPlace) {
-        return (aPlace.isarea ? 'Polygon' : 'Point');
-    },
-    // fDistance is in meters
-    formatDistance: function(fDistanceMeters) {
-        if (fDistanceMeters < 1) return '0';
-
-        var formatted = (fDistanceMeters >= 1000) ?
-            Math.round(fDistanceMeters/1000, 1) + ' km' :
-            Math.round(fDistanceMeters, 0) + ' m';
-
-        return new Handlebars.SafeString(
-            '<abbr class="distance" title="' + fDistanceMeters + '">~' + formatted + '</abbr>'
-        );
-    },
-    // mark partial tokens (those starting with a space) with a star for readability
-    formatKeywordToken: function(sToken) {
-        return (sToken[0] == ' ' ? '*' : '') + Handlebars.escapeExpression(sToken);
-    },
-    // Any over 15 are invalid data in OSM anyway
-    formatAdminLevel: function(iLevel) {
-        return (iLevel < 15 ? iLevel : '');
-    },
-    formatMapIcon: function(sIcon) {
-        if (!sIcon) return;
-        
-        var url = sIcon;
-        if (!url.match(/^http/)) url = get_config_value('Images_Base_Url') + url;
-
-        return new Handlebars.SafeString(
-            '<img class="mapicon" src="' + url + '" alt="' + sIcon + '"/>'
-        );
-    },
-    formatLabel: function(aPlace) {
-        if (aPlace.label) return aPlace.label;
-
-        function capitalize(s)
-        {
-            return s && s[0].toUpperCase() + s.slice(1);
-        }
-
-        if (aPlace.type && aPlace.type === 'yes') {
-            return capitalize(aPlace.class.replace(/_/g, ' '));
-        } else {
-            return capitalize(aPlace.type.replace(/_/g, ' '));
-        }
-    },
-    formatSearchRank: function(iRank) {
-        // same as
-        // https://github.com/openstreetmap/Nominatim/blob/master/sql/functions.sql
-        // get_searchrank_label()
-
-        if (iRank < 2) {
-            return 'continent';
-        } else if (iRank < 4) {
-            return 'sea';
-        } else if (iRank < 8) {
-            return 'country';
-        } else if (iRank < 12) {
-            return 'state';
-        } else if (iRank < 16) { 
-            return 'county';
-        } else if (iRank == 16) {
-            return 'city';
-        } else if (iRank == 17) {
-            return 'town / island';
-        } else if (iRank == 18) {
-            return 'village / hamlet';
-        } else if (iRank == 20) {
-            return 'suburb';
-        } else if (iRank == 21) {
-            return 'postcode area';
-        } else if (iRank == 22) {
-            return 'croft / farm / locality / islet';
-        } else if (iRank == 23) {
-            return 'postcode area';
-        } else if (iRank == 25) {
-            return 'postcode point';
-        } else if (iRank == 26) {
-            return 'street / major landmark';
-        } else if (iRank == 27) {
-            return 'minory street / path';
-        } else if (iRank == 28) {
-            return 'house / building';
-        } else {
-            return 'other: ' + iRank;
-        }
-    },
-    tooManyHierarchyLinesWarning: function(aPlace) {
-        if (!aPlace.hierarchy) return;
-
-        var c = 0;
-        for (var type in aPlace.hierarchy) {
-            c = c + type.length+1;
-        }
-        if (c < 500) return;
-
-        return new Handlebars.SafeString(
-            '<p>There are more child objects which are not shown.</p>'
-        );
-    },
-    zoomLevels: function(iSelectedZoom) {
-        var aZoomLevels = [
-            /*  0 */ 'Continent / Sea',
-            /*  1 */ '',
-            /*  2 */ '',
-            /*  3 */ 'Country',
-            /*  4 */ '',
-            /*  5 */ 'State',
-            /*  6 */ 'Region',
-            /*  7 */ '',
-            /*  8 */ 'County',
-            /*  9 */ '',
-            /* 10 */ 'City',
-            /* 11 */ '',
-            /* 12 */ 'Town / Village',
-            /* 13 */ '',
-            /* 14 */ 'Suburb',
-            /* 15 */ '',
-            /* 16 */ 'Street',
-            /* 17 */ '',
-            /* 18 */ 'Building',
-            /* 19 */ '',
-            /* 20 */ '',
-            /* 21 */ ''
-        ];
-
-        var select = $('<select>');
-        var option = jQuery('<option>', { value: '', text: '--'});
-        if (typeof(iSelectedZoom) === 'undefined') option.attr('selected', 'selected');
-        option.appendTo(select);
-
-        jQuery.each(aZoomLevels, function(i, title) {
-            var option = jQuery('<option>', { value: i, text: i + ' ' + title });
-            if (i == iSelectedZoom) option.attr('selected', 'selected');
-            option.appendTo(select);
-        });
-        return new Handlebars.SafeString(select.html());
+  isaddresses_unused: function(aAddressLine) {
+    return ((aAddressLine.isaddress && aAddressLine.isaddress == 'f') ? 'notused' : '');
+  },
+  // { osm_type: 'R', osm_id: 12345 }
+  // <a href="https://www.openstreetmap.org/relation/12345">relation 12345</a
+  osmLink: function(aPlace) {
+    if (!aPlace.osm_type) return '';
+    var sOSMType = formatOSMType(aPlace.osm_type, false);
+    if (!sOSMType) return '';
+
+    return new Handlebars.SafeString(
+      '<a href="https://www.openstreetmap.org/' + sOSMType + '/' + aPlace.osm_id + '">' + sOSMType + ' ' + aPlace.osm_id + '</a>'
+    );
+  },
+  /* en:London_Borough_of_Redbridge => https://en.wikipedia.org/wiki/London_Borough_of_Redbridge */
+  wikipediaLink: function(aPlace) {
+    if (! aPlace.calculated_wikipedia) return '';
+
+    var parts = aPlace.calculated_wikipedia.split(':', 2);
+
+    var sTitle = Handlebars.escapeExpression(aPlace.calculated_wikipedia),
+      sLanguage = Handlebars.escapeExpression(parts[0]),
+      sArticle = Handlebars.escapeExpression(parts[1]);
+
+    return new Handlebars.SafeString(
+      '<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 '';
+
+    sTitle = Handlebars.escapeExpression(sTitle || 'details >');
+
+    return new Handlebars.SafeString(
+      '<a href="details.html?place_id=' + aFeature.place_id + '">' + sTitle + '</a>'
+    );
+  },
+  detailsPermaLink: function(aFeature, sTitle) {
+    if (!aFeature) return '';
+
+    var sOSMType = formatOSMType(aFeature.osm_type, false);
+    if (!sOSMType) return '';
+
+    sTitle = Handlebars.escapeExpression(sTitle || sOSMType + ' ' + aFeature.osm_id);
+
+    return new Handlebars.SafeString(
+      '<a href="details.html?osmtype=' + aFeature.osm_type + '&osmid=' + aFeature.osm_id + '&class=' + aFeature.category + '">' + sTitle + '</a>'
+    );
+  },
+  coverageType: function(aPlace) {
+    return (aPlace.isarea ? 'Polygon' : 'Point');
+  },
+  // fDistance is in meters
+  formatDistance: function(fDistanceMeters) {
+    if (fDistanceMeters < 1) return '0';
+
+    var formatted = (fDistanceMeters >= 1000) ?
+      Math.round(fDistanceMeters/1000, 1) + ' km' :
+      Math.round(fDistanceMeters, 0) + ' m';
+
+    return new Handlebars.SafeString(
+      '<abbr class="distance" title="' + fDistanceMeters + '">~' + formatted + '</abbr>'
+    );
+  },
+  // mark partial tokens (those starting with a space) with a star for readability
+  formatKeywordToken: function(sToken) {
+    return (sToken[0] == ' ' ? '*' : '') + Handlebars.escapeExpression(sToken);
+  },
+  // Any over 15 are invalid data in OSM anyway
+  formatAdminLevel: function(iLevel) {
+    return (iLevel < 15 ? iLevel : '');
+  },
+  formatMapIcon: function(sIcon) {
+    if (!sIcon) return;
+    
+    var url = sIcon;
+    if (!url.match(/^http/)) url = get_config_value('Images_Base_Url') + url;
+
+    return new Handlebars.SafeString(
+      '<img class="mapicon" src="' + url + '" alt="' + sIcon + '"/>'
+    );
+  },
+  formatLabel: function(aPlace) {
+    if (aPlace.label) return aPlace.label;
+
+    function capitalize(s)
+    {
+      return s && s[0].toUpperCase() + s.slice(1);
     }
+
+    if (aPlace.type && aPlace.type === 'yes') {
+      return capitalize(aPlace.class.replace(/_/g, ' '));
+    } else {
+      return capitalize(aPlace.type.replace(/_/g, ' '));
+    }
+  },
+  formatSearchRank: function(iRank) {
+    // same as
+    // https://github.com/openstreetmap/Nominatim/blob/master/sql/functions.sql
+    // get_searchrank_label()
+
+    if (iRank < 2) {
+      return 'continent';
+    } else if (iRank < 4) {
+      return 'sea';
+    } else if (iRank < 8) {
+      return 'country';
+    } else if (iRank < 12) {
+      return 'state';
+    } else if (iRank < 16) { 
+      return 'county';
+    } else if (iRank == 16) {
+      return 'city';
+    } else if (iRank == 17) {
+      return 'town / island';
+    } else if (iRank == 18) {
+      return 'village / hamlet';
+    } else if (iRank == 20) {
+      return 'suburb';
+    } else if (iRank == 21) {
+      return 'postcode area';
+    } else if (iRank == 22) {
+      return 'croft / farm / locality / islet';
+    } else if (iRank == 23) {
+      return 'postcode area';
+    } else if (iRank == 25) {
+      return 'postcode point';
+    } else if (iRank == 26) {
+      return 'street / major landmark';
+    } else if (iRank == 27) {
+      return 'minory street / path';
+    } else if (iRank == 28) {
+      return 'house / building';
+    } else {
+      return 'other: ' + iRank;
+    }
+  },
+  tooManyHierarchyLinesWarning: function(aPlace) {
+    if (!aPlace.hierarchy) return;
+
+    var c = 0;
+    for (var type in aPlace.hierarchy) {
+      c = c + type.length+1;
+    }
+    if (c < 500) return;
+
+    return new Handlebars.SafeString(
+      '<p>There are more child objects which are not shown.</p>'
+    );
+  },
+  zoomLevels: function(iSelectedZoom) {
+    var aZoomLevels = [
+      /*  0 */ 'Continent / Sea',
+      /*  1 */ '',
+      /*  2 */ '',
+      /*  3 */ 'Country',
+      /*  4 */ '',
+      /*  5 */ 'State',
+      /*  6 */ 'Region',
+      /*  7 */ '',
+      /*  8 */ 'County',
+      /*  9 */ '',
+      /* 10 */ 'City',
+      /* 11 */ '',
+      /* 12 */ 'Town / Village',
+      /* 13 */ '',
+      /* 14 */ 'Suburb',
+      /* 15 */ '',
+      /* 16 */ 'Street',
+      /* 17 */ '',
+      /* 18 */ 'Building',
+      /* 19 */ '',
+      /* 20 */ '',
+      /* 21 */ ''
+    ];
+
+    var select = $('<select>');
+    var option = jQuery('<option>', { value: '', text: '--'});
+    if (typeof(iSelectedZoom) === 'undefined') option.attr('selected', 'selected');
+    option.appendTo(select);
+
+    jQuery.each(aZoomLevels, function(i, title) {
+      var option = jQuery('<option>', { value: i, text: i + ' ' + title });
+      if (i == iSelectedZoom) option.attr('selected', 'selected');
+      option.appendTo(select);
+    });
+    return new Handlebars.SafeString(select.html());
+  }
 });