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') } %> |
7 <%= render :partial => 'sidebar', :locals => { :onopen => "resizeMap();", :onclose => "resizeMap();" } %>
8 <%= render :partial => 'key' %>
9 <%= render :partial => 'search' %>
13 <p><%= t 'site.index.js_1' %></p>
14 <p><%= t 'site.index.js_2' %></p>
15 <p><%= t 'site.index.js_3' %></p>
22 <iframe id="linkloader" style="display: none">
26 <a href="/" id="permalinkanchor"><%= t 'site.index.permalink' %></a><br/>
27 <a href="/" id="shortlinkanchor"><%= t 'site.index.shortlink' %></a><br/>
28 <a href="#" id="reportbuganchor">Report a problem</a>
31 <div id="attribution">
34 <td align="left"><%= t'site.index.license.license_url' %></td>
35 <td align="right"><%= t'site.index.license.project_url' %></td>
38 <td colspan="2" align="center"><%=
39 t'site.index.license.notice',
40 :license_name => t('site.index.license.license_name'),
41 :project_name => t('site.index.license.project_name')
48 if params['mlon'] and params['mlat']
50 mlon = h(params['mlon'])
51 mlat = h(params['mlat'])
54 if params['node'] or params['way'] or params['relation']
60 object_id = h(params['node'])
63 object_id = h(params['way'])
64 elsif params['relation']
65 object_type = 'relation'
66 object_id = h(params['relation'])
70 # Decide on a lat lon to initialise the map with. Various ways of doing this
71 if params['minlon'] and params['minlat'] and params['maxlon'] and params['maxlat']
73 minlon = h(params['minlon'])
74 minlat = h(params['minlat'])
75 maxlon = h(params['maxlon'])
76 maxlat = h(params['maxlat'])
77 layers = h(params['layers'])
78 box = true if params['box']=="yes"
80 elsif params['lon'] and params['lat']
81 lon = h(params['lon'])
82 lat = h(params['lat'])
83 zoom = h(params['zoom'] || '5')
84 layers = h(params['layers'])
86 elsif params['mlon'] and params['mlat']
87 lon = h(params['mlon'])
88 lat = h(params['mlat'])
89 zoom = h(params['zoom'] || '12')
90 layers = h(params['layers'])
92 elsif cookies.key?("_osm_location")
93 lon,lat,zoom,layers = cookies["_osm_location"].split("|")
94 elsif @user and !@user.home_lon.nil? and !@user.home_lat.nil?
99 session[:location] = OSM::IPLocation(request.env['REMOTE_ADDR']) unless session[:location]
101 if session[:location]
103 minlon = session[:location][:minlon]
104 minlat = session[:location][:minlat]
105 maxlon = session[:location][:maxlon]
106 maxlat = session[:location][:maxlat]
110 zoom = h(params['zoom'] || '5')
113 layers = h(params['layers'])
117 <%= javascript_include_tag '/openlayers/OpenLayers.js' %>
118 <%= javascript_include_tag '/openlayers/OpenStreetMap.js' %>
119 <%= javascript_include_tag 'openstreetbugs.js' %>
120 <%= javascript_include_tag 'map.js' %>
122 <script type="text/javascript" defer="defer">
124 var brokenContentSize = $("content").offsetWidth == 0;
128 OpenLayers.Lang.setCode("<%= I18n.locale.to_s %>");
131 var loginName = "<%= @user.display_name %>"
135 map = createMap("map");
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);
142 map.osbLayer = new OpenLayers.Layer.OpenStreetBugs("OpenStreetBugs", {
143 serverURL: "/api/0.6/",
144 iconOpen: new OpenLayers.Icon("<%= image_path "open_bug_marker.png" %>", new OpenLayers.Size(22, 22), new OpenLayers.Pixel(-11, -11)),
145 iconClosed: new OpenLayers.Icon("<%= image_path "closed_bug_marker.png" %>", new OpenLayers.Size(22, 22), new OpenLayers.Pixel(-11, -11)),
148 permalinkURL: "http://www.openstreetmap.org/",
149 theme: "<%= stylesheet_path "openstreetbugs" %>",
152 map.addLayer(map.osbLayer);
154 map.osbControl = new OpenLayers.Control.OpenStreetBugs(map.osbLayer);
155 map.addControl(map.osbControl);
157 $("reportbuganchor").observe("click", addBug);
159 map.events.register("zoomend", map, allowBugReports);
162 <% unless object_zoom %>
164 var bbox = new OpenLayers.Bounds(<%= minlon %>, <%= minlat %>, <%= maxlon %>, <%= maxlat %>);
169 // IE requires Vector layers be initialised on page load, and not under deferred script conditions
170 Event.observe(window, 'load', function() { addBoxToMap(bbox) });
173 var centre = new OpenLayers.LonLat(<%= lon %>, <%= lat %>);
174 var zoom = <%= zoom %>;
176 <% if params['scale'] and params['scale'].length > 0 then %>
177 zoom = scaleToZoom(<%= params['scale'].to_f() %>);
180 setMapCenter(centre, zoom);
186 <% if !layers.nil? and !layers.empty? %>
187 setMapLayers("<%= layers %>");
191 marker = addMarkerToMap(new OpenLayers.LonLat(<%= mlon %>, <%= mlat %>));
195 var url = "/api/<%= "#{API_VERSION}" %>/<%= object_type %>/<%= object_id %>";
197 <% if object_type != "node" %>
201 // IE requires Vector layers be initialised on page load, and not under deferred script conditions
202 Event.observe(window, 'load', function() { addObjectToMap(url, <%= object_zoom %>) });
205 map.events.register("moveend", map, updateLocation);
206 map.events.register("changelayer", map, updateLocation);
211 function toggleData() {
212 if (map.dataLayer.visibility) {
213 <%= remote_function :url => { :controller => 'browse', :action => 'start' } %>
214 } else if (map.dataLayer.active) {
219 function getPosition() {
220 return getMapCenter();
227 function setPosition(lat, lon, zoom, min_lon, min_lat, max_lon, max_lat) {
228 var centre = new OpenLayers.LonLat(lon, lat);
230 if (min_lon && min_lat && max_lon && max_lat) {
231 var bbox = new OpenLayers.Bounds(min_lon, min_lat, max_lon, max_lat);
235 setMapCenter(centre, zoom);
239 removeMarkerFromMap(marker);
241 marker = addMarkerToMap(centre, getArrowIcon());
244 function updateLocation() {
245 var lonlat = getMapCenter();
246 var zoom = map.getZoom();
247 var layers = getMapLayers();
248 var extents = getMapExtent();
249 var expiry = new Date();
254 objtype = "<%= object_type %>";
255 objid = <%= object_id %>;
258 updatelinks(lonlat.lon, lonlat.lat, zoom, layers, extents.left, extents.bottom, extents.right, extents.top, objtype, objid);
260 expiry.setYear(expiry.getFullYear() + 10);
261 document.cookie = "_osm_location=" + lonlat.lon + "|" + lonlat.lat + "|" + zoom + "|" + layers + "; expires=" + expiry.toGMTString();
264 function resizeContent() {
265 var content = $("content");
266 var rightMargin = parseInt(getStyle(content, "right"));
267 var bottomMargin = parseInt(getStyle(content, "bottom"));
269 content.style.width = document.documentElement.clientWidth - content.offsetLeft - rightMargin;
270 content.style.height = document.documentElement.clientHeight - content.offsetTop - bottomMargin;
273 function resizeMap() {
274 var centre = map.getCenter();
275 var zoom = map.getZoom();
276 var sidebar_width = $("sidebar").offsetWidth;
278 if (sidebar_width > 0) {
279 sidebar_width = sidebar_width + 5
282 $("map").style.left = (sidebar_width) + "px";
283 $("map").style.width = ($("content").offsetWidth - sidebar_width) + "px";
284 $("map").style.height = ($("content").offsetHeight - 2) + "px";
286 map.setCenter(centre, zoom);
289 function handleResize() {
290 if (brokenContentSize) {
297 function remoteEditHandler(event) {
298 var extent = getMapExtent();
301 $("linkloader").observe("load", function () { loaded = true; });
302 $("linkloader").src = "http://127.0.0.1:8111/load_and_zoom?left=" + extent.left + "&top=" + extent.top + "&right=" + extent.right + "&bottom=" + extent.bottom;
304 setTimeout(function () {
305 if (!loaded) alert("<%= escape_javascript(t('site.index.remote_failed')) %>");
311 function installEditHandler() {
312 $("remoteanchor").observe("click", remoteEditHandler);
314 <% if preferred_editor == "remote" %>
315 $("editanchor").observe("click", remoteEditHandler);
317 <% if params[:action] == "edit" %>
324 map.osbControl.activate();
325 map.osbControl.addTemporaryMarker(map.getCenter());
328 function allowBugReports() {
329 if (map.getZoom() > 11) {
330 $("reportbuganchor").style.visibility = "visible";
332 $("reportbuganchor").style.visibility = "hidden";
338 Event.observe(window, "load", installEditHandler);
339 Event.observe(window, "load", handleResize);
340 Event.observe(window, "resize", handleResize);
342 <% if params['action'] == 'export' %>
343 <%= remote_function :url => { :controller => 'export', :action => 'start' } %>