Introducing a new /browse/{node,way,relation,changeset}/{id}/map page

which is slippy map covering the screen showing the map data that is
in the small map at /browse/{node,way,relation,changeset}/{id}.

/browse/{node,way,relation,changeset}/{id} now contains a link to both
"View Larger Map" which has been changed to link to this new map
feature, and "View on main map" which as before links to the area
showing the feature on the main slippy map.

/browse/{node,way,relation,changeset}/{id}/map supports permalinks
using its own hacked version of updateLocation() (which doesn't set a
cookie), but shortlinks are not supported. The Edit/History/Export
links link back to the main map.
This commit is contained in:
Ævar Arnfjörð Bjarmason 2009-06-27 09:30:10 +00:00
parent 77f971b79c
commit 8bc8e537b2
10 changed files with 192 additions and 2 deletions

View file

@ -25,6 +25,13 @@ class BrowseController < ApplicationController
@type = "relation"
render :action => "not_found", :status => :not_found
end
def relation_map
@relation = Relation.find(params[:id])
rescue ActiveRecord::RecordNotFound
@type = "relation"
render :action => "not_found", :status => :not_found
end
def way
@way = Way.find(params[:id], :include => [:way_tags, {:changeset => :user}, {:nodes => [:node_tags, {:ways => :way_tags}]}, :containing_relation_members])
@ -45,6 +52,13 @@ class BrowseController < ApplicationController
render :action => "not_found", :status => :not_found
end
def way_map
@way = Way.find(params[:id])
rescue ActiveRecord::RecordNotFound
@type = "way"
render :action => "not_found", :status => :not_found
end
def node
@node = Node.find(params[:id])
@next = Node.find(:first, :order => "id ASC", :conditions => [ "visible = true AND id > :id", { :id => @node.id }] )
@ -60,6 +74,13 @@ class BrowseController < ApplicationController
@type = "way"
render :action => "not_found", :status => :not_found
end
def node_map
@node = Node.find(params[:id])
rescue ActiveRecord::RecordNotFound
@type = "node"
render :action => "not_found", :status => :not_found
end
def changeset
@changeset = Changeset.find(params[:id])
@ -74,4 +95,11 @@ class BrowseController < ApplicationController
@type = "changeset"
render :action => "not_found", :status => :not_found
end
def changeset_map
@changeset = Changeset.find(params[:id])
rescue ActiveRecord::RecordNotFound
@type = "changeset"
render :action => "not_found", :status => :not_found
end
end

View file

@ -0,0 +1,119 @@
<%
# Decide on a lat lon to initialise the map with
if params['lon'] and params['lat']
lon = h(params['lon'])
lat = h(params['lat'])
zoom = h(params['zoom'] || '5')
layers = h(params['layers'])
end
%>
<%= javascript_include_tag '/openlayers/OpenLayers.js' %>
<%= javascript_include_tag '/openlayers/OpenStreetMap.js' %>
<%= javascript_include_tag 'map.js' %>
<td align="right">
<% if big_map.instance_of? Changeset or big_map.visible %>
<div id="big_map" style="right: 0; left: 0; bottom: 0; top: 0; position: absolute; border: solid 1px black">
<div id="permalink">
<a href="<%= url_for :controller => 'browse', :action => (big_map.class.to_s.downcase + '_map'), :id => big_map.id, :only_path => true %>" id="permalinkanchor"><%= t 'site.index.permalink' %></a><br/>
</div>
</div>
<% else %>
<%= t 'browse.map.deleted' %>
<% end %>
</td>
<% if big_map.instance_of? Changeset or big_map.visible %>
<script type="text/javascript">
var big_map;
OpenLayers.Lang.setCode("<%= I18n.locale.to_s %>");
/* A version of index.html.erb->updateLocation that doesn't set a cookie */
function updateBigmapLocation() {
var lonlat = getMapCenter();
var zoom = big_map.getZoom();
var layers = getMapLayers();
var extents = getMapExtent();
var expiry = new Date();
updatelinks(lonlat.lon, lonlat.lat, zoom, layers, extents.left, extents.bottom, extents.right, extents.top);
}
function init() {
big_map = createMap("big_map", {
controls: [
new OpenLayers.Control.ArgParser(),
new OpenLayers.Control.Attribution(),
new OpenLayers.Control.LayerSwitcher(),
new OpenLayers.Control.Navigation(),
new OpenLayers.Control.PanZoomBar(),
new OpenLayers.Control.ScaleLine()
]
});
<% if big_map.instance_of? Changeset %>
var minlon = <%= big_map.min_lon / GeoRecord::SCALE.to_f %>;
var minlat = <%= big_map.min_lat / GeoRecord::SCALE.to_f %>;
var maxlon = <%= big_map.max_lon / GeoRecord::SCALE.to_f %>;
var maxlat = <%= big_map.max_lat / GeoRecord::SCALE.to_f %>;
var bbox = new OpenLayers.Bounds(minlon, minlat, maxlon, maxlat);
<% if lat and lon and zoom %>
var center = new OpenLayers.LonLat(<%= lon %>, <%= lat %>);
var zoom = <%= zoom %>;
<% else %>
setMapExtent(bbox);
<% end %>
addBoxToMap(bbox);
<% if !layers.nil? and !layers.empty? %>
setMapLayers("<%= layers %>");
<% end %>
<% else %>
var obj_type = "<%= big_map.class.name.downcase %>";
var obj_id = <%= big_map.id %>;
var url = "/api/<%= "#{API_VERSION}" %>/<%= big_map.class.name.downcase %>/<%= big_map.id %>";
if (obj_type != "node") {
url += "/full";
}
var osm_layer = new OpenLayers.Layer.GML("OSM", url, {
format: OpenLayers.Format.OSM,
projection: new OpenLayers.Projection("EPSG:4326")
});
osm_layer.events.register("loadend", osm_layer, function() {
var extent = this.features[0].geometry.getBounds();
for (var i = 1; i < this.features.length; i++) {
extent.extend(this.features[i].geometry.getBounds());
}
<% if lat and lon and zoom %>
var center = new OpenLayers.LonLat(<%= lon %>, <%= lat %>);
var zoom = <%= zoom %>;
<% else %>
if (extent) {
this.map.zoomToExtent(extent);
} else {
this.map.zoomToMaxExtent();
}
<% end %>
var center = getMapCenter();
});
big_map.addLayer(osm_layer);
osm_layer.loadGML();
osm_layer.loaded = true;
<% end %>
big_map.events.register("moveend", big_map, updateBigmapLocation);
big_map.events.register("changelayer", big_map, updateBigmapLocation);
updateBigmapLocation();
}
window.onload = init;
</script>
<% end %>

