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>
21 <a href="/" id="permalinkanchor"><%= t 'site.index.permalink' %></a><br/>
22 <a href="/" id="shortlinkanchor"><%= t 'site.index.shortlink' %></a>
26 <iframe id="linkloader" style="display: none">
29 <div id="attribution">
32 <td class="attribution_license"><%= t'site.index.license.license_url' %></td>
33 <td class="attribution_project"><%= t'site.index.license.project_url' %></td>
36 <td colspan="2" class="attribution_notice"><%=
37 t'site.index.license.notice',
38 :license_name => t('site.index.license.license_name'),
39 :project_name => t('site.index.license.project_name')
46 if params['mlon'] and params['mlat']
48 mlon = h(params['mlon'])
49 mlat = h(params['mlat'])
52 if params['node'] or params['way'] or params['relation']
58 object_id = h(params['node'])
61 object_id = h(params['way'])
62 elsif params['relation']
63 object_type = 'relation'
64 object_id = h(params['relation'])
68 # Decide on a lat lon to initialise the map with. Various ways of doing this
69 if params['minlon'] and params['minlat'] and params['maxlon'] and params['maxlat']
71 minlon = h(params['minlon'])
72 minlat = h(params['minlat'])
73 maxlon = h(params['maxlon'])
74 maxlat = h(params['maxlat'])
75 layers = h(params['layers'])
76 box = true if params['box']=="yes"
78 elsif params['lon'] and params['lat']
79 lon = h(params['lon'])
80 lat = h(params['lat'])
81 zoom = h(params['zoom'] || '5')
82 layers = h(params['layers'])
84 elsif params['mlon'] and params['mlat']
85 lon = h(params['mlon'])
86 lat = h(params['mlat'])
87 zoom = h(params['zoom'] || '12')
88 layers = h(params['layers'])
90 elsif cookies.key?("_osm_location")
91 lon,lat,zoom,layers = cookies["_osm_location"].split("|")
92 elsif @user and !@user.home_lon.nil? and !@user.home_lat.nil?
97 unless STATUS == :database_readonly or STATUS == :database_offline
98 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 'map.js' %>
121 <script type="text/javascript" defer="defer">
123 var brokenContentSize = $("content").offsetWidth == 0;
127 OpenLayers.Lang.setCode("<%= I18n.locale.to_s %>");
130 map = createMap("map");
132 <% unless STATUS == :api_offline or STATUS == :database_offline %>
133 map.dataLayer = new OpenLayers.Layer("<%= I18n.t 'browse.start_rjs.data_layer_name' %>", { "visibility": false });
134 map.dataLayer.events.register("visibilitychanged", map.dataLayer, toggleData);
135 map.addLayer(map.dataLayer);
138 <% unless object_zoom %>
140 var bbox = new OpenLayers.Bounds(<%= minlon %>, <%= minlat %>, <%= maxlon %>, <%= maxlat %>);
145 // IE requires Vector layers be initialised on page load, and not under deferred script conditions
146 Event.observe(window, 'load', function() { addBoxToMap(bbox) });
149 var centre = new OpenLayers.LonLat(<%= lon %>, <%= lat %>);
150 var zoom = <%= zoom %>;
152 <% if params['scale'] and params['scale'].length > 0 then %>
153 zoom = scaleToZoom(<%= params['scale'].to_f() %>);
156 setMapCenter(centre, zoom);
162 <% if !layers.nil? and !layers.empty? %>
163 setMapLayers("<%= layers %>");
167 marker = addMarkerToMap(new OpenLayers.LonLat(<%= mlon %>, <%= mlat %>));
171 var url = "/api/<%= "#{API_VERSION}" %>/<%= object_type %>/<%= object_id %>";
173 <% if object_type != "node" %>
177 // IE requires Vector layers be initialised on page load, and not under deferred script conditions
178 Event.observe(window, 'load', function() { addObjectToMap(url, <%= object_zoom %>) });
181 map.events.register("moveend", map, updateLocation);
182 map.events.register("changelayer", map, updateLocation);
187 function toggleData() {
188 if (map.dataLayer.visibility) {
189 <%= remote_function :url => { :controller => 'browse', :action => 'start' } %>
190 } else if (map.dataLayer.active) {
195 function getPosition() {
196 return getMapCenter();
203 function setPosition(lat, lon, zoom, min_lon, min_lat, max_lon, max_lat) {
204 var centre = new OpenLayers.LonLat(lon, lat);
206 if (min_lon && min_lat && max_lon && max_lat) {
207 var bbox = new OpenLayers.Bounds(min_lon, min_lat, max_lon, max_lat);
211 setMapCenter(centre, zoom);
215 removeMarkerFromMap(marker);
217 marker = addMarkerToMap(centre, getArrowIcon());
220 function updateLocation() {
221 var lonlat = getMapCenter();
222 var zoom = map.getZoom();
223 var layers = getMapLayers();
224 var extents = getMapExtent();
225 var expiry = new Date();
230 objtype = "<%= object_type %>";
231 objid = <%= object_id %>;
234 updatelinks(lonlat.lon, lonlat.lat, zoom, layers, extents.left, extents.bottom, extents.right, extents.top, objtype, objid);
236 expiry.setYear(expiry.getFullYear() + 10);
237 document.cookie = "_osm_location=" + lonlat.lon + "|" + lonlat.lat + "|" + zoom + "|" + layers + "; expires=" + expiry.toGMTString();
240 function resizeContent() {
241 var content = $("content");
242 var rightMargin = parseInt(getStyle(content, "right"));
243 var bottomMargin = parseInt(getStyle(content, "bottom"));
245 content.style.width = document.documentElement.clientWidth - content.offsetLeft - rightMargin;
246 content.style.height = document.documentElement.clientHeight - content.offsetTop - bottomMargin;
249 function resizeMap() {
250 var centre = map.getCenter();
251 var zoom = map.getZoom();
252 var sidebar_width = $("sidebar").offsetWidth;
254 if (sidebar_width > 0) {
255 sidebar_width = sidebar_width + 5
258 <% if t('html.dir') == "ltr" -%>
259 $("map").style.left = (sidebar_width) + "px";
261 $("map").style.right = (sidebar_width) + "px";
263 $("map").style.width = ($("content").offsetWidth - sidebar_width) + "px";
264 $("map").style.height = ($("content").offsetHeight - 2) + "px";
266 map.setCenter(centre, zoom);
269 function handleResize() {
270 if (brokenContentSize) {
277 function remoteEditHandler(event) {
278 var extent = getMapExtent();
281 $("linkloader").observe("load", function () { loaded = true; });
282 $("linkloader").src = "http://127.0.0.1:8111/load_and_zoom?left=" + extent.left + "&top=" + extent.top + "&right=" + extent.right + "&bottom=" + extent.bottom;
284 setTimeout(function () {
285 if (!loaded) alert("<%= escape_javascript(t('site.index.remote_failed')) %>");
291 function installEditHandler() {
292 $("remoteanchor").observe("click", remoteEditHandler);
294 <% if preferred_editor == "remote" %>
295 $("editanchor").observe("click", remoteEditHandler);
297 <% if params[:action] == "edit" %>
305 Event.observe(window, "load", installEditHandler);
306 Event.observe(window, "load", handleResize);
307 Event.observe(window, "resize", handleResize);
309 <% if params['action'] == 'export' %>
310 <%= remote_function :url => { :controller => 'export', :action => 'start' } %>