1 <% if @user and !@user.home_lon.nil? and !@user.home_lat.nil? %>
2 <% content_for :greeting do %>
3 <%= link_to t("layouts.home"), "#", :class => "set_position", :data => { :lat => @user.home_lat, :lon => @user.home_lon, :zoom => 15 }, :title => t("layouts.home_tooltip") %> |
7 <% unless STATUS == :api_offline or STATUS == :database_offline -%>
8 <% content_for :editmenu do -%>
9 <li><%= link_to t("browse.start_rjs.data_layer_name"), { :controller => :browse, :action => :start }, :id => "show_data" %></li>
13 <%= render :partial => 'sidebar' %>
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"><%= t'site.index.license.copyright' %></td>
47 if params[:mlon] and params[:mlat]
49 mlon = params[:mlon].to_f
50 mlat = params[:mlat].to_f
53 if params[:node] or params[:way] or params[:relation]
59 object_id = params[:node].to_i
62 object_id = params[:way].to_i
63 elsif params[:relation]
64 object_type = 'relation'
65 object_id = params[:relation].to_i
69 # Decide on a lat lon to initialise the map with. Various ways of doing this
72 minlon, minlat, maxlon, maxlat = params[:bbox].split(",").collect { |c| c.to_f }
73 layers = params[:layers]
74 box = true if params[:box] == "yes"
76 elsif params[:minlon] and params[:minlat] and params[:maxlon] and params[:maxlat]
78 minlon = params[:minlon].to_f
79 minlat = params[:minlat].to_f
80 maxlon = params[:maxlon].to_f
81 maxlat = params[:maxlat].to_f
82 layers = params[:layers]
83 box = true if params[:box]=="yes"
85 elsif params[:lon] and params[:lat]
86 lon = params[:lon].to_f
87 lat = params[:lat].to_f
88 zoom = params.fetch(:zoom, 5).to_i
89 layers = params[:layers]
91 elsif params[:mlon] and params[:mlat]
92 lon = params[:mlon].to_f
93 lat = params[:mlat].to_f
94 zoom = params.fetch(:zoom, 12).to_i
95 layers = params[:layers]
97 elsif cookies.key?("_osm_location")
98 lon,lat,zoom,layers = cookies["_osm_location"].split("|")
99 elsif @user and !@user.home_lon.nil? and !@user.home_lat.nil?
104 unless STATUS == :database_readonly or STATUS == :database_offline
105 session[:location] = OSM::IPLocation(request.env['REMOTE_ADDR']) unless session[:location]
108 if session[:location]
110 minlon = session[:location][:minlon]
111 minlat = session[:location][:minlat]
112 maxlon = session[:location][:maxlon]
113 maxlat = session[:location][:maxlat]
117 zoom = params.fetch(:zoom, 5).to_i
120 layers = params[:layers]
124 <script type="text/javascript">
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' %>", {
134 displayInLayerSwitcher: false
136 map.addLayer(map.dataLayer);
139 <% unless object_zoom %>
141 var bbox = new OpenLayers.Bounds(<%= minlon %>, <%= minlat %>, <%= maxlon %>, <%= maxlat %>);
143 map.zoomToExtent(proj(bbox));
146 $(window).load(function() { addBoxToMap(bbox) });
149 var centre = new OpenLayers.LonLat(<%= lon %>, <%= lat %>);
150 <% if params[:scale].to_f > 0 then -%>
151 var zoom = <%= scale_to_zoom params[:scale] %>;
153 var zoom = <%= zoom %>;
156 setMapCenter(centre, zoom);
160 <% if !layers.nil? and !layers.empty? %>
161 setMapLayers("<%= layers %>");
165 marker = addMarkerToMap(new OpenLayers.LonLat(<%= mlon %>, <%= mlat %>));
169 var url = "/api/<%= "#{API_VERSION}" %>/<%= object_type %>/<%= object_id %>";
171 <% if object_type != "node" %>
175 $(window).load(function() { addObjectToMap(url, <%= object_zoom %>) });
178 map.events.register("moveend", map, updateLocation);
179 map.events.register("changelayer", map, updateLocation);
185 $(document).ready(function () {
186 $("#show_data").click(function (e) {
187 $.ajax({ url: $(this).attr('href'), success: function (sidebarHtml) {
188 startBrowse(sidebarHtml);
193 $("body").on("click", "a.set_position", function () {
194 var lat = parseFloat($(this).attr("data-lat"));
195 var lon = parseFloat($(this).attr("data-lon"));
196 var zoom = parseInt($(this).attr("data-zoom"));
197 var min_lon = parseFloat($(this).attr("data-min-lon"));
198 var min_lat = parseFloat($(this).attr("data-min-lat"));
199 var max_lon = parseFloat($(this).attr("data-max-lon"));
200 var max_lat = parseFloat($(this).attr("data-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());
221 function updateLocation() {
222 var lonlat = unproj(map.getCenter());
223 var zoom = map.getZoom();
224 var layers = getMapLayers();
225 var extents = unproj(map.getExtent());
226 var expiry = new Date();
231 objtype = "<%= object_type %>";
232 objid = <%= object_id %>;
235 updatelinks(lonlat.lon, lonlat.lat, zoom, layers, extents.left, extents.bottom, extents.right, extents.top, objtype, objid);
237 expiry.setYear(expiry.getFullYear() + 10);
238 document.cookie = "_osm_location=" + lonlat.lon + "|" + lonlat.lat + "|" + zoom + "|" + layers + "; expires=" + expiry.toGMTString();
241 function remoteEditHandler(event) {
242 var extent = unproj(map.getExtent());
245 $("#linkloader").load(function () { loaded = true; });
246 $("#linkloader").attr("src", "http://127.0.0.1:8111/load_and_zoom?left=" + extent.left + "&top=" + extent.top + "&right=" + extent.right + "&bottom=" + extent.bottom);
248 setTimeout(function () {
249 if (!loaded) alert("<%=j t('site.index.remote_failed') %>");
255 function installEditHandler() {
256 $("#remoteanchor").click(remoteEditHandler);
258 <% if preferred_editor == "remote" %>
259 $("#editanchor").click(remoteEditHandler);
261 <% if params[:action] == "edit" %>
267 $(document).ready(mapInit);
268 $(document).ready(installEditHandler);
269 $(document).ready(handleResize);
271 $(window).resize(function() {
272 var centre = map.getCenter();
273 var zoom = map.getZoom();
277 map.setCenter(centre, zoom);
280 $(document).ready(function () {
281 $("#exportanchor").click(function (e) {
282 $.ajax({ url: "<%= url_for :controller => :export, :action => :start %>", success: function (sidebarHtml) {
283 startExport(sidebarHtml);
288 <% if params[:export] -%>
289 $("#exportanchor").click();
292 <% if params[:query] -%>
293 doSearch("<%= params[:query] %>");