View file

@ -7,6 +7,8 @@
</div>
<span id="loading"><%= t 'browse.map.loading' %></span>
<a id="larger_map" href=""></a>
<br />
<a id="main_map" href=""></a>
<% else %>
<%= t 'browse.map.deleted' %>
<% end %>
@ -32,8 +34,11 @@
$("loading").innerHTML = "";
$("larger_map").href = '/?minlon='+minlon+'&minlat='+minlat+'&maxlon='+maxlon+'&maxlat='+maxlat+'&box=yes';
$("larger_map").href = '<%= url_for :controller => 'browse', :action => (map.class.to_s.downcase + '_map'), :id => map.id, :only_path => true %>';
$("larger_map").innerHTML = "<%= t 'browse.map.view_larger_map' %>";
$("main_map").href = '/?minlon='+minlon+'&minlat='+minlat+'&maxlon='+maxlon+'&maxlat='+maxlat+'&box=yes';
$("main_map").innerHTML = "<%= t 'browse.map.view_main_map' %>";
<% else %>
var obj_type = "<%= map.class.name.downcase %>";
var obj_id = <%= map.id %>;
@ -65,8 +70,12 @@
}
var center = getMapCenter();
$("larger_map").href = '/?lat='+center.lat+'&lon='+center.lon+'&zoom='+this.map.getZoom();
$("larger_map").href = '<%= url_for :controller => 'browse', :action => (map.class.to_s.downcase + '_map'), :id => map.id, :only_path => true %>';
$("larger_map").innerHTML = "<%= t 'browse.map.view_larger_map' %>";
$("main_map").href = '/?lat='+center.lat+'&lon='+center.lon+'&zoom='+this.map.getZoom();
$("main_map").innerHTML = "<%= t 'browse.map.view_main_map' %>";
} else {
$("small_map").style.display = "none";
}

View file

@ -0,0 +1,5 @@
<%
@name = printable_name @changeset
@title = t('browse.changeset.map_title', :name => @name)
%>
<%= render :partial => "big_map", :object => @changeset %>

View file

@ -0,0 +1,5 @@
<%
@name = printable_name @node
@title = t('browse.node.map_title', :name => @name)
%>
<%= render :partial => "big_map", :object => @node %>

View file

@ -0,0 +1,5 @@
<%
@name = printable_name @relation
@title = t('browse.relation.map_title', :name => @name)
%>
<%= render :partial => "big_map", :object => @relation %>

View file

@ -0,0 +1,5 @@
<%
@name = printable_name @way
@title = t('browse.way.map_title', :name => @name)
%>
<%= render :partial => "big_map", :object => @way %>