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><br/>
22 <a href="/" id="shortlinkanchor"><%= t 'site.index.shortlink' %></a>
23 <a href="#" id="createnoteanchor">Report a problem</a>
27 <iframe id="linkloader" style="display: none">
30 <div id="attribution">
33 <td class="attribution_license"><%= t'site.index.license.license_url' %></td>
34 <td class="attribution_project"><%= t'site.index.license.project_url' %></td>
37 <td colspan="2" class="attribution_notice"><%=
38 t'site.index.license.notice',
39 :license_name => t('site.index.license.license_name'),
40 :project_name => t('site.index.license.project_name')
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 <%= javascript_include_tag 'openlayers.js' %>
125 <%= javascript_include_tag 'map.js' %>
127 <%= render :partial => 'resize' %>
129 <script type="text/javascript">
133 OpenLayers.Lang.setCode("<%= I18n.locale.to_s %>");
136 var loginName = "<%= @user.display_name %>"
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' %>", { "visibility": false });
144 map.dataLayer.events.register("visibilitychanged", map.dataLayer, toggleData);
145 map.addLayer(map.dataLayer);
147 map.noteLayer = new OpenLayers.Layer.Vector("Notes", {
149 projection: new OpenLayers.Projection("EPSG:4326"),
150 styleMap: new OpenLayers.StyleMap(new OpenLayers.Style({
158 new OpenLayers.Rule({
159 filter: new OpenLayers.Filter.Comparison({
160 type: OpenLayers.Filter.Comparison.EQUAL_TO,
165 externalGraphic: "<%= image_path 'open_note_marker.png' %>"
168 new OpenLayers.Rule({
169 filter: new OpenLayers.Filter.Comparison({
170 type: OpenLayers.Filter.Comparison.EQUAL_TO,
175 externalGraphic: "<%= image_path 'closed_note_marker.png' %>"
181 new OpenLayers.Strategy.BBOX()
183 protocol: new OpenLayers.Protocol.HTTP({
184 url: "<%= url_for :controller => :note, :action => :list, :format => :json %>",
185 format: new OpenLayers.Format.GeoJSON(),
186 callback: noteCallback
189 map.noteLayer.events.register("featureselected", map, noteSelected);
190 map.noteLayer.events.register("featureunselected", map, noteUnselected);
191 map.addLayer(map.noteLayer);
193 map.noteControl = new OpenLayers.Control.SelectFeature(map.noteLayer, {
196 map.addControl(map.noteControl);
198 <% if params[:notes] == "yes" -%>
199 map.noteLayer.setVisibility(true);
202 $("#createnoteanchor").click(addNote);
204 map.events.register("zoomend", map, allowNoteReports);
207 <% unless object_zoom %>
209 var bbox = new OpenLayers.Bounds(<%= minlon %>, <%= minlat %>, <%= maxlon %>, <%= maxlat %>);
214 $(window).load(function() { addBoxToMap(bbox) });
217 var centre = new OpenLayers.LonLat(<%= lon %>, <%= lat %>);
218 var zoom = <%= zoom %>;
220 <% if params[:scale] and params[:scale].length > 0 then %>
221 zoom = scaleToZoom(<%= params[:scale].to_f %>);
224 setMapCenter(centre, zoom);
228 <% if !layers.nil? and !layers.empty? %>
229 setMapLayers("<%= layers %>");
233 marker = addMarkerToMap(new OpenLayers.LonLat(<%= mlon %>, <%= mlat %>));
237 var url = "/api/<%= "#{API_VERSION}" %>/<%= object_type %>/<%= object_id %>";
239 <% if object_type != "node" %>
243 $(window).load(function() { addObjectToMap(url, <%= object_zoom %>) });
246 map.events.register("moveend", map, updateLocation);
247 map.events.register("changelayer", map, updateLocation);
253 function toggleData() {
254 if (map.dataLayer.visibility) {
255 $.ajax({ url: "<%= url_for :controller => :browse, :action => :start %>" });
256 } else if (map.dataLayer.active) {
261 function getPosition() {
262 return getMapCenter();
269 function setPosition(lat, lon, zoom, min_lon, min_lat, max_lon, max_lat) {
270 var centre = new OpenLayers.LonLat(lon, lat);
272 if (min_lon && min_lat && max_lon && max_lat) {
273 var bbox = new OpenLayers.Bounds(min_lon, min_lat, max_lon, max_lat);
277 setMapCenter(centre, zoom);
281 removeMarkerFromMap(marker);
283 marker = addMarkerToMap(centre, getArrowIcon());
286 function updateLocation() {
287 var lonlat = getMapCenter();
288 var zoom = map.getZoom();
289 var layers = getMapLayers();
290 var extents = getMapExtent();
291 var expiry = new Date();
296 objtype = "<%= object_type %>";
297 objid = <%= object_id %>;
300 updatelinks(lonlat.lon, lonlat.lat, zoom, layers, extents.left, extents.bottom, extents.right, extents.top, objtype, objid);
302 expiry.setYear(expiry.getFullYear() + 10);
303 document.cookie = "_osm_location=" + lonlat.lon + "|" + lonlat.lat + "|" + zoom + "|" + layers + "; expires=" + expiry.toGMTString();
306 function remoteEditHandler(event) {
307 var extent = getMapExtent();
310 $("#linkloader").load(function () { loaded = true; });
311 $("#linkloader").attr("src", "http://127.0.0.1:8111/load_and_zoom?left=" + extent.left + "&top=" + extent.top + "&right=" + extent.right + "&bottom=" + extent.bottom);
313 setTimeout(function () {
314 if (!loaded) alert("<%=j t('site.index.remote_failed') %>");
320 function installEditHandler() {
321 $("#remoteanchor").click(remoteEditHandler);
323 <% if preferred_editor == "remote" %>
324 $("#editanchor").click(remoteEditHandler);
326 <% if params[:action] == "edit" %>
332 function noteCallback(scope, response) {
333 for (var f = 0; f < response.features.length; f++) {
334 var feature = response.features[f];
338 function noteSelected(o) {
339 var feature = o.feature;
340 var location = feature.geometry.getBounds().getCenterLonLat();
342 feature.popup = new OpenLayers.Popup.FramedCloud(
343 feature.attributes.id, location, null,
344 "<p>" + feature.attributes.id + "</p>",
345 null, true, function (e) { map.noteControl.unselect(feature) }
348 map.addPopup(feature.popup);
349 // feature.popup.show();
352 function noteUnselected(o) {
353 var feature = o.feature;
355 map.removePopup(feature.popup);
356 delete feature.popup;
360 map.noteLayer.setVisibility(true);
361 map.noteLayer.addNote(map.getCenter());
364 function allowNoteReports() {
365 if (map.getZoom() > 11) {
366 $("#createnoteanchor").show();
368 $("#createnoteanchor").hide();
372 $(document).ready(mapInit);
373 $(document).ready(installEditHandler);
374 $(document).ready(handleResize);
376 $(window).resize(function() {
377 var centre = map.getCenter();
378 var zoom = map.getZoom();
382 map.setCenter(centre, zoom);
385 $(document).ready(function () {
386 $("#exportanchor").click(function (e) {
387 $.ajax({ url: "<%= url_for :controller => :export, :action => :start %>" });
391 <% if params[:action] == 'export' -%>
392 $.ajax({ url: "<%= url_for :controller => :export, :action => :start %>" });
395 <% if params[:query] -%>
396 doSearch("<%= params[:query] %>");