]> git.openstreetmap.org Git - rails.git/blob - app/views/site/index.html.erb
Merge branch 'master' into openid
[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>
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 <%= javascript_include_tag '/openlayers/OpenLayers.js' %>
115 <%= javascript_include_tag '/openlayers/OpenStreetMap.js' %>
116 <%= javascript_include_tag 'map.js' %>
117
118 <script type="text/javascript" defer="defer">
119   <!--
120   var brokenContentSize = $("content").offsetWidth == 0;
121   var marker;
122   var map;
123
124   OpenLayers.Lang.setCode("<%= I18n.locale.to_s %>");
125
126   function mapInit(){
127     map = createMap("map");
128
129     <% unless STATUS == :api_offline or STATUS == :database_offline %>
130       map.dataLayer = new OpenLayers.Layer("<%= I18n.t 'browse.start_rjs.data_layer_name' %>", { "visibility": false });
131       map.dataLayer.events.register("visibilitychanged", map.dataLayer, toggleData);
132       map.addLayer(map.dataLayer);
133     <% end %>
134
135     <% unless object_zoom %>
136       <% if bbox %>
137         var bbox = new OpenLayers.Bounds(<%= minlon %>, <%= minlat %>, <%= maxlon %>, <%= maxlat %>);
138
139         setMapExtent(bbox);
140
141         <% if box %>
142           // IE requires Vector layers be initialised on page load, and not under deferred script conditions
143           Event.observe(window, 'load', function() { addBoxToMap(bbox) });
144         <% end %>
145       <% else %>
146         var centre = new OpenLayers.LonLat(<%= lon %>, <%= lat %>);
147         var zoom = <%= zoom %>;
148
149         <% if params['scale'] and params['scale'].length > 0 then %>
150           zoom = scaleToZoom(<%= params['scale'].to_f() %>);
151         <% end %>
152
153         setMapCenter(centre, zoom);
154       <% end %>
155
156       updateLocation();
157     <% end %>
158
159     <% if !layers.nil? and !layers.empty? %>
160       setMapLayers("<%= layers %>");
161     <% end %>
162
163     <% if marker %>
164       marker = addMarkerToMap(new OpenLayers.LonLat(<%= mlon %>, <%= mlat %>));
165     <% end %>
166
167     <% if object %>
168       var url = "/api/<%= "#{API_VERSION}" %>/<%= object_type %>/<%= object_id %>";
169
170       <% if object_type != "node" %>
171         url += "/full";
172       <% end %>
173
174       // IE requires Vector layers be initialised on page load, and not under deferred script conditions
175       Event.observe(window, 'load', function() { addObjectToMap(url, <%= object_zoom %>) });
176     <% end %>
177
178     map.events.register("moveend", map, updateLocation);
179     map.events.register("changelayer", map, updateLocation);
180
181     handleResize();
182   }
183
184   function toggleData() {
185     if (map.dataLayer.visibility) {
186       <%= remote_function :url => { :controller => 'browse', :action => 'start' } %>
187     } else if (map.dataLayer.active) {
188       closeSidebar();
189     }
190   }
191
192   function getPosition() {
193     return getMapCenter();
194   }
195
196   function getZoom() {
197     return getMapZoom();
198   }
199
200   function setPosition(lat, lon, zoom, min_lon, min_lat, max_lon, max_lat) {
201     var centre = new OpenLayers.LonLat(lon, lat);
202
203     if (min_lon && min_lat && max_lon && max_lat) {
204       var bbox = new OpenLayers.Bounds(min_lon, min_lat, max_lon, max_lat);
205
206       setMapExtent(bbox);
207     } else {
208       setMapCenter(centre, zoom);
209     }
210
211     if (marker)
212       removeMarkerFromMap(marker);
213
214     marker = addMarkerToMap(centre, getArrowIcon());
215   }
216
217   function updateLocation() {
218     var lonlat = getMapCenter();
219     var zoom = map.getZoom();
220     var layers = getMapLayers();
221     var extents = getMapExtent();
222     var expiry = new Date();
223     var objtype;
224     var objid;
225
226     <% if object %>
227       objtype = "<%= object_type %>";
228       objid = <%= object_id %>;
229     <% end %>
230
231     updatelinks(lonlat.lon, lonlat.lat, zoom, layers, extents.left, extents.bottom, extents.right, extents.top, objtype, objid);
232
233     expiry.setYear(expiry.getFullYear() + 10);
234     document.cookie = "_osm_location=" + lonlat.lon + "|" + lonlat.lat + "|" + zoom + "|" + layers + "; expires=" + expiry.toGMTString();
235   }
236
237   function resizeContent() {
238     var content = $("content");
239     var rightMargin = parseInt(getStyle(content, "right"));
240     var bottomMargin = parseInt(getStyle(content, "bottom"));
241
242     content.style.width = document.documentElement.clientWidth - content.offsetLeft - rightMargin;
243     content.style.height = document.documentElement.clientHeight - content.offsetTop - bottomMargin;
244   }
245
246   function resizeMap() {
247     var centre = map.getCenter();
248     var zoom = map.getZoom();
249     var sidebar_width = $("sidebar").offsetWidth;
250
251     if (sidebar_width > 0) {
252       sidebar_width = sidebar_width + 5
253     }
254
255     $("map").style.left = (sidebar_width) + "px";
256     $("map").style.width = ($("content").offsetWidth - sidebar_width) + "px";
257     $("map").style.height = ($("content").offsetHeight - 2) + "px";
258
259     map.setCenter(centre, zoom);
260   }
261
262   function handleResize() {
263     if (brokenContentSize) {
264       resizeContent();
265     }
266
267     resizeMap();
268   }
269
270   mapInit();
271
272   window.onload = handleResize;
273   window.onresize = handleResize;
274
275   <% if params['action'] == 'export' %>
276   <%= remote_function :url => { :controller => 'export', :action => 'start' } %>
277   <% end %>
278 // -->
279 </script>