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"), "#", :id => "show_data" %></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>
28 <a href="#" id="createnoteanchor">Report a problem</a>
32 <iframe id="linkloader" style="display: none">
35 <div id="attribution">
38 <td class="attribution_license"><%= t'site.index.license.license_url' %></td>
39 <td class="attribution_project"><%= t'site.index.license.project_url' %></td>
42 <td colspan="2" class="attribution_notice"><%=
43 t'site.index.license.notice',
44 :license_name => t('site.index.license.license_name'),
45 :project_name => t('site.index.license.project_name')
52 if params[:mlon] and params[:mlat]
54 mlon = params[:mlon].to_f
55 mlat = params[:mlat].to_f
58 if params[:node] or params[:way] or params[:relation]
64 object_id = params[:node].to_i
67 object_id = params[:way].to_i
68 elsif params[:relation]
69 object_type = 'relation'
70 object_id = params[:relation].to_i
74 # Decide on a lat lon to initialise the map with. Various ways of doing this
77 minlon, minlat, maxlon, maxlat = params[:bbox].split(",").collect { |c| c.to_f }
78 layers = params[:layers]
79 box = true if params[:box] == "yes"
81 elsif params[:minlon] and params[:minlat] and params[:maxlon] and params[:maxlat]
83 minlon = params[:minlon].to_f
84 minlat = params[:minlat].to_f
85 maxlon = params[:maxlon].to_f
86 maxlat = params[:maxlat].to_f
87 layers = params[:layers]
88 box = true if params[:box]=="yes"
90 elsif params[:lon] and params[:lat]
91 lon = params[:lon].to_f
92 lat = params[:lat].to_f
93 zoom = params.fetch(:zoom, 5).to_i
94 layers = params[:layers]
96 elsif params[:mlon] and params[:mlat]
97 lon = params[:mlon].to_f
98 lat = params[:mlat].to_f
99 zoom = params.fetch(:zoom, 12).to_i
100 layers = params[:layers]
102 elsif cookies.key?("_osm_location")
103 lon,lat,zoom,layers = cookies["_osm_location"].split("|")
104 elsif @user and !@user.home_lon.nil? and !@user.home_lat.nil?
109 unless STATUS == :database_readonly or STATUS == :database_offline
110 session[:location] = OSM::IPLocation(request.env['REMOTE_ADDR']) unless session[:location]
113 if session[:location]
115 minlon = session[:location][:minlon]
116 minlat = session[:location][:minlat]
117 maxlon = session[:location][:maxlon]
118 maxlat = session[:location][:maxlat]
122 zoom = params.fetch(:zoom, 5).to_i
125 layers = params[:layers]
129 <%= javascript_include_tag 'openlayers.js' %>
130 <%= javascript_include_tag 'map.js' %>
131 <%= javascript_include_tag 'notes.js' %>
133 <%= render :partial => 'resize' %>
135 <script type="text/javascript">
139 OpenLayers.Lang.setCode("<%= I18n.locale.to_s %>");
142 var loginName = "<%= @user.display_name %>"
146 map = createMap("map");
148 <% unless STATUS == :api_offline or STATUS == :database_offline %>
149 map.dataLayer = new OpenLayers.Layer("<%= I18n.t 'browse.start_rjs.data_layer_name' %>", {
151 displayInLayerSwitcher: false
153 map.addLayer(map.dataLayer);
155 var noteLayer = addNoteLayer(map, "<%= notes_url :format => 'json' %>", $("#createnoteanchor"), 11);
157 <% if params[:notes] == "yes" -%>
158 noteLayer.setVisibility(true);
162 <% unless object_zoom %>
164 var bbox = new OpenLayers.Bounds(<%= minlon %>, <%= minlat %>, <%= maxlon %>, <%= maxlat %>);
166 map.zoomToExtent(proj(bbox));
169 $(window).load(function() { addBoxToMap(bbox) });
172 var centre = new OpenLayers.LonLat(<%= lon %>, <%= lat %>);
173 <% if params[:scale].to_f > 0 then -%>
174 var zoom = <%= scale_to_zoom params[:scale] %>;
176 var zoom = <%= zoom %>;
179 setMapCenter(centre, zoom);
183 <% if !layers.nil? and !layers.empty? %>
184 setMapLayers("<%= layers %>");
188 marker = addMarkerToMap(new OpenLayers.LonLat(<%= mlon %>, <%= mlat %>));
192 var url = "/api/<%= "#{API_VERSION}" %>/<%= object_type %>/<%= object_id %>";
194 <% if object_type != "node" %>
198 $(window).load(function() { addObjectToMap(url, <%= object_zoom %>) });
201 map.events.register("moveend", map, updateLocation);
202 map.events.register("changelayer", map, updateLocation);
208 $(document).ready(function () {
209 $("#show_data").click(function () {
210 $.ajax({ url: "<%= url_for :controller => :browse, :action => :start %>" });
213 $("body").on("click", "a.set_position", function () {
214 var lat = parseFloat($(this).attr("data-lat"));
215 var lon = parseFloat($(this).attr("data-lon"));
216 var zoom = parseInt($(this).attr("data-zoom"));
217 var min_lon = parseFloat($(this).attr("data-min-lon"));
218 var min_lat = parseFloat($(this).attr("data-min-lat"));
219 var max_lon = parseFloat($(this).attr("data-max-lon"));
220 var max_lat = parseFloat($(this).attr("data-max-lat"));
221 var centre = new OpenLayers.LonLat(lon, lat);
223 if (min_lon && min_lat && max_lon && max_lat) {
224 var bbox = new OpenLayers.Bounds(min_lon, min_lat, max_lon, max_lat);
226 map.zoomToExtent(proj(bbox));
228 setMapCenter(centre, zoom);
232 removeMarkerFromMap(marker);
235 marker = addMarkerToMap(centre, getArrowIcon());
241 function updateLocation() {
242 var lonlat = unproj(map.getCenter());
243 var zoom = map.getZoom();
244 var layers = getMapLayers();
245 var extents = unproj(map.getExtent());
246 var expiry = new Date();
251 objtype = "<%= object_type %>";
252 objid = <%= object_id %>;
255 updatelinks(lonlat.lon, lonlat.lat, zoom, layers, extents.left, extents.bottom, extents.right, extents.top, objtype, objid);
257 expiry.setYear(expiry.getFullYear() + 10);
258 document.cookie = "_osm_location=" + lonlat.lon + "|" + lonlat.lat + "|" + zoom + "|" + layers + "; expires=" + expiry.toGMTString();
261 function remoteEditHandler(event) {
262 var extent = unproj(map.getExtent());
265 $("#linkloader").load(function () { loaded = true; });
266 $("#linkloader").attr("src", "http://127.0.0.1:8111/load_and_zoom?left=" + extent.left + "&top=" + extent.top + "&right=" + extent.right + "&bottom=" + extent.bottom);
268 setTimeout(function () {
269 if (!loaded) alert("<%=j t('site.index.remote_failed') %>");
275 function installEditHandler() {
276 $("#remoteanchor").click(remoteEditHandler);
278 <% if preferred_editor == "remote" %>
279 $("#editanchor").click(remoteEditHandler);
281 <% if params[:action] == "edit" %>
287 $(document).ready(mapInit);
288 $(document).ready(installEditHandler);
289 $(document).ready(handleResize);
291 $(window).resize(function() {
292 var centre = map.getCenter();
293 var zoom = map.getZoom();
297 map.setCenter(centre, zoom);
300 $(document).ready(function () {
301 $("#exportanchor").click(function (e) {
302 $.ajax({ url: "<%= url_for :controller => :export, :action => :start %>" });
306 <% if params[:action] == 'export' -%>
307 $.ajax({ url: "<%= url_for :controller => :export, :action => :start %>" });
310 <% if params[:query] -%>
311 doSearch("<%= params[:query] %>");