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