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 %>");
133 var loginName = "<%= @user.display_name %>"
136 function createBugCallBack() {
137 map.osbControl.deactivate();
138 document.getElementById("OpenLayers.Map_18_OpenLayers_Container").style.cursor = "default";
142 map = createMap("map");
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);
149 map.osbLayer = new OpenLayers.Layer.OpenStreetBugs("OpenStreetBugs", {
150 serverURL : "/api/0.6/",
151 iconOpen : new OpenLayers.Icon("/images/open_bug_marker.png", new OpenLayers.Size(22, 22), new OpenLayers.Pixel(-11, -11)),
152 iconClosed : new OpenLayers.Icon("/images/closed_bug_marker.png", new OpenLayers.Size(22, 22), new OpenLayers.Pixel(-11, -11)),
155 cookieLifetime : 1000,
156 cookiePath : "/my/map/",
157 permalinkURL : "http://www.openstreetmap.org/",
158 theme : "/stylesheets/openstreetbugs.css"
161 map.addLayer(map.osbLayer);
163 map.osbControl = new OpenLayers.Control.OpenStreetBugs(map.osbLayer);
165 map.addControl(map.osbControl);
167 var lBug = document.getElementById('ReportBug');
168 lBug.addEventListener('click',function (e) {
169 map.osbControl.activate(); document.getElementById("OpenLayers.Map_18_OpenLayers_Container").style.cursor = "crosshair" },false);
174 <% unless object_zoom %>
176 var bbox = new OpenLayers.Bounds(<%= minlon %>, <%= minlat %>, <%= maxlon %>, <%= maxlat %>);
181 // IE requires Vector layers be initialised on page load, and not under deferred script conditions
182 Event.observe(window, 'load', function() { addBoxToMap(bbox) });
185 var centre = new OpenLayers.LonLat(<%= lon %>, <%= lat %>);
186 var zoom = <%= zoom %>;
188 <% if params['scale'] and params['scale'].length > 0 then %>
189 zoom = scaleToZoom(<%= params['scale'].to_f() %>);
192 setMapCenter(centre, zoom);
198 <% if !layers.nil? and !layers.empty? %>
199 setMapLayers("<%= layers %>");
203 marker = addMarkerToMap(new OpenLayers.LonLat(<%= mlon %>, <%= mlat %>));
207 var url = "/api/<%= "#{API_VERSION}" %>/<%= object_type %>/<%= object_id %>";
209 <% if object_type != "node" %>
213 // IE requires Vector layers be initialised on page load, and not under deferred script conditions
214 Event.observe(window, 'load', function() { addObjectToMap(url, <%= object_zoom %>) });
217 map.events.register("moveend", map, updateLocation);
218 map.events.register("changelayer", map, updateLocation);
223 function toggleData() {
224 if (map.dataLayer.visibility) {
225 <%= remote_function :url => { :controller => 'browse', :action => 'start' } %>
226 } else if (map.dataLayer.active) {
231 function getPosition() {
232 return getMapCenter();
239 function setPosition(lat, lon, zoom, min_lon, min_lat, max_lon, max_lat) {
240 var centre = new OpenLayers.LonLat(lon, lat);
242 if (min_lon && min_lat && max_lon && max_lat) {
243 var bbox = new OpenLayers.Bounds(min_lon, min_lat, max_lon, max_lat);
247 setMapCenter(centre, zoom);
251 removeMarkerFromMap(marker);
253 marker = addMarkerToMap(centre, getArrowIcon());
256 function updateLocation() {
257 var lonlat = getMapCenter();
258 var zoom = map.getZoom();
259 var layers = getMapLayers();
260 var extents = getMapExtent();
261 var expiry = new Date();
266 objtype = "<%= object_type %>";
267 objid = <%= object_id %>;
270 updatelinks(lonlat.lon, lonlat.lat, zoom, layers, extents.left, extents.bottom, extents.right, extents.top, objtype, objid);
272 expiry.setYear(expiry.getFullYear() + 10);
273 document.cookie = "_osm_location=" + lonlat.lon + "|" + lonlat.lat + "|" + zoom + "|" + layers + "; expires=" + expiry.toGMTString();
276 function resizeContent() {
277 var content = $("content");
278 var rightMargin = parseInt(getStyle(content, "right"));
279 var bottomMargin = parseInt(getStyle(content, "bottom"));
281 content.style.width = document.documentElement.clientWidth - content.offsetLeft - rightMargin;
282 content.style.height = document.documentElement.clientHeight - content.offsetTop - bottomMargin;
285 function resizeMap() {
286 var centre = map.getCenter();
287 var zoom = map.getZoom();
288 var sidebar_width = $("sidebar").offsetWidth;
290 if (sidebar_width > 0) {
291 sidebar_width = sidebar_width + 5
294 $("map").style.left = (sidebar_width) + "px";
295 $("map").style.width = ($("content").offsetWidth - sidebar_width) + "px";
296 $("map").style.height = ($("content").offsetHeight - 2) + "px";
298 map.setCenter(centre, zoom);
301 function handleResize() {
302 if (brokenContentSize) {
309 function remoteEditHandler(event) {
310 var extent = getMapExtent();
313 $("linkloader").observe("load", function () { loaded = true; });
314 $("linkloader").src = "http://127.0.0.1:8111/load_and_zoom?left=" + extent.left + "&top=" + extent.top + "&right=" + extent.right + "&bottom=" + extent.bottom;
316 setTimeout(function () {
317 if (!loaded) alert("<%= escape_javascript(t('site.index.remote_failed')) %>");
323 function installEditHandler() {
324 $("remoteanchor").observe("click", remoteEditHandler);
326 <% if preferred_editor == "remote" %>
327 $("editanchor").observe("click", remoteEditHandler);
329 <% if params[:action] == "edit" %>
337 Event.observe(window, "load", installEditHandler);
338 Event.observe(window, "load", handleResize);
339 Event.observe(window, "resize", handleResize);
341 <% if params['action'] == 'export' %>
342 <%= remote_function :url => { :controller => 'export', :action => 'start' } %>