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