Commit crschmdt's data browser patch.

This commit is contained in:
Tom Hughes 2008-04-20 12:20:23 +00:00
parent 093aea72bd
commit db30a423a8
9 changed files with 101 additions and 2 deletions

View file

@ -0,0 +1,34 @@
class BrowseController < ApplicationController
before_filter :authorize_web
layout 'site'
def way_view
begin
way = Way.find(params[:id])
@way = way
@name = @way.tags['name'].to_s
if @name.length == 0:
@name = "#" + @way.id.to_s
end
@title = 'Way | ' + (@name)
rescue ActiveRecord::RecordNotFound
render :nothing => true, :status => :not_found
end
end
def node_view
begin
node = Node.find(params[:id])
@node = node
@name = @node.tags_as_hash['name'].to_s
if @name.length == 0:
@name = "#" + @node.id.to_s
end
@title = 'Node | ' + (@name)
rescue ActiveRecord::RecordNotFound
render :nothing => true, :status => :not_found
end
end
end

View file

@ -0,0 +1,9 @@
<%= render :partial => 'map', :locals => { :type => type, :id => obj.id } %>
<ul>
<li><%= link_to h("API"), :controller => "api/#{API_VERSION}/"+type, :id => obj.id %></li>
<li><%= link_to h("History"), :controller => "api/#{API_VERSION}/"+type, :id => obj.id, :action => "history" %></li>
</ul>
Last edited: <%= h(obj.timestamp) %><% if obj.user.data_public %>,
by <%= link_to h(obj.user.display_name), :controller => 'user', :action => 'view' , :display_name => obj.user.display_name %>
<% end %>

View file

@ -0,0 +1,32 @@
<%= javascript_include_tag '/openlayers/OpenLayers.js' %>
<%= javascript_include_tag '/openlayers/OpenStreetMap.js' %>
<%= javascript_include_tag 'map.js' %>
<div style="float:right">
<div id="small_map" style="width:250px; height: 300px; border: solid 1px black">
</div>
<script type="text/javascript">
function init() {
var obj_type = '<%= type %>';
var obj_id = <%= id %>;
var url = "/api/<%= "#{API_VERSION}" %>/<%= type %>/<%= id %>";
if (obj_type == "way") {
url += "/full";
}
var map = createMap('small_map', {controls: [new OpenLayers.Control.Navigation()]});
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() {
$("loading").innerHTML = "";
this.map.zoomToExtent( this.features[0].geometry.getBounds());
var center = map.getCenter().clone().transform(this.map.getProjectionObject(), new OpenLayers.Projection("EPSG:4326"));
$("larger_map").href = '/?lat='+center.lat+'&lon='+center.lon+'&zoom='+this.map.getZoom();
$("larger_map").innerHTML = "View Larger Map";
})
map.addLayer(osm_layer);
osm_layer.loadGML();
osm_layer.loaded = true;
}
window.onload = init;
</script>
<span id="loading">Loading...</span>
<a id="larger_map" href=""></a>
</div>

View file

@ -0,0 +1,4 @@
<tr>
<td><%= h(tag[0]) %></td><td><%= h(tag[1]) %></td>
</tr>

View file

@ -0,0 +1,9 @@
<% if tags.length != 0 %>
<table id="keyvalue" cellpadding="3">
<tr>
<th>Key</th>
<th>Value</th>
</tr>
<%= render :partial => 'tag', :collection => tags %>
</table>
<% end %>

View file

@ -0,0 +1,3 @@
<h2>Node Browser: <%= h(@name) %></h2>
<%= render :partial => 'common', :locals => { :obj => @node, :type => "node" } %>
<%= render :partial => 'tag_table', :locals => { :tags => @node.tags_as_hash } %>

View file

@ -0,0 +1,3 @@
<h2>Way Browser: <%= h(@name) %></h2>
<%= render :partial => 'common', :locals => { :obj => @way, :type => "way" } %>
<%= render :partial => 'tag_table', :locals => { :tags => @way.tags } %>

View file

@ -54,6 +54,10 @@ ActionController::Routing::Routes.draw do |map|
map.connect "api/#{API_VERSION}/amf", :controller =>'amf', :action =>'talk'
map.connect "api/#{API_VERSION}/swf/trackpoints", :controller =>'swf', :action =>'trackpoints'
# Data browsing
map.connect '/way/:id', :controller => 'browse', :action => 'way_view', :id => /\d+/
map.connect '/node/:id', :controller => 'browse', :action => 'node_view', :id => /\d+/
# web site
map.connect '/', :controller => 'site', :action => 'index'

View file

@ -7,9 +7,10 @@ OpenLayers._getScriptLocation = function () {
return "/openlayers/";
}
function createMap(divName) {
function createMap(divName, options) {
if (!options) { options = {} }
map = new OpenLayers.Map(divName, {
controls: [
controls: options.controls || [
new OpenLayers.Control.ArgParser(),
new OpenLayers.Control.Attribution(),
new OpenLayers.Control.LayerSwitcher(),