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