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', :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 <%= render :partial => 'resize' %>
130 <script type="text/javascript">
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' %>", {
140 displayInLayerSwitcher: false
142 map.addLayer(map.dataLayer);
145 <% unless object_zoom %>
147 var bbox = new OpenLayers.Bounds(<%= minlon %>, <%= minlat %>, <%= maxlon %>, <%= maxlat %>);
149 map.zoomToExtent(proj(bbox));
152 $(window).load(function() { addBoxToMap(bbox) });
155 var centre = new OpenLayers.LonLat(<%= lon %>, <%= lat %>);
156 <% if params[:scale].to_f > 0 then -%>
157 var zoom = <%= scale_to_zoom params[:scale] %>;
159 var zoom = <%= zoom %>;
162 setMapCenter(centre, zoom);
166 <% if !layers.nil? and !layers.empty? %>
167 setMapLayers("<%= layers %>");
171 marker = addMarkerToMap(new OpenLayers.LonLat(<%= mlon %>, <%= mlat %>));
175 var url = "/api/<%= "#{API_VERSION}" %>/<%= object_type %>/<%= object_id %>";
177 <% if object_type != "node" %>
181 $(window).load(function() { addObjectToMap(url, <%= object_zoom %>) });
184 map.events.register("moveend", map, updateLocation);
185 map.events.register("changelayer", map, updateLocation);
191 $(document).ready(function () {
192 $("#show_data").click(function (e) {
193 $.ajax({ url: $(this).attr('href'), success: function (sidebarHtml) {
194 startBrowse(sidebarHtml);
199 $("body").on("click", "a.set_position", function () {
200 var lat = parseFloat($(this).attr("data-lat"));
201 var lon = parseFloat($(this).attr("data-lon"));
202 var zoom = parseInt($(this).attr("data-zoom"));
203 var min_lon = parseFloat($(this).attr("data-min-lon"));
204 var min_lat = parseFloat($(this).attr("data-min-lat"));
205 var max_lon = parseFloat($(this).attr("data-max-lon"));
206 var max_lat = parseFloat($(this).attr("data-max-lat"));
207 var centre = new OpenLayers.LonLat(lon, lat);
209 if (min_lon && min_lat && max_lon && max_lat) {
210 var bbox = new OpenLayers.Bounds(min_lon, min_lat, max_lon, max_lat);
212 map.zoomToExtent(proj(bbox));
214 setMapCenter(centre, zoom);
218 removeMarkerFromMap(marker);
221 marker = addMarkerToMap(centre, getArrowIcon());
227 function updateLocation() {
228 var lonlat = unproj(map.getCenter());
229 var zoom = map.getZoom();
230 var layers = getMapLayers();
231 var extents = unproj(map.getExtent());
232 var expiry = new Date();
237 objtype = "<%= object_type %>";
238 objid = <%= object_id %>;
241 updatelinks(lonlat.lon, lonlat.lat, zoom, layers, extents.left, extents.bottom, extents.right, extents.top, objtype, objid);
243 expiry.setYear(expiry.getFullYear() + 10);
244 document.cookie = "_osm_location=" + lonlat.lon + "|" + lonlat.lat + "|" + zoom + "|" + layers + "; expires=" + expiry.toGMTString();
247 function remoteEditHandler(event) {
248 var extent = unproj(map.getExtent());
251 $("#linkloader").load(function () { loaded = true; });
252 $("#linkloader").attr("src", "http://127.0.0.1:8111/load_and_zoom?left=" + extent.left + "&top=" + extent.top + "&right=" + extent.right + "&bottom=" + extent.bottom);
254 setTimeout(function () {
255 if (!loaded) alert("<%=j t('site.index.remote_failed') %>");
261 function installEditHandler() {
262 $("#remoteanchor").click(remoteEditHandler);
264 <% if preferred_editor == "remote" %>
265 $("#editanchor").click(remoteEditHandler);
267 <% if params[:action] == "edit" %>
273 $(document).ready(mapInit);
274 $(document).ready(installEditHandler);
275 $(document).ready(handleResize);
277 $(window).resize(function() {
278 var centre = map.getCenter();
279 var zoom = map.getZoom();
283 map.setCenter(centre, zoom);
286 $(document).ready(function () {
287 $("#exportanchor").click(function (e) {
288 $.ajax({ url: "<%= url_for :controller => :export, :action => :start %>", success: function (sidebarHtml) {
289 startExport(sidebarHtml);
294 <% if params[:action] == 'export' -%>
295 $("#exportanchor").click();
298 <% if params[:query] -%>
299 doSearch("<%= params[:query] %>");