]> git.openstreetmap.org Git - rails.git/blob - app/views/site/index.html.erb
Merge branch 'master' into openstreetbugs
[rails.git] / app / views / site / index.html.erb
1 <% content_for :greeting do %>
2 <% if @user and !@user.home_lon.nil? and !@user.home_lat.nil? %>
3   <%= link_to_function t('layouts.home'), "setPosition(#{@user.home_lat}, #{@user.home_lon}, 15)", { :title => t('layouts.home_tooltip') } %> |
4 <% end %>
5 <% end %>
6
7 <%= render :partial => 'sidebar', :locals => { :onopen => "resizeMap();", :onclose => "resizeMap();" } %>
8 <%= render :partial => 'key' %>
9 <%= render :partial => 'search' %>
10
11 <noscript>
12   <div id="noscript">
13     <p><%= t 'site.index.js_1' %></p>
14     <p><%= t 'site.index.js_2' %></p>
15     <p><%= t 'site.index.js_3' %></p>
16   </div>
17 </noscript>
18
19 <div id="map">
20   <div id="permalink">
21     <a href="/" id="permalinkanchor" class="geolink llz layers object"><%= t 'site.index.permalink' %></a><br/>
22     <a href="/" id="shortlinkanchor"><%= t 'site.index.shortlink' %></a>
23     <a href="#" id="createnoteanchor">Report a problem</a>      
24   </div>
25 </div>
26
27 <iframe id="linkloader" style="display: none">
28 </iframe>
29
30 <div id="attribution">
31   <table width="100%">
32     <tr>
33       <td class="attribution_license"><%= t'site.index.license.license_url' %></td>
34       <td class="attribution_project"><%= t'site.index.license.project_url' %></td>
35     </tr>
36     <tr>
37       <td colspan="2" class="attribution_notice"><%=
38         t'site.index.license.notice',
39           :license_name => t('site.index.license.license_name'),
40           :project_name => t('site.index.license.project_name')
41         %></td>
42     </tr>
43   </table>
44 </div>
45
46 <%
47 if params['mlon'] and params['mlat']
48     marker = true
49     mlon = h(params['mlon'])
50     mlat = h(params['mlat'])
51 end
52
53 if params['node'] or params['way'] or params['relation']
54     object = true
55     object_zoom = true
56
57     if params['node']
58         object_type = 'node'
59         object_id = h(params['node'])
60     elsif params['way']
61         object_type = 'way'
62         object_id = h(params['way'])
63     elsif params['relation']
64         object_type = 'relation'
65         object_id = h(params['relation'])
66     end
67 end
68
69 # Decide on a lat lon to initialise the map with. Various ways of doing this
70 if params['bbox']
71     bbox = true
72     minlon, minlat, maxlon, maxlat = h(params['bbox']).split(",")
73     layers = h(params['layers'])
74     box = true if params['box']=="yes"
75     object_zoom = false
76 elsif params['minlon'] and params['minlat'] and params['maxlon'] and params['maxlat']
77     bbox = true
78     minlon = h(params['minlon'])
79     minlat = h(params['minlat'])
80     maxlon = h(params['maxlon'])
81     maxlat = h(params['maxlat'])
82     layers = h(params['layers'])
83     box = true if params['box']=="yes"
84     object_zoom = false
85 elsif params['lon'] and params['lat']
86     lon =  h(params['lon'])
87     lat =  h(params['lat'])
88     zoom =  h(params['zoom'] || '5')
89     layers = h(params['layers'])
90     object_zoom = false
91 elsif params['mlon'] and params['mlat']
92     lon = h(params['mlon'])
93     lat = h(params['mlat'])
94     zoom =  h(params['zoom'] || '12')
95     layers = h(params['layers'])
96     object_zoom = false
97 elsif cookies.key?("_osm_location")
98     lon,lat,zoom,layers = cookies["_osm_location"].split("|")
99 elsif @user and !@user.home_lon.nil? and !@user.home_lat.nil?
100     lon =  @user.home_lon
101     lat =  @user.home_lat
102     zoom = '10'
103 else
104     unless STATUS == :database_readonly or STATUS == :database_offline
105       session[:location] = OSM::IPLocation(request.env['REMOTE_ADDR']) unless session[:location]
106     end
107
108     if session[:location]
109         bbox = true
110         minlon = session[:location][:minlon]
111         minlat = session[:location][:minlat]
112         maxlon = session[:location][:maxlon]
113         maxlat = session[:location][:maxlat]
114     else
115         lon =  '-0.1'
116         lat =  '51.5'
117         zoom =  h(params['zoom'] || '5')
118     end
119
120     layers = h(params['layers'])
121 end
122 %>
123
124 <%= javascript_include_tag '/openlayers/OpenLayers.js' %>
125 <%= javascript_include_tag '/openlayers/OpenStreetMap.js' %>
126 <%= javascript_include_tag 'notes.js' %>
127 <%= javascript_include_tag 'map.js' %>
128
129 <%= render :partial => 'resize' %>
130
131 <script type="text/javascript">
132   var marker;
133   var map;
134
135   OpenLayers.Lang.setCode("<%= I18n.locale.to_s %>");
136
137   <% if @user %>
138     var loginName = "<%= @user.display_name %>"
139   <% end %>
140
141   function mapInit(){
142     map = createMap("map");
143
144     <% unless STATUS == :api_offline or STATUS == :database_offline %>
145       map.dataLayer = new OpenLayers.Layer("<%= I18n.t 'browse.start_rjs.data_layer_name' %>", { "visibility": false });
146       map.dataLayer.events.register("visibilitychanged", map.dataLayer, toggleData);
147       map.addLayer(map.dataLayer);
148
149       map.noteLayer = new OpenLayers.Layer.Notes("Notes", {
150           setCookie: false,
151           permalinkURL: "http://www.openstreetmap.org/",
152           visibility: <%= params[:notes] == "yes" %>
153       });
154       map.addLayer(map.noteLayer);
155
156       $("createnoteanchor").observe("click", addNote);
157
158       map.events.register("zoomend", map, allowNoteReports);
159     <% end %>
160
161     <% unless object_zoom %>
162       <% if bbox %>
163         var bbox = new OpenLayers.Bounds(<%= minlon %>, <%= minlat %>, <%= maxlon %>, <%= maxlat %>);
164
165         setMapExtent(bbox);
166
167         <% if box %>
168           Event.observe(window, "load", function() { addBoxToMap(bbox) });
169         <% end %>
170       <% else %>
171         var centre = new OpenLayers.LonLat(<%= lon %>, <%= lat %>);
172         var zoom = <%= zoom %>;
173
174         <% if params['scale'] and params['scale'].length > 0 then %>
175           zoom = scaleToZoom(<%= params['scale'].to_f() %>);
176         <% end %>
177
178         setMapCenter(centre, zoom);
179       <% end %>
180
181       updateLocation();
182     <% end %>
183
184     <% if !layers.nil? and !layers.empty? %>
185       setMapLayers("<%= layers %>");
186     <% end %>
187
188     <% if marker %>
189       marker = addMarkerToMap(new OpenLayers.LonLat(<%= mlon %>, <%= mlat %>));
190     <% end %>
191
192     <% if object %>
193       var url = "/api/<%= "#{API_VERSION}" %>/<%= object_type %>/<%= object_id %>";
194
195       <% if object_type != "node" %>
196         url += "/full";
197       <% end %>
198
199       Event.observe(window, "load", function() { addObjectToMap(url, <%= object_zoom %>) });
200     <% end %>
201
202     map.events.register("moveend", map, updateLocation);
203     map.events.register("changelayer", map, updateLocation);
204
205     handleResize();
206   }
207
208   function toggleData() {
209     if (map.dataLayer.visibility) {
210       <%= remote_function :url => { :controller => 'browse', :action => 'start' } %>
211     } else if (map.dataLayer.active) {
212       closeSidebar();
213     }
214   }
215
216   function getPosition() {
217     return getMapCenter();
218   }
219
220   function getZoom() {
221     return getMapZoom();
222   }
223
224   function setPosition(lat, lon, zoom, min_lon, min_lat, max_lon, max_lat) {
225     var centre = new OpenLayers.LonLat(lon, lat);
226
227     if (min_lon && min_lat && max_lon && max_lat) {
228       var bbox = new OpenLayers.Bounds(min_lon, min_lat, max_lon, max_lat);
229
230       setMapExtent(bbox);
231     } else {
232       setMapCenter(centre, zoom);
233     }
234
235     if (marker)
236       removeMarkerFromMap(marker);
237
238     marker = addMarkerToMap(centre, getArrowIcon());
239   }
240
241   function updateLocation() {
242     var lonlat = getMapCenter();
243     var zoom = map.getZoom();
244     var layers = getMapLayers();
245     var extents = getMapExtent();
246     var expiry = new Date();
247     var objtype;
248     var objid;
249
250     <% if object %>
251       objtype = "<%= object_type %>";
252       objid = <%= object_id %>;
253     <% end %>
254
255     updatelinks(lonlat.lon, lonlat.lat, zoom, layers, extents.left, extents.bottom, extents.right, extents.top, objtype, objid);
256
257     expiry.setYear(expiry.getFullYear() + 10);
258     document.cookie = "_osm_location=" + lonlat.lon + "|" + lonlat.lat + "|" + zoom + "|" + layers + "; expires=" + expiry.toGMTString();
259   }
260
261   function remoteEditHandler(event) {
262     var extent = getMapExtent();
263     var loaded = false;
264
265     $("linkloader").observe("load", function () { loaded = true; });
266     $("linkloader").src = "http://127.0.0.1:8111/load_and_zoom?left=" + extent.left + "&top=" + extent.top + "&right=" + extent.right + "&bottom=" + extent.bottom;
267
268     setTimeout(function () {
269       if (!loaded) alert("<%= escape_javascript(t('site.index.remote_failed')) %>");
270     }, 1000);
271
272     event.stop();
273   }
274
275   function installEditHandler() {
276     $("remoteanchor").observe("click", remoteEditHandler);
277
278     <% if preferred_editor == "remote" %>
279       $("editanchor").observe("click", remoteEditHandler);
280
281       <% if params[:action] == "edit" %>
282         remoteEditHandler();
283       <% end %>
284     <% end %>
285   }
286
287   function addNote() {
288     map.noteLayer.setVisibility(true);
289     map.noteLayer.addNote(map.getCenter());
290   }
291
292   function allowNoteReports() { 
293     if (map.getZoom() > 11) {
294       $("createnoteanchor").style.visibility = "visible";
295     } else {
296       $("createnoteanchor").style.visibility = "hidden";
297     }
298   }
299
300   document.observe("dom:loaded", mapInit);
301   document.observe("dom:loaded", installEditHandler);
302   document.observe("dom:loaded", handleResize);
303
304   Event.observe(window, "resize", function() {
305     var centre = map.getCenter();
306     var zoom = map.getZoom();
307
308     handleResize();
309
310     map.setCenter(centre, zoom);
311   });
312
313   <% if params['action'] == 'export' %>
314   <%= remote_function :url => { :controller => 'export', :action => 'start' } %>
315   <% end %>
316 </script>