5 /*********************************************************
7 *********************************************************/
9 function get_config_value(str, default_val) {
10 return (typeof Nominatim_Config[str] !== 'undefined' ? Nominatim_Config[str] : default_val);
13 function parse_and_normalize_geojson_string(part){
14 // normalize places the geometry into a featurecollection, similar to
15 // https://github.com/mapbox/geojson-normalize
16 var parsed_geojson = {
17 type: "FeatureCollection",
26 return parsed_geojson;
29 function map_link_to_osm(){
30 return "https://openstreetmap.org/#map=" + map.getZoom() + "/" + map.getCenter().lat + "/" + map.getCenter().lng;
33 function map_viewbox_as_string() {
34 // since .toBBoxString() doesn't round numbers
36 map.getBounds().getSouthWest().lng.toFixed(5), // left
37 map.getBounds().getNorthEast().lat.toFixed(5), // top
38 map.getBounds().getNorthEast().lng.toFixed(5), // right
39 map.getBounds().getSouthWest().lat.toFixed(5) // bottom
44 /*********************************************************
46 *********************************************************/
48 function fetch_from_api(endpoint_name, params, callback) {
49 var api_url = get_config_value('Nominatim_API_Endpoint') + endpoint_name + '.php?' + $.param(params);
50 if (endpoint_name !== 'status') {
51 $('#api-request-link').attr('href', api_url);
53 $.get(api_url, function(data){
58 function update_data_date() {
59 fetch_from_api('status', {format: 'json'}, function(data){
60 $('#data-date').text(data.data_last_updated.formatted);
64 function render_template(el, template_name, page_context) {
65 var template_source = $('#' + template_name).text();
66 var template = Handlebars.compile(template_source);
67 var html = template(page_context);
71 function show_error(html) {
72 $('#error-overlay').html(html).show();
75 function hide_error() {
76 $('#error-overlay').empty().hide();
80 $(document).ajaxError(function(event, jqXHR, ajaxSettings, thrownError) {
81 // console.log(thrownError);
82 // console.log(ajaxSettings);
83 show_error('Error fetching results from <a href="' + ajaxSettings.url + '">' + ajaxSettings.url + '</a>');
87 jQuery(document).ready(function(){