]> git.openstreetmap.org Git - rails.git/blob - app/views/site/index.html.erb
Fixed small bug where clicking on the "Report a Problem" link would directly create...
[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 mapInit(){
130     map = createMap("map");
131
132     <% unless OSM_STATUS == :api_offline or OSM_STATUS == :database_offline %>
133       map.dataLayer = new OpenLayers.Layer("<%= I18n.t 'browse.start_rjs.data_layer_name' %>", { "visibility": false });
134       map.dataLayer.events.register("visibilitychanged", map.dataLayer, toggleData);
135       map.addLayer(map.dataLayer);
136
137       map.osbLayer = new OpenLayers.Layer.OpenStreetBugs("OpenStreetBugs", {
138           serverURL : "/api/0.6/bugs/",
139           iconOpen : new OpenLayers.Icon("http://openstreetbugs.schokokeks.org/client/open_bug_marker.png", new OpenLayers.Size(22, 22), new OpenLayers.Pixel(-11, -11)),
140           iconClosed : new OpenLayers.Icon("http://openstreetbugs.schokokeks.org/client/closed_bug_marker.png", new OpenLayers.Size(22, 22), new OpenLayers.Pixel(-11, -11)),
141           readonly : false,
142           setCookie : false,
143           cookieLifetime : 1000, 
144           cookiePath : "/my/map/", 
145           permalinkURL : "http://www.openstreetmap.org/", 
146           theme : "http://osm.cdauth.de/map/openstreetbugs.css" 
147       });
148
149       map.addLayer(map.osbLayer);
150
151       map.osbControl = new OpenLayers.Control.OpenStreetBugs(map.osbLayer); 
152       map.addControl(map.osbControl);
153                 
154           var lBug = document.getElementById('ReportBug');
155       lBug.addEventListener('click',function (e) {
156                 map.osbControl.activate(); document.getElementById("map_OpenLayers_Container").style.cursor = "crosshair"; if (e.stopPropagation) e.stopPropagation(); },false);
157
158
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           // IE requires Vector layers be initialised on page load, and not under deferred script conditions
169           Event.observe(window, 'load', function() { addBoxToMap(bbox) });
170         <% end %>
171       <% else %>
172         var centre = new OpenLayers.LonLat(<%= lon %>, <%= lat %>);
173         var zoom = <%= zoom %>;
174
175         <% if params['scale'] and params['scale'].length > 0 then %>
176           zoom = scaleToZoom(<%= params['scale'].to_f() %>);
177         <% end %>
178
179         setMapCenter(centre, zoom);
180       <% end %>
181
182       updateLocation();
183     <% end %>
184
185     <% if !layers.nil? and !layers.empty? %>
186       setMapLayers("<%= layers %>");
187     <% end %>
188
189     <% if marker %>
190       marker = addMarkerToMap(new OpenLayers.LonLat(<%= mlon %>, <%= mlat %>));
191     <% end %>
192
193     <% if object %>
194       var url = "/api/<%= "#{API_VERSION}" %>/<%= object_type %>/<%= object_id %>";
195
196       <% if object_type != "node" %>
197         url += "/full";
198       <% end %>
199
200       // IE requires Vector layers be initialised on page load, and not under deferred script conditions
201       Event.observe(window, 'load', function() { addObjectToMap(url, <%= object_zoom %>) });
202     <% end %>
203
204     map.events.register("moveend", map, updateLocation);
205     map.events.register("changelayer", map, updateLocation);
206
207     handleResize();
208   }
209
210   function toggleData() {
211     if (map.dataLayer.visibility) {
212       <%= remote_function :url => { :controller => 'browse', :action => 'start' } %>
213     } else if (map.dataLayer.active) {
214       closeSidebar();
215     }
216   }
217
218   function getPosition() {
219     return getMapCenter();
220   }
221
222   function getZoom() {
223     return getMapZoom();
224   }
225
226   function setPosition(lat, lon, zoom, min_lon, min_lat, max_lon, max_lat) {
227     var centre = new OpenLayers.LonLat(lon, lat);
228
229     if (min_lon && min_lat && max_lon && max_lat) {
230       var bbox = new OpenLayers.Bounds(min_lon, min_lat, max_lon, max_lat);
231
232       setMapExtent(bbox);
233     } else {
234       setMapCenter(centre, zoom);
235     }
236
237     if (marker)
238       removeMarkerFromMap(marker);
239
240     marker = addMarkerToMap(centre, getArrowIcon());
241   }
242
243   function updateLocation() {
244     var lonlat = getMapCenter();
245     var zoom = map.getZoom();
246     var layers = getMapLayers();
247     var extents = getMapExtent();
248     var expiry = new Date();
249     var objtype;
250     var objid;
251
252     <% if object %>
253       objtype = "<%= object_type %>";
254       objid = <%= object_id %>;
255     <% end %>
256
257     updatelinks(lonlat.lon, lonlat.lat, zoom, layers, extents.left, extents.bottom, extents.right, extents.top, objtype, objid);
258
259     expiry.setYear(expiry.getFullYear() + 10); 
260     document.cookie = "_osm_location=" + lonlat.lon + "|" + lonlat.lat + "|" + zoom + "|" + layers + "; expires=" + expiry.toGMTString();
261   }
262
263   function resizeContent() {
264     var content = $("content");
265     var rightMargin = parseInt(getStyle(content, "right"));
266     var bottomMargin = parseInt(getStyle(content, "bottom"));
267
268     content.style.width = document.documentElement.clientWidth - content.offsetLeft - rightMargin;
269     content.style.height = document.documentElement.clientHeight - content.offsetTop - bottomMargin;
270   }
271   
272   function resizeMap() {
273     var centre = map.getCenter();
274     var zoom = map.getZoom();
275     var sidebar_width = $("sidebar").offsetWidth;
276
277     if (sidebar_width > 0) {
278       sidebar_width = sidebar_width + 5
279     }
280
281     $("map").style.left = (sidebar_width) + "px";
282     $("map").style.width = ($("content").offsetWidth - sidebar_width) + "px";
283     $("map").style.height = ($("content").offsetHeight - 2) + "px";
284
285     map.setCenter(centre, zoom);
286   }
287
288   function handleResize() {
289     if (brokenContentSize) {
290       resizeContent();
291     }
292
293     resizeMap();
294   }
295   
296   mapInit();
297
298   window.onload = handleResize;
299   window.onresize = handleResize;
300
301   <% if params['action'] == 'export' %>
302   <%= remote_function :url => { :controller => 'export', :action => 'start' } %>
303   <% end %>
304 // -->
305 </script>