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 session[:location] = OSM::IPLocation(request.env['REMOTE_ADDR']) unless session[:location]
100 if session[:location]
102 minlon = session[:location][:minlon]
103 minlat = session[:location][:minlat]
104 maxlon = session[:location][:maxlon]
105 maxlat = session[:location][:maxlat]
109 zoom = h(params['zoom'] || '5')
112 layers = h(params['layers'])
116 <%= javascript_include_tag '/openlayers/OpenLayers.js' %>
117 <%= javascript_include_tag '/openlayers/OpenStreetMap.js' %>
118 <%= javascript_include_tag 'map.js' %>
120 <script type="text/javascript" defer="defer">
122 var brokenContentSize = $("content").offsetWidth == 0;
126 OpenLayers.Lang.setCode("<%= I18n.locale.to_s %>");
129 map = createMap("map");
131 <% unless STATUS == :api_offline or STATUS == :database_offline %>
132 map.dataLayer = new OpenLayers.Layer("<%= I18n.t 'browse.start_rjs.data_layer_name' %>", { "visibility": false });
133 map.dataLayer.events.register("visibilitychanged", map.dataLayer, toggleData);
134 map.addLayer(map.dataLayer);
137 <% unless object_zoom %>
139 var bbox = new OpenLayers.Bounds(<%= minlon %>, <%= minlat %>, <%= maxlon %>, <%= maxlat %>);
144 // IE requires Vector layers be initialised on page load, and not under deferred script conditions
145 Event.observe(window, 'load', function() { addBoxToMap(bbox) });
148 var centre = new OpenLayers.LonLat(<%= lon %>, <%= lat %>);
149 var zoom = <%= zoom %>;
151 <% if params['scale'] and params['scale'].length > 0 then %>
152 zoom = scaleToZoom(<%= params['scale'].to_f() %>);
155 setMapCenter(centre, zoom);
161 <% if !layers.nil? and !layers.empty? %>
162 setMapLayers("<%= layers %>");
166 marker = addMarkerToMap(new OpenLayers.LonLat(<%= mlon %>, <%= mlat %>));
170 var url = "/api/<%= "#{API_VERSION}" %>/<%= object_type %>/<%= object_id %>";
172 <% if object_type != "node" %>
176 // IE requires Vector layers be initialised on page load, and not under deferred script conditions
177 Event.observe(window, 'load', function() { addObjectToMap(url, <%= object_zoom %>) });
180 map.events.register("moveend", map, updateLocation);
181 map.events.register("changelayer", map, updateLocation);
186 function toggleData() {
187 if (map.dataLayer.visibility) {
188 <%= remote_function :url => { :controller => 'browse', :action => 'start' } %>
189 } else if (map.dataLayer.active) {
194 function getPosition() {
195 return getMapCenter();
202 function setPosition(lat, lon, zoom, min_lon, min_lat, max_lon, max_lat) {
203 var centre = new OpenLayers.LonLat(lon, lat);
205 if (min_lon && min_lat && max_lon && max_lat) {
206 var bbox = new OpenLayers.Bounds(min_lon, min_lat, max_lon, max_lat);
210 setMapCenter(centre, zoom);
214 removeMarkerFromMap(marker);
216 marker = addMarkerToMap(centre, getArrowIcon());
219 function updateLocation() {
220 var lonlat = getMapCenter();
221 var zoom = map.getZoom();
222 var layers = getMapLayers();
223 var extents = getMapExtent();
224 var expiry = new Date();
229 objtype = "<%= object_type %>";
230 objid = <%= object_id %>;
233 updatelinks(lonlat.lon, lonlat.lat, zoom, layers, extents.left, extents.bottom, extents.right, extents.top, objtype, objid);
235 expiry.setYear(expiry.getFullYear() + 10);
236 document.cookie = "_osm_location=" + lonlat.lon + "|" + lonlat.lat + "|" + zoom + "|" + layers + "; expires=" + expiry.toGMTString();
239 function resizeContent() {
240 var content = $("content");
241 var rightMargin = parseInt(getStyle(content, "right"));
242 var bottomMargin = parseInt(getStyle(content, "bottom"));
244 content.style.width = document.documentElement.clientWidth - content.offsetLeft - rightMargin;
245 content.style.height = document.documentElement.clientHeight - content.offsetTop - bottomMargin;
248 function resizeMap() {
249 var centre = map.getCenter();
250 var zoom = map.getZoom();
251 var sidebar_width = $("sidebar").offsetWidth;
253 if (sidebar_width > 0) {
254 sidebar_width = sidebar_width + 5
257 $("map").style.left = (sidebar_width) + "px";
258 $("map").style.width = ($("content").offsetWidth - sidebar_width) + "px";
259 $("map").style.height = ($("content").offsetHeight - 2) + "px";
261 map.setCenter(centre, zoom);
264 function handleResize() {
265 if (brokenContentSize) {
272 function remoteEditHandler(event) {
273 var extent = getMapExtent();
276 $("linkloader").observe("load", function () { loaded = true; });
277 $("linkloader").src = "http://127.0.0.1:8111/load_and_zoom?left=" + extent.left + "&top=" + extent.top + "&right=" + extent.right + "&bottom=" + extent.bottom;
279 setTimeout(function () {
280 if (!loaded) alert("<%= escape_javascript(t('site.index.remote_failed')) %>");
286 function installEditHandler() {
287 $("remoteanchor").observe("click", remoteEditHandler);
289 <% if preferred_editor == "remote" %>
290 $("editanchor").observe("click", remoteEditHandler);
292 <% if params[:action] == "edit" %>
300 Event.observe(window, "load", installEditHandler);
301 Event.observe(window, "load", handleResize);
302 Event.observe(window, "resize", handleResize);
304 <% if params['action'] == 'export' %>
305 <%= remote_function :url => { :controller => 'export', :action => 'start' } %>