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