]> 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}, 10)", { :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"><%= t 'site.index.permalink' %></a><br/>
22     <a href="/" id="shortlinkanchor"><%= t 'site.index.shortlink' %></a><br/>
23         <a id="ReportBug">Report a problem</a>  
24   </div>
25 </div> 
26
27 <div id="attribution">
28   <table width="100%">
29     <tr>
30       <td align="left"><%= t'site.index.license.license_url' %></td>
31       <td align="right"><%= t'site.index.license.project_url' %></td>
32     </tr>
33     <tr>
34       <td colspan="2" align="center"><%=
35         t'site.index.license.notice',
36           :license_name => t('site.index.license.license_name'),
37           :project_name => t('site.index.license.project_name')
38         %></td>
39     </tr>
40   </table>
41 </div>
42
43 <%
44 if params['mlon'] and params['mlat'] 
45     marker = true
46     mlon = h(params['mlon'])
47     mlat = h(params['mlat'])
48 end
49
50 if params['node'] or params['way'] or params['relation']
51     object = true
52     object_zoom = true
53
54     if params['node']
55         object_type = 'node'
56         object_id = h(params['node'])
57     elsif params['way']
58         object_type = 'way'
59         object_id = h(params['way'])
60     elsif params['relation']
61         object_type = 'relation'
62         object_id = h(params['relation'])
63     end
64 end
65
66 if params['minlon'] and params['minlat'] and params['maxlon'] and params['maxlat']
67     bbox = true
68     minlon = h(params['minlon'])
69     minlat = h(params['minlat'])
70     maxlon = h(params['maxlon'])
71     maxlat = h(params['maxlat'])
72     box = true if params['box']=="yes" 
73     object_zoom = false
74 end
75
76 # Decide on a lat lon to initialise the map with. Various ways of doing this
77 if params['lon'] and params['lat']
78     lon =  h(params['lon'])
79     lat =  h(params['lat'])
80     zoom =  h(params['zoom'] || '5')
81     layers = h(params['layers'])
82     object_zoom = false
83 elsif params['mlon'] and params['mlat']
84     lon = h(params['mlon']) 
85     lat = h(params['mlat'])
86     zoom =  h(params['zoom'] || '12')
87     layers = h(params['layers'])
88     object_zoom = false
89 elsif cookies.key?("_osm_location")
90     lon,lat,zoom,layers = cookies["_osm_location"].split("|")
91 elsif @user and !@user.home_lon.nil? and !@user.home_lat.nil? 
92     lon =  @user.home_lon
93     lat =  @user.home_lat
94     zoom = '10'
95 else
96     session[:location] = OSM::IPLocation(request.env['REMOTE_ADDR']) unless session[:location]
97
98     if session[:location]
99         bbox = true
100         minlon = session[:location][:minlon]
101         minlat = session[:location][:minlat]
102         maxlon = session[:location][:maxlon]
103         maxlat = session[:location][:maxlat]
104     else
105         lon =  '-0.1' 
106         lat =  '51.5' 
107         zoom =  h(params['zoom'] || '5') 
108     end
109
110     layers = h(params['layers']) 
111 end
112 %>
113
114 <!--Use stock OpenLayers for now, as the OSM one is missing some needed classes-->
115 <script src="http://www.openlayers.org/api/OpenLayers.js"></script>
116 <!-- < %= javascript_include_tag '/openlayers/OpenLayers.js' % > -->
117 <%= javascript_include_tag '/openlayers/OpenStreetMap.js' %>
118 <%= javascript_include_tag 'openstreetbugs.js' %>
119 <%= javascript_include_tag 'map.js' %>
120
121 <script type="text/javascript" defer="defer">
122   <!--
123   var brokenContentSize = $("content").offsetWidth == 0;
124   var marker;
125   var map;
126
127   OpenLayers.Lang.setCode("<%= I18n.locale.to_s %>");
128
129   function createBugCallBack() {
130         map.osbControl.deactivate();
131         document.getElementById("map_OpenLayers_Container").style.cursor = "default";
132   }
133
134   function mapInit(){
135     map = createMap("map");
136
137     <% unless OSM_STATUS == :api_offline or OSM_STATUS == :database_offline %>
138       map.dataLayer = new OpenLayers.Layer("<%= I18n.t 'browse.start_rjs.data_layer_name' %>", { "visibility": false });
139       map.dataLayer.events.register("visibilitychanged", map.dataLayer, toggleData);
140       map.addLayer(map.dataLayer);
141
142       map.osbLayer = new OpenLayers.Layer.OpenStreetBugs("OpenStreetBugs", {
143           serverURL : "/api/0.6/",
144           iconOpen : new OpenLayers.Icon("http://openstreetbugs.schokokeks.org/client/open_bug_marker.png", new OpenLayers.Size(22, 22), new OpenLayers.Pixel(-11, -11)),
145           iconClosed : new OpenLayers.Icon("http://openstreetbugs.schokokeks.org/client/closed_bug_marker.png", new OpenLayers.Size(22, 22), new OpenLayers.Pixel(-11, -11)),
146           readonly : false,
147           setCookie : false,
148           cookieLifetime : 1000, 
149           cookiePath : "/my/map/", 
150           permalinkURL : "http://www.openstreetmap.org/", 
151           theme : "http://osm.cdauth.de/map/openstreetbugs.css" 
152       });
153
154       map.addLayer(map.osbLayer);
155
156       map.osbControl = new OpenLayers.Control.OpenStreetBugs(map.osbLayer); 
157       map.addControl(map.osbControl);
158                 
159           var lBug = document.getElementById('ReportBug');
160       lBug.addEventListener('click',function (e) {
161                 map.osbControl.activate(); document.getElementById("map_OpenLayers_Container").style.cursor = "crosshair"; if (e.stopPropagation) e.stopPropagation(); },false);
162
163
164     <% end %>
165
166     <% unless object_zoom %>
167       <% if bbox %>
168         var bbox = new OpenLayers.Bounds(<%= minlon %>, <%= minlat %>, <%= maxlon %>, <%= maxlat %>);
169
170         setMapExtent(bbox);
171
172         <% if box %>
173           // IE requires Vector layers be initialised on page load, and not under deferred script conditions
174           Event.observe(window, 'load', function() { addBoxToMap(bbox) });
175         <% end %>
176       <% else %>
177         var centre = new OpenLayers.LonLat(<%= lon %>, <%= lat %>);
178         var zoom = <%= zoom %>;
179
180         <% if params['scale'] and params['scale'].length > 0 then %>
181           zoom = scaleToZoom(<%= params['scale'].to_f() %>);
182         <% end %>
183
184         setMapCenter(centre, zoom);
185       <% end %>
186
187       updateLocation();
188     <% end %>
189
190     <% if !layers.nil? and !layers.empty? %>
191       setMapLayers("<%= layers %>");
192     <% end %>
193
194     <% if marker %>
195       marker = addMarkerToMap(new OpenLayers.LonLat(<%= mlon %>, <%= mlat %>));
196     <% end %>
197
198     <% if object %>
199       var url = "/api/<%= "#{API_VERSION}" %>/<%= object_type %>/<%= object_id %>";
200
201       <% if object_type != "node" %>
202         url += "/full";
203       <% end %>
204
205       // IE requires Vector layers be initialised on page load, and not under deferred script conditions
206       Event.observe(window, 'load', function() { addObjectToMap(url, <%= object_zoom %>) });
207     <% end %>
208
209     map.events.register("moveend", map, updateLocation);
210     map.events.register("changelayer", map, updateLocation);
211
212     handleResize();
213   }
214
215   function toggleData() {
216     if (map.dataLayer.visibility) {
217       <%= remote_function :url => { :controller => 'browse', :action => 'start' } %>
218     } else if (map.dataLayer.active) {
219       closeSidebar();
220     }
221   }
222
223   function getPosition() {
224     return getMapCenter();
225   }
226
227   function getZoom() {
228     return getMapZoom();
229   }
230
231   function setPosition(lat, lon, zoom, min_lon, min_lat, max_lon, max_lat) {
232     var centre = new OpenLayers.LonLat(lon, lat);
233
234     if (min_lon && min_lat && max_lon && max_lat) {
235       var bbox = new OpenLayers.Bounds(min_lon, min_lat, max_lon, max_lat);
236
237       setMapExtent(bbox);
238     } else {
239       setMapCenter(centre, zoom);
240     }
241
242     if (marker)
243       removeMarkerFromMap(marker);
244
245     marker = addMarkerToMap(centre, getArrowIcon());
246   }
247
248   function updateLocation() {
249     var lonlat = getMapCenter();
250     var zoom = map.getZoom();
251     var layers = getMapLayers();
252     var extents = getMapExtent();
253     var expiry = new Date();
254     var objtype;
255     var objid;
256
257     <% if object %>
258       objtype = "<%= object_type %>";
259       objid = <%= object_id %>;
260     <% end %>
261
262     updatelinks(lonlat.lon, lonlat.lat, zoom, layers, extents.left, extents.bottom, extents.right, extents.top, objtype, objid);
263
264     expiry.setYear(expiry.getFullYear() + 10); 
265     document.cookie = "_osm_location=" + lonlat.lon + "|" + lonlat.lat + "|" + zoom + "|" + layers + "; expires=" + expiry.toGMTString();
266   }
267
268   function resizeContent() {
269     var content = $("content");
270     var rightMargin = parseInt(getStyle(content, "right"));
271     var bottomMargin = parseInt(getStyle(content, "bottom"));
272
273     content.style.width = document.documentElement.clientWidth - content.offsetLeft - rightMargin;
274     content.style.height = document.documentElement.clientHeight - content.offsetTop - bottomMargin;
275   }
276   
277   function resizeMap() {
278     var centre = map.getCenter();
279     var zoom = map.getZoom();
280     var sidebar_width = $("sidebar").offsetWidth;
281
282     if (sidebar_width > 0) {
283       sidebar_width = sidebar_width + 5
284     }
285
286     $("map").style.left = (sidebar_width) + "px";
287     $("map").style.width = ($("content").offsetWidth - sidebar_width) + "px";
288     $("map").style.height = ($("content").offsetHeight - 2) + "px";
289
290     map.setCenter(centre, zoom);
291   }
292
293   function handleResize() {
294     if (brokenContentSize) {
295       resizeContent();
296     }
297
298     resizeMap();
299   }
300   
301   mapInit();
302
303   window.onload = handleResize;
304   window.onresize = handleResize;
305
306   <% if params['action'] == 'export' %>
307   <%= remote_function :url => { :controller => 'export', :action => 'start' } %>
308   <% end %>
309 // -->
310 </script>