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 <%= 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" class="geolink llz layers object"><%= t 'site.index.permalink' %></a>
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 = params[:mlon].to_f
49 mlat = params[:mlat].to_f
52 if params[:node] or params[:way] or params[:relation]
58 object_id = params[:node].to_i
61 object_id = params[:way].to_i
62 elsif params[:relation]
63 object_type = 'relation'
64 object_id = params[:relation].to_i
68 # Decide on a lat lon to initialise the map with. Various ways of doing this
71 minlon, minlat, maxlon, maxlat = params[:bbox].split(",").collect { |c| c.to_f }
72 layers = params[:layers]
73 box = true if params[:box] == "yes"
75 elsif params[:minlon] and params[:minlat] and params[:maxlon] and params[:maxlat]
77 minlon = params[:minlon].to_f
78 minlat = params[:minlat].to_f
79 maxlon = params[:maxlon].to_f
80 maxlat = params[:maxlat].to_f
81 layers = params[:layers]
82 box = true if params[:box]=="yes"
84 elsif params[:lon] and params[:lat]
85 lon = params[:lon].to_f
86 lat = params[:lat].to_f
87 zoom = params.fetch(:zoom, 5).to_i
88 layers = params[:layers]
90 elsif params[:mlon] and params[:mlat]
91 lon = params[:mlon].to_f
92 lat = params[:mlat].to_f
93 zoom = params.fetch(:zoom, 12).to_i
94 layers = params[:layers]
96 elsif cookies.key?("_osm_location")
97 lon,lat,zoom,layers = cookies["_osm_location"].split("|")
98 elsif @user and !@user.home_lon.nil? and !@user.home_lat.nil?
103 unless STATUS == :database_readonly or STATUS == :database_offline
104 session[:location] = OSM::IPLocation(request.env['REMOTE_ADDR']) unless session[:location]
107 if session[:location]
109 minlon = session[:location][:minlon]
110 minlat = session[:location][:minlat]
111 maxlon = session[:location][:maxlon]
112 maxlat = session[:location][:maxlat]
116 zoom = params.fetch(:zoom, 5).to_i
119 layers = params[:layers]
123 <%= javascript_include_tag 'openlayers.js' %>
124 <%= javascript_include_tag 'map.js' %>
126 <%= render :partial => 'resize' %>
128 <script type="text/javascript">
132 OpenLayers.Lang.setCode("<%= I18n.locale.to_s %>");
135 map = createMap("map");
137 <% unless STATUS == :api_offline or STATUS == :database_offline %>
138 map.dataLayer = new OpenLayers.Layer("<%= I18n.t 'browse.start_rjs.data_layer_name' %>", { "visibility": false });
139 map.dataLayer.events.register("visibilitychanged", map.dataLayer, toggleData);
140 map.addLayer(map.dataLayer);
143 <% unless object_zoom %>
145 var bbox = new OpenLayers.Bounds(<%= minlon %>, <%= minlat %>, <%= maxlon %>, <%= maxlat %>);
147 map.zoomToExtent(proj(bbox));
150 $(window).load(function() { addBoxToMap(bbox) });
153 var centre = new OpenLayers.LonLat(<%= lon %>, <%= lat %>);
154 <% if params[:scale].to_f > 0 then -%>
155 var zoom = <%= scale_to_zoom params[:scale] %>;
157 var zoom = <%= zoom %>;
160 setMapCenter(centre, zoom);
164 <% if !layers.nil? and !layers.empty? %>
165 setMapLayers("<%= layers %>");
169 marker = addMarkerToMap(new OpenLayers.LonLat(<%= mlon %>, <%= mlat %>));
173 var url = "/api/<%= "#{API_VERSION}" %>/<%= object_type %>/<%= object_id %>";
175 <% if object_type != "node" %>
179 $(window).load(function() { addObjectToMap(url, <%= object_zoom %>) });
182 map.events.register("moveend", map, updateLocation);
183 map.events.register("changelayer", map, updateLocation);
189 function toggleData() {
190 if (map.dataLayer.visibility) {
191 $.ajax({ url: "<%= url_for :controller => :browse, :action => :start %>" });
192 } else if (map.dataLayer.active) {
197 function setPosition(lat, lon, zoom, min_lon, min_lat, max_lon, max_lat) {
198 var centre = new OpenLayers.LonLat(lon, lat);
200 if (min_lon && min_lat && max_lon && max_lat) {
201 var bbox = new OpenLayers.Bounds(min_lon, min_lat, max_lon, max_lat);
203 map.zoomToExtent(proj(bbox));
205 setMapCenter(centre, zoom);
209 removeMarkerFromMap(marker);
212 marker = addMarkerToMap(centre, getArrowIcon());
215 function updateLocation() {
216 var lonlat = unproj(map.getCenter());
217 var zoom = map.getZoom();
218 var layers = getMapLayers();
219 var extents = unproj(map.getExtent());
220 var expiry = new Date();
225 objtype = "<%= object_type %>";
226 objid = <%= object_id %>;
229 updatelinks(lonlat.lon, lonlat.lat, zoom, layers, extents.left, extents.bottom, extents.right, extents.top, objtype, objid);
231 expiry.setYear(expiry.getFullYear() + 10);
232 document.cookie = "_osm_location=" + lonlat.lon + "|" + lonlat.lat + "|" + zoom + "|" + layers + "; expires=" + expiry.toGMTString();
235 function remoteEditHandler(event) {
236 var extent = unproj(map.getExtent());
239 $("#linkloader").load(function () { loaded = true; });
240 $("#linkloader").attr("src", "http://127.0.0.1:8111/load_and_zoom?left=" + extent.left + "&top=" + extent.top + "&right=" + extent.right + "&bottom=" + extent.bottom);
242 setTimeout(function () {
243 if (!loaded) alert("<%=j t('site.index.remote_failed') %>");
249 function installEditHandler() {
250 $("#remoteanchor").click(remoteEditHandler);
252 <% if preferred_editor == "remote" %>
253 $("#editanchor").click(remoteEditHandler);
255 <% if params[:action] == "edit" %>
261 $(document).ready(mapInit);
262 $(document).ready(installEditHandler);
263 $(document).ready(handleResize);
265 $(window).resize(function() {
266 var centre = map.getCenter();
267 var zoom = map.getZoom();
271 map.setCenter(centre, zoom);
274 $(document).ready(function () {
275 $("#exportanchor").click(function (e) {
276 $.ajax({ url: "<%= url_for :controller => :export, :action => :start %>" });
280 <% if params[:action] == 'export' -%>
281 $.ajax({ url: "<%= url_for :controller => :export, :action => :start %>" });
284 <% if params[:query] -%>
285 doSearch("<%= params[:query] %>");