4 jQuery(document).on('ready', function(){
7 map = new L.map('map', {
8 center: [nominatim_map_init.lat, nominatim_map_init.lon],
9 zoom: nominatim_map_init.zoom,
10 attributionControl: false,
11 scrollWheelZoom: false,
15 L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
16 // attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
21 function display_map_position(mouse_lat_lng){
23 html_mouse = "mouse position " + (mouse_lat_lng ? [mouse_lat_lng.lat.toFixed(5), mouse_lat_lng.lng.toFixed(5)].join(',') : '-');
24 html_click = "last click: " + (last_click_latlng ? [last_click_latlng.lat.toFixed(5),last_click_latlng.lng.toFixed(5)].join(',') : '-');
28 map.getCenter().lat.toFixed(5) + ',' + map.getCenter().lng.toFixed(5) +
29 " <a target='_blank' href='" + map_link_to_osm() + "'>view on osm.org</a>";
31 html_viewbox = "viewbox: " + map_viewbox_as_string();
33 $('#map-position').html([html_center,html_viewbox,html_click,html_mouse].join('<br/>'));
34 $('input#use_viewbox').trigger('change');
37 map.on('move', function(e) {
38 display_map_position();
41 map.on('mousemove', function(e) {
42 display_map_position(e.latlng);
45 map.on('click', function(e) {
46 last_click_latlng = e.latlng;
47 display_map_position();
50 map.on('load', function(e){
51 display_map_position();
55 $('input#use_viewbox').on('change', function(){
56 $('input[name=viewbox]').val( $(this).prop('checked') ? map_viewbox_as_string() : '');
61 function map_viewbox_as_string() {
62 // since .toBBoxString() doesn't round numbers
64 map.getBounds().getSouthWest().lat.toFixed(5),
65 map.getBounds().getSouthWest().lng.toFixed(5),
66 map.getBounds().getNorthEast().lat.toFixed(5),
67 map.getBounds().getNorthEast().lng.toFixed(5) ].join(',');
69 function map_link_to_osm(){
70 return "http://openstreetmap.org/#map=" + map.getZoom() + "/" + map.getCenter().lat + "/" + map.getCenter().lng;
73 function get_result_element(position){
74 return $('.result').eq(position);
76 function marker_for_result(result){
77 return L.marker([result.lat,result.lon], {riseOnHover:true,title:result.name });
79 function circle_for_result(result){
80 return L.circleMarker([result.lat,result.lon], { radius: 50, weight: 1, fillColor: '#F0F7FF', color: 'red', opacity: 0.75});
83 var layerGroup = new L.layerGroup().addTo(map);
84 function highlight_result(position, bool_focus){
85 var result = nominatim_results[position];
86 if (!result){ return }
87 var result_el = get_result_element(position);
89 $('.result').removeClass('highlight');
90 result_el.addClass('highlight');
92 layerGroup.clearLayers();
94 if (result.aBoundingBox){
96 console.log('bounding box, maybe polygon', result);
97 var bounds = [[result.aBoundingBox[0]*1,result.aBoundingBox[2]*1], [result.aBoundingBox[1]*1,result.aBoundingBox[3]*1]];
98 map.fitBounds(bounds);
99 if (result.astext && result.astext.match(/POLY/) ){
100 var layer = omnivore.wkt.parse(result.astext);
101 layerGroup.addLayer(layer);
103 // addedLayers.push(layer);
106 var layer = L.rectangle(bounds, {color: "#ff7800", weight: 1} );
107 layerGroup.addLayer(layer);
111 // console.log('lat,lon,zoom');
112 map.panTo([result.lat,result.lon], result.zoom || nominatim_map_init.zoom);
113 var circle = circle_for_result(result);
114 circle.on('click', function(){
117 layerGroup.addLayer(layer);
119 // circle.addTo(map);
122 var crosshairIcon = L.icon({
123 iconUrl: 'images/crosshair.png',
127 var crossMarker = new L.Marker([result.lat,result.lon], { icon: crosshairIcon, clickable: false});
128 layerGroup.addLayer(crossMarker);
130 // crossMarker.addTo(map);
131 // addedLayers.push(crossMarker);
139 $.each(nominatim_results, function(i, result){
144 $('.result').on('click', function(e){
145 highlight_result($(this).data('position'), true);
148 highlight_result(0, false);