6 // *********************************************************
8 // *********************************************************
10 var Nominatim_Config_Defaults = {
11 Nominatim_API_Endpoint: 'http://localhost/nominatim/',
12 Images_Base_Url: '/mapicons/',
13 Search_AreaPolygons: 1,
14 Reverse_Default_Search_Zoom: 18,
15 Map_Default_Lat: 20.0,
18 Map_Tile_URL: 'https://{s}.tile.osm.org/{z}/{x}/{y}.png',
19 Map_Tile_Attribution: '<a href="https://osm.org/copyright">OpenStreetMap contributors</a>'
22 // *********************************************************
24 // *********************************************************
27 function get_config_value(str, default_val) {
28 var value = ((typeof Nominatim_Config !== 'undefined')
29 && (typeof Nominatim_Config[str] !== 'undefined'))
30 ? Nominatim_Config[str]
31 : Nominatim_Config_Defaults[str];
32 return (typeof value !== 'undefined' ? value : default_val);
35 function parse_and_normalize_geojson_string(part) {
36 // normalize places the geometry into a featurecollection, similar to
37 // https://github.com/mapbox/geojson-normalize
38 var parsed_geojson = {
39 type: 'FeatureCollection',
48 return parsed_geojson;
51 function map_link_to_osm() {
52 var zoom = map.getZoom();
53 var lat = map.getCenter().lat;
54 var lng = map.getCenter().lng;
55 return 'https://openstreetmap.org/#map=' + zoom + '/' + lat + '/' + lng;
58 function map_viewbox_as_string() {
59 var bounds = map.getBounds();
60 var west = bounds.getWest();
61 var east = bounds.getEast();
63 if ((east - west) >= 360) { // covers more than whole planet
64 west = map.getCenter().lng - 179.999;
65 east = map.getCenter().lng + 179.999;
67 east = L.latLng(77, east).wrap().lng;
68 west = L.latLng(77, west).wrap().lng;
71 west.toFixed(5), // left
72 bounds.getNorth().toFixed(5), // top
73 east.toFixed(5), // right
74 bounds.getSouth().toFixed(5) // bottom
79 // *********************************************************
81 // *********************************************************
83 function fetch_from_api(endpoint_name, params, callback) {
85 // `&a=&b=&c=1` => '&c=1'
86 var param_names = Object.keys(params);
87 for (var i = 0; i < param_names.length; i += 1) {
88 var val = params[param_names[i]];
89 if (typeof (val) === 'undefined' || val === '' || val === null) {
90 delete params[param_names[i]];
94 var api_url = get_config_value('Nominatim_API_Endpoint') + endpoint_name + '.php?'
96 if (endpoint_name !== 'status') {
97 $('#api-request-link').attr('href', api_url);
99 $.get(api_url, function (data) {
104 function update_data_date() {
105 fetch_from_api('status', { format: 'json' }, function (data) {
106 $('#data-date').text(data.data_updated);
110 function render_template(el, template_name, page_context) {
111 var template_source = $('#' + template_name).text();
112 var template = Handlebars.compile(template_source);
113 var html = template(page_context);
117 function update_html_title(title) {
119 if (title && title.length > 1) {
120 prefix = title + ' | ';
122 $('head title').text(prefix + 'OpenStreetMap Nominatim');
125 function show_error(html) {
126 $('#error-overlay').html(html).show();
129 function hide_error() {
130 $('#error-overlay').empty().hide();
134 $(document).ajaxError(function (event, jqXHR, ajaxSettings/* , thrownError */) {
135 // console.log(thrownError);
136 // console.log(ajaxSettings);
137 var url = ajaxSettings.url;
138 show_error('Error fetching results from <a href="' + url + '">' + url + '</a>');
142 jQuery(document).ready(function () {