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