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}, 10)", { :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 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 box = true if params['box']=="yes"
79 # Decide on a lat lon to initialise the map with. Various ways of doing this
80 if 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 '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 $("map").style.left = (sidebar_width) + "px";
259 $("map").style.width = ($("content").offsetWidth - sidebar_width) + "px";
260 $("map").style.height = ($("content").offsetHeight - 2) + "px";
262 map.setCenter(centre, zoom);
265 function handleResize() {
266 if (brokenContentSize) {
273 function remoteEditHandler(event) {
274 var extent = getMapExtent();
277 $("linkloader").observe("load", function () { loaded = true; });
278 $("linkloader").src = "http://127.0.0.1:8111/load_and_zoom?left=" + extent.left + "&top=" + extent.top + "&right=" + extent.right + "&bottom=" + extent.bottom;
280 setTimeout(function () {
281 if (!loaded) alert("<%= t('site.index.remote_failed') %>");
287 function installEditHandler() {
288 $("remoteanchor").observe("click", remoteEditHandler);
290 <% if preferred_editor == "remote" %>
291 $("editanchor").observe("click", remoteEditHandler);
293 <% if params[:action] == "edit" %>
301 Event.observe(window, "load", installEditHandler);
302 Event.observe(window, "load", handleResize);
303 Event.observe(window, "resize", handleResize);
305 <% if params['action'] == 'export' %>
306 <%= remote_function :url => { :controller => 'export', :action => 'start' } %>