4 jQuery(document).on('ready', function(){
6 if ( !$('#search-page').length ){ return; }
10 map = new L.map('map', {
11 center: [nominatim_map_init.lat, nominatim_map_init.lon],
12 zoom: nominatim_map_init.zoom,
13 attributionControl: false,
14 scrollWheelZoom: false,
18 L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
20 // attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
25 function display_map_position(mouse_lat_lng){
27 html_mouse = "mouse position " + (mouse_lat_lng ? [mouse_lat_lng.lat.toFixed(5), mouse_lat_lng.lng.toFixed(5)].join(',') : '-');
28 html_click = "last click: " + (last_click_latlng ? [last_click_latlng.lat.toFixed(5),last_click_latlng.lng.toFixed(5)].join(',') : '-');
32 map.getCenter().lat.toFixed(5) + ',' + map.getCenter().lng.toFixed(5) +
33 " <a target='_blank' href='" + map_link_to_osm() + "'>view on osm.org</a>";
35 html_viewbox = "viewbox: " + map_viewbox_as_string();
37 $('#map-position').html([html_center,html_viewbox,html_click,html_mouse].join('<br/>'));
38 $('input#use_viewbox').trigger('change');
41 map.on('move', function(e) {
42 display_map_position();
45 map.on('mousemove', function(e) {
46 display_map_position(e.latlng);
49 map.on('click', function(e) {
50 last_click_latlng = e.latlng;
51 display_map_position();
54 map.on('load', function(e){
55 display_map_position();
59 $('input#use_viewbox').on('change', function(){
60 $('input[name=viewbox]').val( $(this).prop('checked') ? map_viewbox_as_string() : '');
65 function map_viewbox_as_string() {
66 // since .toBBoxString() doesn't round numbers
68 map.getBounds().getSouthWest().lat.toFixed(5),
69 map.getBounds().getSouthWest().lng.toFixed(5),
70 map.getBounds().getNorthEast().lat.toFixed(5),
71 map.getBounds().getNorthEast().lng.toFixed(5) ].join(',');
73 function map_link_to_osm(){
74 return "http://openstreetmap.org/#map=" + map.getZoom() + "/" + map.getCenter().lat + "/" + map.getCenter().lng;
77 function get_result_element(position){
78 return $('.result').eq(position);
80 function marker_for_result(result){
81 return L.marker([result.lat,result.lon], {riseOnHover:true,title:result.name });
83 function circle_for_result(result){
84 return L.circleMarker([result.lat,result.lon], { radius: 10, weight: 2, fillColor: '#ff7800', color: 'blue', opacity: 0.75});
87 var layerGroup = new L.layerGroup().addTo(map);
88 function highlight_result(position, bool_focus){
89 var result = nominatim_results[position];
90 if (!result){ return }
91 var result_el = get_result_element(position);
93 $('.result').removeClass('highlight');
94 result_el.addClass('highlight');
96 layerGroup.clearLayers();
99 var circle = circle_for_result(result);
100 circle.on('click', function(){
101 highlight_result(position);
103 layerGroup.addLayer(circle);
105 if (result.aBoundingBox){
107 var bounds = [[result.aBoundingBox[0]*1,result.aBoundingBox[2]*1], [result.aBoundingBox[1]*1,result.aBoundingBox[3]*1]];
108 map.fitBounds(bounds);
109 if (result.astext && result.astext.match(/POLY/) ){
110 var layer = omnivore.wkt.parse(result.astext);
111 layerGroup.addLayer(layer);
114 // var layer = L.rectangle(bounds, {color: "#ff7800", weight: 1} );
115 // layerGroup.addLayer(layer);
119 map.panTo([result.lat,result.lon], result.zoom || nominatim_map_init.zoom);
122 // var crosshairIcon = L.icon({
123 // iconUrl: 'images/crosshair.png',
124 // iconSize: [12, 12],
125 // iconAnchor: [6, 6],
127 // var crossMarker = new L.Marker([result.lat,result.lon], { icon: crosshairIcon, clickable: false});
128 // layerGroup.addLayer(crossMarker);
138 $('.result').on('click', function(e){
139 highlight_result($(this).data('position'), true);
142 highlight_result(0, false);
148 jQuery(document).on('ready', function(){
150 if ( !$('#details-page').length ){ return; }
153 map = new L.map('map', {
154 // center: [nominatim_map_init.lat, nominatim_map_init.lon],
155 // zoom: nominatim_map_init.zoom,
156 attributionControl: false,
157 scrollWheelZoom: false,
161 L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
163 // attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
166 var layerGroup = new L.layerGroup().addTo(map);
169 var outline = omnivore.wkt.parse(nominatim_result.outlinestring);
170 map.addLayer(outline);
172 var circle = L.circleMarker([nominatim_result.lat,nominatim_result.lon], { radius: 10, weight: 2, fillColor: '#ff7800', color: 'blue', opacity: 0.75});
173 map.addLayer(circle);
175 map.fitBounds(outline.getBounds());