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) {
50 // `&a=&b=&c=1` => '&c='
51 for(var k in params) {
52 if (typeof(params[k]) === 'undefined' || params[k] === '' || params[k] === null ) delete params[k];
55 var api_url = get_config_value('Nominatim_API_Endpoint') + endpoint_name + '.php?' + $.param(params);
56 if (endpoint_name !== 'status') {
57 $('#api-request-link').attr('href', api_url);
59 $.get(api_url, function(data){
64 function update_data_date() {
65 fetch_from_api('status', {format: 'json'}, function(data){
66 $('#data-date').text(data.data_last_updated.formatted);
70 function render_template(el, template_name, page_context) {
71 var template_source = $('#' + template_name).text();
72 var template = Handlebars.compile(template_source);
73 var html = template(page_context);
77 function show_error(html) {
78 $('#error-overlay').html(html).show();
81 function hide_error() {
82 $('#error-overlay').empty().hide();
86 $(document).ajaxError(function(event, jqXHR, ajaxSettings, thrownError) {
87 // console.log(thrownError);
88 // console.log(ajaxSettings);
89 show_error('Error fetching results from <a href="' + ajaxSettings.url + '">' + ajaxSettings.url + '</a>');
93 jQuery(document).ready(function(){