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 var zoom = map.getZoom();
33 var lat = map.getCenter().lat;
34 var lng = map.getCenter().lng;
35 return 'https://openstreetmap.org/#map=' + zoom + '/' + lat + '/' + lng;
38 function map_viewbox_as_string() {
39 var bounds = map.getBounds();
40 var west = bounds.getWest();
41 var east = bounds.getEast();
43 if ((east - west) >= 360) { // covers more than whole planet
44 west = map.getCenter().lng - 179.999;
45 east = map.getCenter().lng + 179.999;
47 east = L.latLng(77, east).wrap().lng;
48 west = L.latLng(77, west).wrap().lng;
51 west.toFixed(5), // left
52 bounds.getNorth().toFixed(5), // top
53 east.toFixed(5), // right
54 bounds.getSouth().toFixed(5) // bottom
59 // *********************************************************
61 // *********************************************************
63 function fetch_from_api(endpoint_name, params, callback) {
65 // `&a=&b=&c=1` => '&c=1'
66 var param_names = Object.keys(params);
67 for (var i = 0; i < param_names.length; i += 1) {
68 var val = params[param_names[i]];
69 if (typeof (val) === 'undefined' || val === '' || val === null) {
70 delete params[param_names[i]];
74 var api_url = get_config_value('Nominatim_API_Endpoint') + endpoint_name + '.php?'
76 if (endpoint_name !== 'status') {
77 $('#api-request-link').attr('href', api_url);
79 $.get(api_url, function (data) {
84 function update_data_date() {
85 fetch_from_api('status', { format: 'json' }, function (data) {
86 $('#data-date').text(data.data_updated);
90 function render_template(el, template_name, page_context) {
91 var template_source = $('#' + template_name).text();
92 var template = Handlebars.compile(template_source);
93 var html = template(page_context);
97 function update_html_title(title) {
99 if (title && title.length > 1) {
100 prefix = title + ' | ';
102 $('head title').text(prefix + 'OpenStreetMap Nominatim');
105 function show_error(html) {
106 $('#error-overlay').html(html).show();
109 function hide_error() {
110 $('#error-overlay').empty().hide();
114 $(document).ajaxError(function (event, jqXHR, ajaxSettings/* , thrownError */) {
115 // console.log(thrownError);
116 // console.log(ajaxSettings);
117 var url = ajaxSettings.url;
118 show_error('Error fetching results from <a href="' + url + '">' + url + '</a>');
122 jQuery(document).ready(function () {