4 jQuery(document).on('ready', function(){
6 if ( !$('#search-page,#reverse-page').length ){ return; }
8 var is_reverse_search = !!( $('#reverse-page').length );
12 map = new L.map('map', {
13 attributionControl: (nominatim_map_init.tile_attribution && nominatim_map_init.tile_attribution.length),
14 scrollWheelZoom: !L.Browser.touch,
18 L.tileLayer(nominatim_map_init.tile_url, {
19 noWrap: true, // otherwise we end up with click coordinates like latitude -728
21 attribution: (nominatim_map_init.tile_attribution || null ) //'© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
24 map.setView([nominatim_map_init.lat, nominatim_map_init.lon], nominatim_map_init.zoom);
26 if ( is_reverse_search ){
27 // We don't need a marker, but an L.circle instance changes radius once you zoom in/out
28 var cm = L.circleMarker([nominatim_map_init.lat,nominatim_map_init.lon], { radius: 5, weight: 2, fillColor: '#ff7800', color: 'red', opacity: 0.75, clickable: false});
32 var MapPositionControl = L.Control.extend({
34 position: 'bottomright'
37 onAdd: function (map) {
38 var container = L.DomUtil.create('div', 'my-custom-control');
40 $(container).text('show map bounds').addClass('leaflet-bar btn btn-sm btn-default').on('click', function(e){
43 $('#map-position').show();
46 $('#map-position-close a').on('click', function(e){
49 $('#map-position').hide();
57 map.addControl(new MapPositionControl());
60 function display_map_position(mouse_lat_lng){
62 html_mouse = "mouse position " + (mouse_lat_lng ? [mouse_lat_lng.lat.toFixed(5), mouse_lat_lng.lng.toFixed(5)].join(',') : '-');
63 html_click = "last click: " + (last_click_latlng ? [last_click_latlng.lat.toFixed(5),last_click_latlng.lng.toFixed(5)].join(',') : '-');
67 map.getCenter().lat.toFixed(5) + ',' + map.getCenter().lng.toFixed(5) +
68 " <a target='_blank' href='" + map_link_to_osm() + "'>view on osm.org</a>";
70 html_zoom = "map zoom: " + map.getZoom();
72 html_viewbox = "viewbox: " + map_viewbox_as_string();
74 $('#map-position-inner').html([html_center,html_zoom,html_viewbox,html_click,html_mouse].join('<br/>'));
75 $('input#use_viewbox').trigger('change');
78 map.on('move', function(e) {
79 display_map_position();
82 map.on('mousemove', function(e) {
83 display_map_position(e.latlng);
86 map.on('click', function(e) {
87 last_click_latlng = e.latlng;
88 display_map_position();
91 map.on('load', function(e){
92 display_map_position();
96 $('input#use_viewbox').on('change', function(){
97 $('input[name=viewbox]').val( $(this).prop('checked') ? map_viewbox_as_string() : '');
102 function map_viewbox_as_string() {
103 // since .toBBoxString() doesn't round numbers
105 map.getBounds().getSouthWest().lat.toFixed(5),
106 map.getBounds().getSouthWest().lng.toFixed(5),
107 map.getBounds().getNorthEast().lat.toFixed(5),
108 map.getBounds().getNorthEast().lng.toFixed(5) ].join(',');
110 function map_link_to_osm(){
111 return "http://openstreetmap.org/#map=" + map.getZoom() + "/" + map.getCenter().lat + "/" + map.getCenter().lng;
114 function get_result_element(position){
115 return $('.result').eq(position);
117 function marker_for_result(result){
118 return L.marker([result.lat,result.lon], {riseOnHover:true,title:result.name });
120 function circle_for_result(result){
121 return L.circleMarker([result.lat,result.lon], { radius: 10, weight: 2, fillColor: '#ff7800', color: 'blue', opacity: 0.75, clickable: !is_reverse_search});
124 var layerGroup = new L.layerGroup().addTo(map);
125 function highlight_result(position, bool_focus){
126 var result = nominatim_results[position];
127 if (!result){ return }
128 var result_el = get_result_element(position);
130 $('.result').removeClass('highlight');
131 result_el.addClass('highlight');
133 layerGroup.clearLayers();
136 var circle = circle_for_result(result);
137 circle.on('click', function(){
138 highlight_result(position);
140 layerGroup.addLayer(circle);
142 if (result.aBoundingBox){
144 var bounds = [[result.aBoundingBox[0]*1,result.aBoundingBox[2]*1], [result.aBoundingBox[1]*1,result.aBoundingBox[3]*1]];
145 map.fitBounds(bounds);
146 if (result.astext && result.astext.match(/(POLY)|(LINE)/) ){
147 var geojson_layer = L.geoJson(null, {
148 // http://leafletjs.com/reference.html#geojson-style
149 style: function(feature) { return { clickable: false, color: 'blue' }; }
151 omnivore.wkt.parse(result.astext,null,geojson_layer);
152 layerGroup.addLayer(geojson_layer);
155 // var layer = L.rectangle(bounds, {color: "#ff7800", weight: 1} );
156 // layerGroup.addLayer(layer);
160 if ( is_reverse_search ){
161 // make sure the search coordinates are in the map view as well
162 map.fitBounds([[result.lat,result.lon], [nominatim_map_init.lat,nominatim_map_init.lon]], {padding: [50,50], maxZoom: map.getZoom()});
164 // better, but causes a leaflet warning
165 // map.panInsideBounds([[result.lat,result.lon], [nominatim_map_init.lat,nominatim_map_init.lon]], {animate: false});
168 map.panTo([result.lat,result.lon], result.zoom || nominatim_map_init.zoom);
172 // var crosshairIcon = L.icon({
173 // iconUrl: 'images/crosshair.png',
174 // iconSize: [12, 12],
175 // iconAnchor: [6, 6],
177 // var crossMarker = new L.Marker([result.lat,result.lon], { icon: crosshairIcon, clickable: false});
178 // layerGroup.addLayer(crossMarker);
188 $('.result').on('click', function(e){
189 highlight_result($(this).data('position'), true);
192 if ( is_reverse_search ){
193 map.on('click', function(e){
194 $('form input[name=lat]').val( e.latlng.lat);
195 $('form input[name=lon]').val( e.latlng.lng);
200 highlight_result(0, false);
206 jQuery(document).on('ready', function(){
208 if ( !$('#details-page').length ){ return; }
211 map = new L.map('map', {
212 // center: [nominatim_map_init.lat, nominatim_map_init.lon],
213 // zoom: nominatim_map_init.zoom,
214 attributionControl: (nominatim_map_init.tile_attribution && nominatim_map_init.tile_attribution.length),
215 scrollWheelZoom: false,
220 L.tileLayer(nominatim_map_init.tile_url, {
222 attribution: (nominatim_map_init.tile_attribution || null ) //'© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
226 var layerGroup = new L.layerGroup().addTo(map);
228 var circle = L.circleMarker([nominatim_result.lat,nominatim_result.lon], { radius: 10, weight: 2, fillColor: '#ff7800', color: 'blue', opacity: 0.75});
229 map.addLayer(circle);
231 if ( nominatim_result.outlinestring ){
233 var geojson_layer = L.geoJson(null, {
234 // http://leafletjs.com/reference.html#geojson-style
235 style: function(feature) { return { clickable: false, color: 'blue' }; }
237 omnivore.wkt.parse(nominatim_result.outlinestring,null,geojson_layer);
238 layerGroup.addLayer(geojson_layer);
239 map.fitBounds(geojson_layer.getBounds());
241 map.setView([nominatim_result.lat,nominatim_result.lon],10);