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="javascript:void()" id="ReportBug">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 <!--Use stock OpenLayers for now, as the OSM one is missing some needed classes-->
118 <script src="http://www.openlayers.org/api/OpenLayers.js"></script>
119 <!-- < %= javascript_include_tag '/openlayers/OpenLayers.js' % > -->
120 <%= javascript_include_tag '/openlayers/OpenStreetMap.js' %>
121 <%= javascript_include_tag 'openstreetbugs.js' %>
122 <%= javascript_include_tag 'map.js' %>
124 <script type="text/javascript" defer="defer">
126 var brokenContentSize = $("content").offsetWidth == 0;
130 OpenLayers.Lang.setCode("<%= I18n.locale.to_s %>");
132 function createBugCallBack() {
133 map.osbControl.deactivate();
134 document.getElementById("OpenLayers.Map_18_OpenLayers_Container").style.cursor = "default";
138 map = createMap("map");
140 <% unless STATUS == :api_offline or STATUS == :database_offline %>
141 map.dataLayer = new OpenLayers.Layer("<%= I18n.t 'browse.start_rjs.data_layer_name' %>", { "visibility": false });
142 map.dataLayer.events.register("visibilitychanged", map.dataLayer, toggleData);
143 map.addLayer(map.dataLayer);
145 map.osbLayer = new OpenLayers.Layer.OpenStreetBugs("OpenStreetBugs", {
146 serverURL : "/api/0.6/",
147 iconOpen : new OpenLayers.Icon("/images/open_bug_marker.png", new OpenLayers.Size(22, 22), new OpenLayers.Pixel(-11, -11)),
148 iconClosed : new OpenLayers.Icon("/images/closed_bug_marker.png", new OpenLayers.Size(22, 22), new OpenLayers.Pixel(-11, -11)),
151 cookieLifetime : 1000,
152 cookiePath : "/my/map/",
153 permalinkURL : "http://www.openstreetmap.org/",
154 theme : "/stylesheets/openstreetbugs.css"
157 map.addLayer(map.osbLayer);
159 map.osbControl = new OpenLayers.Control.OpenStreetBugs(map.osbLayer);
161 map.addControl(map.osbControl);
163 var lBug = document.getElementById('ReportBug');
164 lBug.addEventListener('click',function (e) {
165 map.osbControl.activate(); document.getElementById("OpenLayers.Map_18_OpenLayers_Container").style.cursor = "crosshair" },false);
170 <% unless object_zoom %>
172 var bbox = new OpenLayers.Bounds(<%= minlon %>, <%= minlat %>, <%= maxlon %>, <%= maxlat %>);
177 // IE requires Vector layers be initialised on page load, and not under deferred script conditions
178 Event.observe(window, 'load', function() { addBoxToMap(bbox) });
181 var centre = new OpenLayers.LonLat(<%= lon %>, <%= lat %>);
182 var zoom = <%= zoom %>;
184 <% if params['scale'] and params['scale'].length > 0 then %>
185 zoom = scaleToZoom(<%= params['scale'].to_f() %>);
188 setMapCenter(centre, zoom);
194 <% if !layers.nil? and !layers.empty? %>
195 setMapLayers("<%= layers %>");
199 marker = addMarkerToMap(new OpenLayers.LonLat(<%= mlon %>, <%= mlat %>));
203 var url = "/api/<%= "#{API_VERSION}" %>/<%= object_type %>/<%= object_id %>";
205 <% if object_type != "node" %>
209 // IE requires Vector layers be initialised on page load, and not under deferred script conditions
210 Event.observe(window, 'load', function() { addObjectToMap(url, <%= object_zoom %>) });
213 map.events.register("moveend", map, updateLocation);
214 map.events.register("changelayer", map, updateLocation);
219 function toggleData() {
220 if (map.dataLayer.visibility) {
221 <%= remote_function :url => { :controller => 'browse', :action => 'start' } %>
222 } else if (map.dataLayer.active) {
227 function getPosition() {
228 return getMapCenter();
235 function setPosition(lat, lon, zoom, min_lon, min_lat, max_lon, max_lat) {
236 var centre = new OpenLayers.LonLat(lon, lat);
238 if (min_lon && min_lat && max_lon && max_lat) {
239 var bbox = new OpenLayers.Bounds(min_lon, min_lat, max_lon, max_lat);
243 setMapCenter(centre, zoom);
247 removeMarkerFromMap(marker);
249 marker = addMarkerToMap(centre, getArrowIcon());
252 function updateLocation() {
253 var lonlat = getMapCenter();
254 var zoom = map.getZoom();
255 var layers = getMapLayers();
256 var extents = getMapExtent();
257 var expiry = new Date();
262 objtype = "<%= object_type %>";
263 objid = <%= object_id %>;
266 updatelinks(lonlat.lon, lonlat.lat, zoom, layers, extents.left, extents.bottom, extents.right, extents.top, objtype, objid);
268 expiry.setYear(expiry.getFullYear() + 10);
269 document.cookie = "_osm_location=" + lonlat.lon + "|" + lonlat.lat + "|" + zoom + "|" + layers + "; expires=" + expiry.toGMTString();
272 function resizeContent() {
273 var content = $("content");
274 var rightMargin = parseInt(getStyle(content, "right"));
275 var bottomMargin = parseInt(getStyle(content, "bottom"));
277 content.style.width = document.documentElement.clientWidth - content.offsetLeft - rightMargin;
278 content.style.height = document.documentElement.clientHeight - content.offsetTop - bottomMargin;
281 function resizeMap() {
282 var centre = map.getCenter();
283 var zoom = map.getZoom();
284 var sidebar_width = $("sidebar").offsetWidth;
286 if (sidebar_width > 0) {
287 sidebar_width = sidebar_width + 5
290 $("map").style.left = (sidebar_width) + "px";
291 $("map").style.width = ($("content").offsetWidth - sidebar_width) + "px";
292 $("map").style.height = ($("content").offsetHeight - 2) + "px";
294 map.setCenter(centre, zoom);
297 function handleResize() {
298 if (brokenContentSize) {
305 function remoteEditHandler(event) {
306 var extent = getMapExtent();
309 $("linkloader").observe("load", function () { loaded = true; });
310 $("linkloader").src = "http://127.0.0.1:8111/load_and_zoom?left=" + extent.left + "&top=" + extent.top + "&right=" + extent.right + "&bottom=" + extent.bottom;
312 setTimeout(function () {
313 if (!loaded) alert("<%= escape_javascript(t('site.index.remote_failed')) %>");
319 function installEditHandler() {
320 $("remoteanchor").observe("click", remoteEditHandler);
322 <% if preferred_editor == "remote" %>
323 $("editanchor").observe("click", remoteEditHandler);
325 <% if params[:action] == "edit" %>
333 Event.observe(window, "load", installEditHandler);
334 Event.observe(window, "load", handleResize);
335 Event.observe(window, "resize", handleResize);
337 <% if params['action'] == 'export' %>
338 <%= remote_function :url => { :controller => 'export', :action => 'start' } %>