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>
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 $(document).ready(function () {
197 $("#show_data").click(function () {
198 $.ajax({ url: "<%= url_for :controller => :browse, :action => :start %>" });
201 $("body").on("click", "a.set_position", function () {
202 var lat = parseFloat($(this).attr("data-lat"));
203 var lon = parseFloat($(this).attr("data-lon"));
204 var zoom = parseInt($(this).attr("data-zoom"));
205 var min_lon = parseFloat($(this).attr("data-min-lon"));
206 var min_lat = parseFloat($(this).attr("data-min-lat"));
207 var max_lon = parseFloat($(this).attr("data-max-lon"));
208 var max_lat = parseFloat($(this).attr("data-max-lat"));
209 var centre = new OpenLayers.LonLat(lon, lat);
211 if (min_lon && min_lat && max_lon && max_lat) {
212 var bbox = new OpenLayers.Bounds(min_lon, min_lat, max_lon, max_lat);
214 map.zoomToExtent(proj(bbox));
216 setMapCenter(centre, zoom);
220 removeMarkerFromMap(marker);
223 marker = addMarkerToMap(centre, getArrowIcon());
229 function updateLocation() {
230 var lonlat = unproj(map.getCenter());
231 var zoom = map.getZoom();
232 var layers = getMapLayers();
233 var extents = unproj(map.getExtent());
234 var expiry = new Date();
239 objtype = "<%= object_type %>";
240 objid = <%= object_id %>;
243 updatelinks(lonlat.lon, lonlat.lat, zoom, layers, extents.left, extents.bottom, extents.right, extents.top, objtype, objid);
245 expiry.setYear(expiry.getFullYear() + 10);
246 document.cookie = "_osm_location=" + lonlat.lon + "|" + lonlat.lat + "|" + zoom + "|" + layers + "; expires=" + expiry.toGMTString();
249 function remoteEditHandler(event) {
250 var extent = unproj(map.getExtent());
253 $("#linkloader").load(function () { loaded = true; });
254 $("#linkloader").attr("src", "http://127.0.0.1:8111/load_and_zoom?left=" + extent.left + "&top=" + extent.top + "&right=" + extent.right + "&bottom=" + extent.bottom);
256 setTimeout(function () {
257 if (!loaded) alert("<%=j t('site.index.remote_failed') %>");
263 function installEditHandler() {
264 $("#remoteanchor").click(remoteEditHandler);
266 <% if preferred_editor == "remote" %>
267 $("#editanchor").click(remoteEditHandler);
269 <% if params[:action] == "edit" %>
275 $(document).ready(mapInit);
276 $(document).ready(installEditHandler);
277 $(document).ready(handleResize);
279 $(window).resize(function() {
280 var centre = map.getCenter();
281 var zoom = map.getZoom();
285 map.setCenter(centre, zoom);
288 $(document).ready(function () {
289 $("#exportanchor").click(function (e) {
290 $.ajax({ url: "<%= url_for :controller => :export, :action => :start %>" });
294 <% if params[:action] == 'export' -%>
295 $.ajax({ url: "<%= url_for :controller => :export, :action => :start %>" });
298 <% if params[:query] -%>
299 doSearch("<%= params[:query] %>");