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>
30 <div id="attribution">
33 <td align="left"><%= t'site.index.license.license_url' %></td>
34 <td align="right"><%= t'site.index.license.project_url' %></td>
37 <td colspan="2" align="center"><%=
38 t'site.index.license.notice',
39 :license_name => t('site.index.license.license_name'),
40 :project_name => t('site.index.license.project_name')
47 if params['mlon'] and params['mlat']
49 mlon = h(params['mlon'])
50 mlat = h(params['mlat'])
53 if params['node'] or params['way'] or params['relation']
59 object_id = h(params['node'])
62 object_id = h(params['way'])
63 elsif params['relation']
64 object_type = 'relation'
65 object_id = h(params['relation'])
69 # Decide on a lat lon to initialise the map with. Various ways of doing this
70 if params['minlon'] and params['minlat'] and params['maxlon'] and params['maxlat']
72 minlon = h(params['minlon'])
73 minlat = h(params['minlat'])
74 maxlon = h(params['maxlon'])
75 maxlat = h(params['maxlat'])
76 layers = h(params['layers'])
77 box = true if params['box']=="yes"
79 elsif params['lon'] and params['lat']
80 lon = h(params['lon'])
81 lat = h(params['lat'])
82 zoom = h(params['zoom'] || '5')
83 layers = h(params['layers'])
85 elsif params['mlon'] and params['mlat']
86 lon = h(params['mlon'])
87 lat = h(params['mlat'])
88 zoom = h(params['zoom'] || '12')
89 layers = h(params['layers'])
91 elsif cookies.key?("_osm_location")
92 lon,lat,zoom,layers = cookies["_osm_location"].split("|")
93 elsif @user and !@user.home_lon.nil? and !@user.home_lat.nil?
98 unless STATUS == :database_readonly or STATUS == :database_offline
99 session[:location] = OSM::IPLocation(request.env['REMOTE_ADDR']) unless session[:location]
102 if session[:location]
104 minlon = session[:location][:minlon]
105 minlat = session[:location][:minlat]
106 maxlon = session[:location][:maxlon]
107 maxlat = session[:location][:maxlat]
111 zoom = h(params['zoom'] || '5')
114 layers = h(params['layers'])
118 <%= javascript_include_tag '/openlayers/OpenLayers.js' %>
119 <%= javascript_include_tag '/openlayers/OpenStreetMap.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 map = createMap("map");
133 <% unless STATUS == :api_offline or STATUS == :database_offline %>
134 map.dataLayer = new OpenLayers.Layer("<%= I18n.t 'browse.start_rjs.data_layer_name' %>", { "visibility": false });
135 map.dataLayer.events.register("visibilitychanged", map.dataLayer, toggleData);
136 map.addLayer(map.dataLayer);
139 <% unless object_zoom %>
141 var bbox = new OpenLayers.Bounds(<%= minlon %>, <%= minlat %>, <%= maxlon %>, <%= maxlat %>);
146 // IE requires Vector layers be initialised on page load, and not under deferred script conditions
147 Event.observe(window, 'load', function() { addBoxToMap(bbox) });
150 var centre = new OpenLayers.LonLat(<%= lon %>, <%= lat %>);
151 var zoom = <%= zoom %>;
153 <% if params['scale'] and params['scale'].length > 0 then %>
154 zoom = scaleToZoom(<%= params['scale'].to_f() %>);
157 setMapCenter(centre, zoom);
163 <% if !layers.nil? and !layers.empty? %>
164 setMapLayers("<%= layers %>");
168 marker = addMarkerToMap(new OpenLayers.LonLat(<%= mlon %>, <%= mlat %>));
172 var url = "/api/<%= "#{API_VERSION}" %>/<%= object_type %>/<%= object_id %>";
174 <% if object_type != "node" %>
178 // IE requires Vector layers be initialised on page load, and not under deferred script conditions
179 Event.observe(window, 'load', function() { addObjectToMap(url, <%= object_zoom %>) });
182 map.events.register("moveend", map, updateLocation);
183 map.events.register("changelayer", map, updateLocation);
188 function toggleData() {
189 if (map.dataLayer.visibility) {
190 <%= remote_function :url => { :controller => 'browse', :action => 'start' } %>
191 } else if (map.dataLayer.active) {
196 function getPosition() {
197 return getMapCenter();
204 function setPosition(lat, lon, zoom, min_lon, min_lat, max_lon, max_lat) {
205 var centre = new OpenLayers.LonLat(lon, lat);
207 if (min_lon && min_lat && max_lon && max_lat) {
208 var bbox = new OpenLayers.Bounds(min_lon, min_lat, max_lon, max_lat);
212 setMapCenter(centre, zoom);
216 removeMarkerFromMap(marker);
218 marker = addMarkerToMap(centre, getArrowIcon());
221 function updateLocation() {
222 var lonlat = getMapCenter();
223 var zoom = map.getZoom();
224 var layers = getMapLayers();
225 var extents = getMapExtent();
226 var expiry = new Date();
231 objtype = "<%= object_type %>";
232 objid = <%= object_id %>;
235 updatelinks(lonlat.lon, lonlat.lat, zoom, layers, extents.left, extents.bottom, extents.right, extents.top, objtype, objid);
237 expiry.setYear(expiry.getFullYear() + 10);
238 document.cookie = "_osm_location=" + lonlat.lon + "|" + lonlat.lat + "|" + zoom + "|" + layers + "; expires=" + expiry.toGMTString();
241 function resizeContent() {
242 var content = $("content");
243 var rightMargin = parseInt(getStyle(content, "right"));
244 var bottomMargin = parseInt(getStyle(content, "bottom"));
246 content.style.width = document.documentElement.clientWidth - content.offsetLeft - rightMargin;
247 content.style.height = document.documentElement.clientHeight - content.offsetTop - bottomMargin;
250 function resizeMap() {
251 var centre = map.getCenter();
252 var zoom = map.getZoom();
253 var sidebar_width = $("sidebar").offsetWidth;
255 if (sidebar_width > 0) {
256 sidebar_width = sidebar_width + 5
259 $("map").style.left = (sidebar_width) + "px";
260 $("map").style.width = ($("content").offsetWidth - sidebar_width) + "px";
261 $("map").style.height = ($("content").offsetHeight - 2) + "px";
263 map.setCenter(centre, zoom);
266 function handleResize() {
267 if (brokenContentSize) {
274 function remoteEditHandler(event) {
275 var extent = getMapExtent();
278 $("linkloader").observe("load", function () { loaded = true; });
279 $("linkloader").src = "http://127.0.0.1:8111/load_and_zoom?left=" + extent.left + "&top=" + extent.top + "&right=" + extent.right + "&bottom=" + extent.bottom;
281 setTimeout(function () {
282 if (!loaded) alert("<%= escape_javascript(t('site.index.remote_failed')) %>");
288 function installEditHandler() {
289 $("remoteanchor").observe("click", remoteEditHandler);
291 <% if preferred_editor == "remote" %>
292 $("editanchor").observe("click", remoteEditHandler);
294 <% if params[:action] == "edit" %>
302 Event.observe(window, "load", installEditHandler);
303 Event.observe(window, "load", handleResize);
304 Event.observe(window, "resize", handleResize);
306 <% if params['action'] == 'export' %>
307 <%= remote_function :url => { :controller => 'export', :action => 'start' } %>