]> git.openstreetmap.org Git - rails.git/blob - app/views/site/index.html.erb
Remove dead code
[rails.git] / app / views / site / index.html.erb
1 <% if @user and !@user.home_lon.nil? and !@user.home_lat.nil? %>
2   <% content_for :greeting do %>
3     <%= link_to_function t('layouts.home'), "setPosition(#{@user.home_lat}, #{@user.home_lon}, 15)", { :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" class="geolink llz layers object"><%= t 'site.index.permalink' %></a>
22     <a href="/" id="shortlinkanchor"><%= t 'site.index.shortlink' %></a>
23   </div>
24 </div>
25
26 <iframe id="linkloader" style="display: none">
27 </iframe>
28
29 <div id="attribution">
30   <table width="100%">
31     <tr>
32       <td class="attribution_license"><%= t'site.index.license.license_url' %></td>
33       <td class="attribution_project"><%= t'site.index.license.project_url' %></td>
34     </tr>
35     <tr>
36       <td colspan="2" class="attribution_notice"><%=
37         t'site.index.license.notice',
38           :license_name => t('site.index.license.license_name'),
39           :project_name => t('site.index.license.project_name')
40         %></td>
41     </tr>
42   </table>
43 </div>
44
45 <%
46 if params[:mlon] and params[:mlat]
47     marker = true
48     mlon = params[:mlon].to_f
49     mlat = params[:mlat].to_f
50 end
51
52 if params[:node] or params[:way] or params[:relation]
53     object = true
54     object_zoom = true
55
56     if params[:node]
57         object_type = 'node'
58         object_id = params[:node].to_i
59     elsif params[:way]
60         object_type = 'way'
61         object_id = params[:way].to_i
62     elsif params[:relation]
63         object_type = 'relation'
64         object_id = params[:relation].to_i
65     end
66 end
67
68 # Decide on a lat lon to initialise the map with. Various ways of doing this
69 if params[:bbox]
70     bbox = true
71     minlon, minlat, maxlon, maxlat = params[:bbox].split(",").collect { |c| c.to_f }
72     layers = params[:layers]
73     box = true if params[:box] == "yes"
74     object_zoom = false
75 elsif params[:minlon] and params[:minlat] and params[:maxlon] and params[:maxlat]
76     bbox = true
77     minlon = params[:minlon].to_f
78     minlat = params[:minlat].to_f
79     maxlon = params[:maxlon].to_f
80     maxlat = params[:maxlat].to_f
81     layers = params[:layers]
82     box = true if params[:box]=="yes"
83     object_zoom = false
84 elsif params[:lon] and params[:lat]
85     lon =  params[:lon].to_f
86     lat =  params[:lat].to_f
87     zoom =  params.fetch(:zoom, 5).to_i
88     layers = params[:layers]
89     object_zoom = false
90 elsif params[:mlon] and params[:mlat]
91     lon = params[:mlon].to_f
92     lat = params[:mlat].to_f
93     zoom =  params.fetch(:zoom, 12).to_i
94     layers = params[:layers]
95     object_zoom = false
96 elsif cookies.key?("_osm_location")
97     lon,lat,zoom,layers = cookies["_osm_location"].split("|")
98 elsif @user and !@user.home_lon.nil? and !@user.home_lat.nil?
99     lon =  @user.home_lon
100     lat =  @user.home_lat
101     zoom = 10
102 else
103     unless STATUS == :database_readonly or STATUS == :database_offline
104       session[:location] = OSM::IPLocation(request.env['REMOTE_ADDR']) unless session[:location]
105     end
106
107     if session[:location]
108         bbox = true
109         minlon = session[:location][:minlon]
110         minlat = session[:location][:minlat]
111         maxlon = session[:location][:maxlon]
112         maxlat = session[:location][:maxlat]
113     else
114         lon =  -0.1
115         lat =  51.5
116         zoom =  params.fetch(:zoom, 5).to_i
117     end
118
119     layers = params[:layers]
120 end
121 %>
122
123 <%= javascript_include_tag 'openlayers.js' %>
124 <%= javascript_include_tag 'map.js' %>
125
126 <%= render :partial => 'resize' %>
127
128 <script type="text/javascript">
129   var marker;
130   var map;
131
132   OpenLayers.Lang.setCode("<%= I18n.locale.to_s %>");
133
134   function mapInit(){
135     map = createMap("map");
136
137     <% unless STATUS == :api_offline or STATUS == :database_offline %>
138       map.dataLayer = new OpenLayers.Layer("<%= I18n.t 'browse.start_rjs.data_layer_name' %>", { "visibility": false });
139       map.dataLayer.events.register("visibilitychanged", map.dataLayer, toggleData);
140       map.addLayer(map.dataLayer);
141     <% end %>
142
143     <% unless object_zoom %>
144       <% if bbox %>
145         var bbox = new OpenLayers.Bounds(<%= minlon %>, <%= minlat %>, <%= maxlon %>, <%= maxlat %>);
146
147         setMapExtent(bbox);
148
149         <% if box %>
150           $(window).load(function() { addBoxToMap(bbox) });
151         <% end %>
152       <% else %>
153         var centre = new OpenLayers.LonLat(<%= lon %>, <%= lat %>);
154         var zoom = <%= zoom %>;
155
156         <% if params[:scale] and params[:scale].length > 0 then %>
157           zoom = scaleToZoom(<%= params[:scale].to_f %>);
158         <% end %>
159
160         setMapCenter(centre, zoom);
161       <% end %>
162     <% end %>
163
164     <% if !layers.nil? and !layers.empty? %>
165       setMapLayers("<%= layers %>");
166     <% end %>
167
168     <% if marker %>
169       marker = addMarkerToMap(new OpenLayers.LonLat(<%= mlon %>, <%= mlat %>));
170     <% end %>
171
172     <% if object %>
173       var url = "/api/<%= "#{API_VERSION}" %>/<%= object_type %>/<%= object_id %>";
174
175       <% if object_type != "node" %>
176         url += "/full";
177       <% end %>
178
179       $(window).load(function() { addObjectToMap(url, <%= object_zoom %>) });
180     <% end %>
181
182     map.events.register("moveend", map, updateLocation);
183     map.events.register("changelayer", map, updateLocation);
184
185     updateLocation();
186     handleResize();
187   }
188
189   function toggleData() {
190     if (map.dataLayer.visibility) {
191       $.ajax({ url: "<%= url_for :controller => :browse, :action => :start %>" });
192     } else if (map.dataLayer.active) {
193       closeSidebar();
194     }
195   }
196
197   function setPosition(lat, lon, zoom, min_lon, min_lat, max_lon, max_lat) {
198     var centre = new OpenLayers.LonLat(lon, lat);
199
200     if (min_lon && min_lat && max_lon && max_lat) {
201       var bbox = new OpenLayers.Bounds(min_lon, min_lat, max_lon, max_lat);
202
203       setMapExtent(bbox);
204     } else {
205       setMapCenter(centre, zoom);
206     }
207
208     if (marker)
209       removeMarkerFromMap(marker);
210
211     marker = addMarkerToMap(centre, getArrowIcon());
212   }
213
214   function updateLocation() {
215     var lonlat = getMapCenter();
216     var zoom = map.getZoom();
217     var layers = getMapLayers();
218     var extents = getMapExtent();
219     var expiry = new Date();
220     var objtype;
221     var objid;
222
223     <% if object %>
224       objtype = "<%= object_type %>";
225       objid = <%= object_id %>;
226     <% end %>
227
228     updatelinks(lonlat.lon, lonlat.lat, zoom, layers, extents.left, extents.bottom, extents.right, extents.top, objtype, objid);
229
230     expiry.setYear(expiry.getFullYear() + 10);
231     document.cookie = "_osm_location=" + lonlat.lon + "|" + lonlat.lat + "|" + zoom + "|" + layers + "; expires=" + expiry.toGMTString();
232   }
233
234   function remoteEditHandler(event) {
235     var extent = getMapExtent();
236     var loaded = false;
237
238     $("#linkloader").load(function () { loaded = true; });
239     $("#linkloader").attr("src", "http://127.0.0.1:8111/load_and_zoom?left=" + extent.left + "&top=" + extent.top + "&right=" + extent.right + "&bottom=" + extent.bottom);
240
241     setTimeout(function () {
242       if (!loaded) alert("<%=j t('site.index.remote_failed') %>");
243     }, 1000);
244
245     return false;
246   }
247
248   function installEditHandler() {
249     $("#remoteanchor").click(remoteEditHandler);
250
251     <% if preferred_editor == "remote" %>
252       $("#editanchor").click(remoteEditHandler);
253
254       <% if params[:action] == "edit" %>
255         remoteEditHandler();
256       <% end %>
257     <% end %>
258   }
259
260   $(document).ready(mapInit);
261   $(document).ready(installEditHandler);
262   $(document).ready(handleResize);
263
264   $(window).resize(function() {
265     var centre = map.getCenter();
266     var zoom = map.getZoom();
267
268     handleResize();
269
270     map.setCenter(centre, zoom);
271   });
272
273   $(document).ready(function () {
274     $("#exportanchor").click(function (e) {
275       $.ajax({ url: "<%= url_for :controller => :export, :action => :start %>" });
276       Event.stop(e);
277     });
278
279     <% if params[:action] == 'export' -%>
280     $.ajax({ url: "<%= url_for :controller => :export, :action => :start %>" });
281     <% end -%>
282
283     <% if params[:query] -%>
284     doSearch("<%= params[:query] %>");
285     <% end %>
286   });
287 // -->
288 </script>