7 // *********************************************************
9 // *********************************************************
11 function get_config_value(str, default_val) {
12 return (typeof Nominatim_Config[str] !== 'undefined' ? Nominatim_Config[str] : default_val);
15 function parse_and_normalize_geojson_string(part) {
16 // normalize places the geometry into a featurecollection, similar to
17 // https://github.com/mapbox/geojson-normalize
18 var parsed_geojson = {
19 type: 'FeatureCollection',
28 return parsed_geojson;
31 function map_link_to_osm() {
32 return 'https://openstreetmap.org/#map=' + map.getZoom() + '/' + map.getCenter().lat + '/' + map.getCenter().lng;
35 function map_viewbox_as_string() {
36 var bounds = map.getBounds();
37 var west = bounds.getWest();
38 var east = bounds.getEast();
40 if ((east - west) >= 360) { // covers more than whole planet
41 west = map.getCenter().lng - 179.999;
42 east = map.getCenter().lng + 179.999;
44 east = L.latLng(77, east).wrap().lng;
45 west = L.latLng(77, west).wrap().lng;
48 west.toFixed(5), // left
49 bounds.getNorth().toFixed(5), // top
50 east.toFixed(5), // right
51 bounds.getSouth().toFixed(5) // bottom
56 // *********************************************************
58 // *********************************************************
60 function fetch_from_api(endpoint_name, params, callback) {
61 // `&a=&b=&c=1` => '&c='
62 for (var k in params) {
63 if (typeof (params[k]) === 'undefined' || params[k] === '' || params[k] === null) delete params[k];
66 var api_url = get_config_value('Nominatim_API_Endpoint') + endpoint_name + '.php?' + $.param(params);
67 if (endpoint_name !== 'status') {
68 $('#api-request-link').attr('href', api_url);
70 $.get(api_url, function (data) {
75 function update_data_date() {
76 fetch_from_api('status', { format: 'json' }, function (data) {
77 $('#data-date').text(data.data_updated);
81 function render_template(el, template_name, page_context) {
82 var template_source = $('#' + template_name).text();
83 var template = Handlebars.compile(template_source);
84 var html = template(page_context);
88 function update_html_title(title) {
90 if (title && title.length > 1) {
91 prefix = title + ' | ';
93 $('head title').text(prefix + 'OpenStreetMap Nominatim');
96 function show_error(html) {
97 $('#error-overlay').html(html).show();
100 function hide_error() {
101 $('#error-overlay').empty().hide();
105 $(document).ajaxError(function (event, jqXHR, ajaxSettings/* , thrownError */) {
106 // console.log(thrownError);
107 // console.log(ajaxSettings);
108 show_error('Error fetching results from <a href="' + ajaxSettings.url + '">' + ajaxSettings.url + '</a>');
112 jQuery(document).ready(function () {