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 var bounds = map.getBounds();
35 var west = bounds.getWest();
36 var east = bounds.getEast();
38 if ((east - west) >= 360) { // covers more than whole planet
39 west = map.getCenter().lng-179.999;
40 east = map.getCenter().lng+179.999;
42 east = L.latLng(77, east).wrap().lng;
43 west = L.latLng(77, west).wrap().lng;
46 west.toFixed(5), // left
47 bounds.getNorth().toFixed(5), // top
48 east.toFixed(5), // right
49 bounds.getSouth().toFixed(5) // bottom
54 /*********************************************************
56 *********************************************************/
58 function fetch_from_api(endpoint_name, params, callback) {
60 // `&a=&b=&c=1` => '&c='
61 for(var k in params) {
62 if (typeof(params[k]) === 'undefined' || params[k] === '' || params[k] === null ) delete params[k];
65 var api_url = get_config_value('Nominatim_API_Endpoint') + endpoint_name + '.php?' + $.param(params);
66 if (endpoint_name !== 'status') {
67 $('#api-request-link').attr('href', api_url);
69 $.get(api_url, function(data){
74 function update_data_date() {
75 fetch_from_api('status', {format: 'json'}, function(data){
76 $('#data-date').text(data.data_updated);
80 function render_template(el, template_name, page_context) {
81 var template_source = $('#' + template_name).text();
82 var template = Handlebars.compile(template_source);
83 var html = template(page_context);
87 function show_error(html) {
88 $('#error-overlay').html(html).show();
91 function hide_error() {
92 $('#error-overlay').empty().hide();
96 $(document).ajaxError(function(event, jqXHR, ajaxSettings, thrownError) {
97 // console.log(thrownError);
98 // console.log(ajaxSettings);
99 show_error('Error fetching results from <a href="' + ajaxSettings.url + '">' + ajaxSettings.url + '</a>');
103 jQuery(document).ready(function(){