]> git.openstreetmap.org Git - rails.git/blob - app/views/site/index.html.erb
Change the feature commited in [16174] to use the main map view
[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 if params['node'] or params['way'] or params['relation']
59     object = true
60     if params['node']
61         object_type = 'node'
62         object_id = h(params['node'])
63     elsif params['way']
64         object_type = 'way'
65         object_id = h(params['way'])
66     elsif params['relation']
67         object_type = 'relation'
68         object_id = h(params['relation'])
69     end
70 end
71
72 # Decide on a lat lon to initialise the map with. Various ways of doing this
73 if params['lon'] and params['lat']
74         # We only want to override the default 'object = true' zoom above
75         # if we get actual GET params, as opposed to say a cookie
76         lat_lon_zoom_via_params = true
77
78         lon =  h(params['lon'])
79         lat =  h(params['lat'])
80         zoom =  h(params['zoom'] || '5')
81         layers = h(params['layers'])
82         
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         
89 elsif cookies.key?("_osm_location")
90         lon,lat,zoom,layers = cookies["_osm_location"].split("|")
91         
92 elsif @user and !@user.home_lon.nil? and !@user.home_lat.nil? 
93         lon =  @user.home_lon
94         lat =  @user.home_lat
95         zoom = '10'
96 else
97         session[:location] = OSM::IPLocation(request.env['REMOTE_ADDR']) unless session[:location]
98
99         if session[:location]
100                 bbox = true
101                 minlon = session[:location][:minlon]
102                 minlat = session[:location][:minlat]
103                 maxlon = session[:location][:maxlon]
104                 maxlat = session[:location][:maxlat]
105         else
106                 lon =  '-0.1' 
107                 lat =  '51.5' 
108                 zoom =  h(params['zoom'] || '5') 
109         end
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
119 <script type="text/javascript" defer="defer">
120   <!--
121   var brokenContentSize = $("content").offsetWidth == 0;
122   var marker;
123   var map;
124   var obj_type = false;
125   var obj_id = false;
126
127   OpenLayers.Lang.setCode("<%= I18n.locale.to_s %>");
128
129   function mapInit(){
130     map = createMap("map");
131
132     <% unless OSM_STATUS == :api_offline or OSM_STATUS == :database_offline %>
133     map.dataLayer = new OpenLayers.Layer("<%= I18n.t 'browse.start_rjs.data_layer_name' %>", { "visibility": false });
134     map.dataLayer.events.register("visibilitychanged", map.dataLayer, toggleData);
135     map.addLayer(map.dataLayer);
136     <% end %>
137
138     <% if bbox %>
139     var bbox = new OpenLayers.Bounds(<%= minlon %>, <%= minlat %>, <%= maxlon %>, <%= maxlat %>);
140
141     setMapExtent(bbox);
142     <%    if box %>
143     // IE requires Vector layers be initialised on page load, and not under deferred script conditions
144     Event.observe(window, 'load', function() {addBoxToMap(bbox)});
145     <%    end %>
146     <% elsif object %>
147     // Display node/way/relation on the map
148     obj_type = "<%= object_type %>";
149     obj_id = <%= object_id %>;
150     var url = "/api/<%= "#{API_VERSION}" %>/<%= object_type %>/<%= object_id %>";
151
152     if (obj_type != "node") {
153         url += "/full";
154     }
155
156     var osm_layer = new OpenLayers.Layer.GML("OSM", url, {
157         format: OpenLayers.Format.OSM,
158         projection: new OpenLayers.Projection("EPSG:4326")
159     });
160
161     osm_layer.events.register("loadend", osm_layer, function() {
162       if (this.features.length) {
163         var extent =  this.features[0].geometry.getBounds();
164           for (var i = 1; i < this.features.length; i++) {
165             extent.extend(this.features[i].geometry.getBounds());
166            }
167
168            <% unless lat_lon_zoom_via_params %>
169            if (extent) {
170              this.map.zoomToExtent(extent);
171            } else {
172              this.map.zoomToMaxExtent();
173            }
174            <% else %>
175            var center = new OpenLayers.LonLat(<%= lon %>, <%= lat %>);
176            var zoom = <%= zoom %>;
177            <% end %>
178   
179            var center = getMapCenter();
180       }
181     });
182    
183     map.addLayer(osm_layer);
184     osm_layer.loadGML();
185     osm_layer.loaded = true;
186
187     <% else %>
188     var centre = new OpenLayers.LonLat(<%= lon %>, <%= lat %>);
189     var zoom = <%= zoom %>;
190
191     <%    if params['scale'] and params['scale'].length > 0 then %>
192     zoom = scaleToZoom(<%= params['scale'].to_f() %>);
193     <%    end %>
194
195     setMapCenter(centre, zoom);
196     <% end %>
197
198     <% if !layers.nil? and !layers.empty? %>
199     setMapLayers("<%= layers %>");
200     <% end %>
201
202     <% if marker %>
203     marker = addMarkerToMap(new OpenLayers.LonLat(<%= mlon %>, <%= mlat %>));
204     <% end %>
205
206     map.events.register("moveend", map, updateLocation);
207     map.events.register("changelayer", map, updateLocation);
208     updateLocation();
209
210     handleResize();
211   }
212
213   function toggleData() {
214     if (map.dataLayer.visibility) {
215       <%= remote_function :url => { :controller => 'browse', :action => 'start' } %>
216     } else {
217       closeSidebar();
218     }
219   }
220
221   function getPosition() {
222     return getMapCenter();
223   }
224
225   function setPosition(lat, lon, zoom) {
226     var centre = new OpenLayers.LonLat(lon, lat);
227
228     setMapCenter(centre, zoom);
229
230     if (marker)
231       removeMarkerFromMap(marker);
232
233     marker = addMarkerToMap(centre, getArrowIcon());
234   }
235
236   function updateLocation() {
237     var lonlat = getMapCenter();
238     var zoom = map.getZoom();
239     var layers = getMapLayers();
240     var extents = getMapExtent();
241     var expiry = new Date();
242
243     updatelinks(lonlat.lon, lonlat.lat, zoom, layers, extents.left, extents.bottom, extents.right, extents.top, obj_type, obj_id);
244
245     expiry.setYear(expiry.getFullYear() + 10); 
246     document.cookie = "_osm_location=" + lonlat.lon + "|" + lonlat.lat + "|" + zoom + "|" + layers + "; expires=" + expiry.toGMTString();
247   }
248
249   function resizeContent() {
250     var content = $("content");
251     var rightMargin = parseInt(getStyle(content, "right"));
252     var bottomMargin = parseInt(getStyle(content, "bottom"));
253
254     content.style.width = document.documentElement.clientWidth - content.offsetLeft - rightMargin;
255     content.style.height = document.documentElement.clientHeight - content.offsetTop - bottomMargin;
256   }
257   
258   function resizeMap() {
259     var centre = map.getCenter();
260     var zoom = map.getZoom();
261     var sidebar_width = $("sidebar").offsetWidth;
262
263     if (sidebar_width > 0) {
264       sidebar_width = sidebar_width + 5
265     }
266
267     $("map").style.left = (sidebar_width) + "px";
268     $("map").style.width = ($("content").offsetWidth - sidebar_width) + "px";
269     $("map").style.height = ($("content").offsetHeight - 2) + "px";
270
271     map.setCenter(centre, zoom);
272   }
273
274   function handleResize() {
275     if (brokenContentSize) {
276       resizeContent();
277     }
278
279     resizeMap();
280   }
281   
282   mapInit();
283
284   window.onload = handleResize;
285   window.onresize = handleResize;
286
287   <% if params['action'] == 'export' %>
288   <%= remote_function :url => { :controller => 'export', :action => 'start' } %>
289   <% end %>
290 // -->
291 </script>