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