1 <% if @user and !@user.home_lon.nil? and !@user.home_lat.nil? %>
2 <% content_for :greeting do %>
3 <%= link_to_function t('layouts.home'), "setPosition(#{@user.home_lat}, #{@user.home_lon}, 15)", { :title => t('layouts.home_tooltip') } %> |
7 <% unless STATUS == :api_offline or STATUS == :database_offline -%>
8 <% content_for :editmenu do -%>
9 <li><%= link_to_function(t('browse.start_rjs.data_layer_name'), 'showData()') %></li>
13 <%= render :partial => 'sidebar', :locals => { :onopen => "resizeMap();", :onclose => "resizeMap();" } %>
14 <%= render :partial => 'key' %>
15 <%= render :partial => 'search' %>
19 <p><%= t 'site.index.js_1' %></p>
20 <p><%= t 'site.index.js_2' %></p>
26 <a href="/" id="permalinkanchor" class="geolink llz layers object"><%= t 'site.index.permalink' %></a>
27 <a href="/" id="shortlinkanchor"><%= t 'site.index.shortlink' %></a>
31 <iframe id="linkloader" style="display: none">
34 <div id="attribution">
37 <td class="attribution_license"><%= t'site.index.license.license_url' %></td>
38 <td class="attribution_project"><%= t'site.index.license.project_url' %></td>
41 <td colspan="2" class="attribution_notice"><%=
42 t'site.index.license.notice',
43 :license_name => t('site.index.license.license_name'),
44 :project_name => t('site.index.license.project_name')
51 if params[:mlon] and params[:mlat]
53 mlon = params[:mlon].to_f
54 mlat = params[:mlat].to_f
57 if params[:node] or params[:way] or params[:relation]
63 object_id = params[:node].to_i
66 object_id = params[:way].to_i
67 elsif params[:relation]
68 object_type = 'relation'
69 object_id = params[:relation].to_i
73 # Decide on a lat lon to initialise the map with. Various ways of doing this
76 minlon, minlat, maxlon, maxlat = params[:bbox].split(",").collect { |c| c.to_f }
77 layers = params[:layers]
78 box = true if params[:box] == "yes"
80 elsif params[:minlon] and params[:minlat] and params[:maxlon] and params[:maxlat]
82 minlon = params[:minlon].to_f
83 minlat = params[:minlat].to_f
84 maxlon = params[:maxlon].to_f
85 maxlat = params[:maxlat].to_f
86 layers = params[:layers]
87 box = true if params[:box]=="yes"
89 elsif params[:lon] and params[:lat]
90 lon = params[:lon].to_f
91 lat = params[:lat].to_f
92 zoom = params.fetch(:zoom, 5).to_i
93 layers = params[:layers]
95 elsif params[:mlon] and params[:mlat]
96 lon = params[:mlon].to_f
97 lat = params[:mlat].to_f
98 zoom = params.fetch(:zoom, 12).to_i
99 layers = params[:layers]
101 elsif cookies.key?("_osm_location")
102 lon,lat,zoom,layers = cookies["_osm_location"].split("|")
103 elsif @user and !@user.home_lon.nil? and !@user.home_lat.nil?
108 unless STATUS == :database_readonly or STATUS == :database_offline
109 session[:location] = OSM::IPLocation(request.env['REMOTE_ADDR']) unless session[:location]
112 if session[:location]
114 minlon = session[:location][:minlon]
115 minlat = session[:location][:minlat]
116 maxlon = session[:location][:maxlon]
117 maxlat = session[:location][:maxlat]
121 zoom = params.fetch(:zoom, 5).to_i
124 layers = params[:layers]
128 <%= javascript_include_tag 'openlayers.js' %>
129 <%= javascript_include_tag 'map.js' %>
131 <%= render :partial => 'resize' %>
133 <script type="text/javascript">
137 OpenLayers.Lang.setCode("<%= I18n.locale.to_s %>");
140 map = createMap("map");
142 <% unless STATUS == :api_offline or STATUS == :database_offline %>
143 map.dataLayer = new OpenLayers.Layer("<%= I18n.t 'browse.start_rjs.data_layer_name' %>", {
145 displayInLayerSwitcher: false
147 map.addLayer(map.dataLayer);
150 <% unless object_zoom %>
152 var bbox = new OpenLayers.Bounds(<%= minlon %>, <%= minlat %>, <%= maxlon %>, <%= maxlat %>);
154 map.zoomToExtent(proj(bbox));
157 $(window).load(function() { addBoxToMap(bbox) });
160 var centre = new OpenLayers.LonLat(<%= lon %>, <%= lat %>);
161 <% if params[:scale].to_f > 0 then -%>
162 var zoom = <%= scale_to_zoom params[:scale] %>;
164 var zoom = <%= zoom %>;
167 setMapCenter(centre, zoom);
171 <% if !layers.nil? and !layers.empty? %>
172 setMapLayers("<%= layers %>");
176 marker = addMarkerToMap(new OpenLayers.LonLat(<%= mlon %>, <%= mlat %>));
180 var url = "/api/<%= "#{API_VERSION}" %>/<%= object_type %>/<%= object_id %>";
182 <% if object_type != "node" %>
186 $(window).load(function() { addObjectToMap(url, <%= object_zoom %>) });
189 map.events.register("moveend", map, updateLocation);
190 map.events.register("changelayer", map, updateLocation);
196 function showData() {
197 $.ajax({ url: "<%= url_for :controller => :browse, :action => :start %>" });
200 function setPosition(lat, lon, zoom, min_lon, min_lat, max_lon, max_lat) {
201 var centre = new OpenLayers.LonLat(lon, lat);
203 if (min_lon && min_lat && max_lon && max_lat) {
204 var bbox = new OpenLayers.Bounds(min_lon, min_lat, max_lon, max_lat);
206 map.zoomToExtent(proj(bbox));
208 setMapCenter(centre, zoom);
212 removeMarkerFromMap(marker);
215 marker = addMarkerToMap(centre, getArrowIcon());
218 function updateLocation() {
219 var lonlat = unproj(map.getCenter());
220 var zoom = map.getZoom();
221 var layers = getMapLayers();
222 var extents = unproj(map.getExtent());
223 var expiry = new Date();
228 objtype = "<%= object_type %>";
229 objid = <%= object_id %>;
232 updatelinks(lonlat.lon, lonlat.lat, zoom, layers, extents.left, extents.bottom, extents.right, extents.top, objtype, objid);
234 expiry.setYear(expiry.getFullYear() + 10);
235 document.cookie = "_osm_location=" + lonlat.lon + "|" + lonlat.lat + "|" + zoom + "|" + layers + "; expires=" + expiry.toGMTString();
238 function remoteEditHandler(event) {
239 var extent = unproj(map.getExtent());
242 $("#linkloader").load(function () { loaded = true; });
243 $("#linkloader").attr("src", "http://127.0.0.1:8111/load_and_zoom?left=" + extent.left + "&top=" + extent.top + "&right=" + extent.right + "&bottom=" + extent.bottom);
245 setTimeout(function () {
246 if (!loaded) alert("<%=j t('site.index.remote_failed') %>");
252 function installEditHandler() {
253 $("#remoteanchor").click(remoteEditHandler);
255 <% if preferred_editor == "remote" %>
256 $("#editanchor").click(remoteEditHandler);
258 <% if params[:action] == "edit" %>
264 $(document).ready(mapInit);
265 $(document).ready(installEditHandler);
266 $(document).ready(handleResize);
268 $(window).resize(function() {
269 var centre = map.getCenter();
270 var zoom = map.getZoom();
274 map.setCenter(centre, zoom);
277 $(document).ready(function () {
278 $("#exportanchor").click(function (e) {
279 $.ajax({ url: "<%= url_for :controller => :export, :action => :start %>" });
283 <% if params[:action] == 'export' -%>
284 $.ajax({ url: "<%= url_for :controller => :export, :action => :start %>" });
287 <% if params[:query] -%>
288 doSearch("<%= params[:query] %>");