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) {
59 // `&a=&b=&c=1` => '&c='
60 for (var k in params) {
61 if (typeof (params[k]) === 'undefined' || params[k] === '' || params[k] === null) delete params[k];
64 var api_url = get_config_value('Nominatim_API_Endpoint') + endpoint_name + '.php?' + $.param(params);
65 if (endpoint_name !== 'status') {
66 $('#api-request-link').attr('href', api_url);
68 $.get(api_url, function (data) {
73 function update_data_date() {
74 fetch_from_api('status', { format: 'json' }, function (data) {
75 $('#data-date').text(data.data_updated);
79 function render_template(el, template_name, page_context) {
80 var template_source = $('#' + template_name).text();
81 var template = Handlebars.compile(template_source);
82 var html = template(page_context);
86 function show_error(html) {
87 $('#error-overlay').html(html).show();
90 function hide_error() {
91 $('#error-overlay').empty().hide();
95 $(document).ajaxError(function (event, jqXHR, ajaxSettings, thrownError) {
96 // console.log(thrownError);
97 // console.log(ajaxSettings);
98 show_error('Error fetching results from <a href="' + ajaxSettings.url + '">' + ajaxSettings.url + '</a>');
102 jQuery(document).ready(function () {