]> git.openstreetmap.org Git - nominatim.git/blob - website/js/nominatim-ui.js
user interface: less spacing in table, pushing more content above the fold
[nominatim.git] / website / js / nominatim-ui.js
1 var map;
2 var last_click_latlng;
3
4 jQuery(document).on('ready', function(){
5
6         if ( !$('#search-page,#reverse-page').length ){ return; }
7         
8         var is_reverse_search = !!( $('#reverse-page').length );
9
10         $('#q').focus();
11
12         map = new L.map('map', {
13                                 // center: [nominatim_map_init.lat || 0, nominatim_map_init.lon],
14                                 // zoom:   nominatim_map_init.zoom,
15                                 attributionControl: false,
16                                 scrollWheelZoom:    false,
17                                 touchZoom:          false,
18                         });
19
20
21
22         L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
23                 noWrap: true // otherwise we end up with click coordinates like latitude -728
24                 // moved to footer
25                 // attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
26         }).addTo(map);
27
28         if ( nominatim_map_init.lat ){
29                 map.setView([nominatim_map_init.lat || 0, nominatim_map_init.lon], nominatim_map_init.zoom);
30
31                 if ( is_reverse_search ){
32                         // not really a market, but the .circle changes radius once you zoom in/out
33                         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});
34                         cm.addTo(map);
35                 }
36         } else {
37                 map.setView([0,0],2);
38         }
39
40
41
42         function display_map_position(mouse_lat_lng){
43
44                 html_mouse = "mouse position " + (mouse_lat_lng ? [mouse_lat_lng.lat.toFixed(5), mouse_lat_lng.lng.toFixed(5)].join(',') : '-');
45                 html_click = "last click: " + (last_click_latlng ? [last_click_latlng.lat.toFixed(5),last_click_latlng.lng.toFixed(5)].join(',') : '-');
46
47                 html_center = 
48                         "map center: " + 
49                         map.getCenter().lat.toFixed(5) + ',' + map.getCenter().lng.toFixed(5) +
50                         " <a target='_blank' href='" + map_link_to_osm() + "'>view on osm.org</a>";
51
52                 html_viewbox = "viewbox: " + map_viewbox_as_string();
53
54                 $('#map-position').html([html_center,html_viewbox,html_click,html_mouse].join('<br/>'));
55                 $('input#use_viewbox').trigger('change');
56         }
57
58         map.on('move', function(e) {
59                 display_map_position();
60         });
61
62         map.on('mousemove', function(e) {
63                 display_map_position(e.latlng);
64         });
65
66         map.on('click', function(e) {
67                 last_click_latlng = e.latlng;
68                 display_map_position();
69         });
70
71         map.on('load', function(e){
72                 display_map_position();
73         });
74
75
76         $('input#use_viewbox').on('change', function(){
77                 $('input[name=viewbox]').val( $(this).prop('checked') ? map_viewbox_as_string() : '');
78         });
79
80
81
82         function map_viewbox_as_string() {
83                 // since .toBBoxString() doesn't round numbers
84                 return [
85                         map.getBounds().getSouthWest().lat.toFixed(5),
86                         map.getBounds().getSouthWest().lng.toFixed(5),
87                         map.getBounds().getNorthEast().lat.toFixed(5),
88                         map.getBounds().getNorthEast().lng.toFixed(5) ].join(',');
89         }
90         function map_link_to_osm(){
91                 return "http://openstreetmap.org/#map=" + map.getZoom() + "/" + map.getCenter().lat + "/" + map.getCenter().lng;
92         }
93
94         function get_result_element(position){
95                 return $('.result').eq(position);
96         }
97         function marker_for_result(result){
98                 return L.marker([result.lat,result.lon], {riseOnHover:true,title:result.name });
99         }
100         function circle_for_result(result){
101                 return L.circleMarker([result.lat,result.lon], { radius: 10, weight: 2, fillColor: '#ff7800', color: 'blue', opacity: 0.75, clickable: !is_reverse_search});
102         }
103
104         var layerGroup = new L.layerGroup().addTo(map);
105         function highlight_result(position, bool_focus){
106                 var result = nominatim_results[position];
107                 if (!result){ return }
108                 var result_el = get_result_element(position);
109
110                 $('.result').removeClass('highlight');
111                 result_el.addClass('highlight');
112
113                 layerGroup.clearLayers();
114
115                 if (result.lat){
116                         var circle = circle_for_result(result);
117                         circle.on('click', function(){
118                                 highlight_result(position);
119                         });
120                         layerGroup.addLayer(circle);                    
121                 }
122                 if (result.aBoundingBox){
123
124                         var bounds = [[result.aBoundingBox[0]*1,result.aBoundingBox[2]*1], [result.aBoundingBox[1]*1,result.aBoundingBox[3]*1]];
125                         map.fitBounds(bounds);
126                         if (result.astext && result.astext.match(/POLY/) ){
127                                 var layer = omnivore.wkt.parse(result.astext);
128                                 layerGroup.addLayer(layer);
129                         }
130                         else {
131                                 // var layer = L.rectangle(bounds, {color: "#ff7800", weight: 1} );
132                                 // layerGroup.addLayer(layer);
133                         }
134                 }
135                 else {
136                         if ( is_reverse_search ){
137                                 // make sure the search coordinates are in the map view as well
138                                 map.fitBounds([[result.lat,result.lon], [nominatim_map_init.lat,nominatim_map_init.lon]], {padding: [50,50]});
139
140                                 // better, but causes a leaflet warning
141                                 // map.panInsideBounds([[result.lat,result.lon], [nominatim_map_init.lat,nominatim_map_init.lon]], {animate: false});
142                         }
143                         else {
144                                 map.panTo([result.lat,result.lon], result.zoom || nominatim_map_init.zoom);
145                         }
146                 }
147
148                 // var crosshairIcon = L.icon({
149                 //      iconUrl:     'images/crosshair.png',
150                 //      iconSize:    [12, 12],
151                 //      iconAnchor:  [6, 6],
152                 // });
153                 // var crossMarker = new L.Marker([result.lat,result.lon], { icon: crosshairIcon, clickable: false});
154                 // layerGroup.addLayer(crossMarker);
155
156
157
158                 if (bool_focus){
159                         $('#map').focus();
160                 }
161         }
162
163
164         $('.result').on('click', function(e){
165                 highlight_result($(this).data('position'), true);
166         });
167
168         if ( is_reverse_search ){
169                 map.on('click', function(e){
170                         $('form input[name=lat]').val( e.latlng.lat);
171                         $('form input[name=lon]').val( e.latlng.lng);
172                         $('form').submit();
173                 });
174         }
175
176         highlight_result(0, false);
177
178
179 });
180
181
182 jQuery(document).on('ready', function(){
183
184         if ( !$('#details-page').length ){ return; }
185
186
187                 map = new L.map('map', {
188                                         // center: [nominatim_map_init.lat, nominatim_map_init.lon],
189                                         // zoom:   nominatim_map_init.zoom,
190                                         attributionControl: false,
191                                         scrollWheelZoom:    false,
192                                         touchZoom:          false,
193                                 });
194
195                 L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
196                         // moved to footer
197                         // attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
198                 }).addTo(map);
199
200                 var layerGroup = new L.layerGroup().addTo(map);
201
202                 var circle = L.circleMarker([nominatim_result.lat,nominatim_result.lon], { radius: 10, weight: 2, fillColor: '#ff7800', color: 'blue', opacity: 0.75});
203                 map.addLayer(circle);
204
205                 if ( nominatim_result.outlinestring ){
206                         var outline = omnivore.wkt.parse(nominatim_result.outlinestring);
207                         map.addLayer(outline);
208                         map.fitBounds(outline.getBounds());
209                 } else {
210                         map.setView([nominatim_result.lat,nominatim_result.lon],10);
211                 }
212
213
214
215 });
216