]> git.openstreetmap.org Git - rails.git/commitdiff
Add relation browsing:
authorChristopher Schmidt <crschmidt@crschmidt.net>
Sun, 20 Apr 2008 14:24:42 +0000 (14:24 +0000)
committerChristopher Schmidt <crschmidt@crschmidt.net>
Sun, 20 Apr 2008 14:24:42 +0000 (14:24 +0000)
 * Improve map to also work for relations
 * Add display of relations (view)
 * Add relation members display
 * add new view to browse_controller

app/controllers/browse_controller.rb
app/views/browse/_map.rhtml
app/views/browse/_member.rhtml [new file with mode: 0644]
app/views/browse/_relation_members.rhtml [new file with mode: 0644]
app/views/browse/_tag_table.rhtml
app/views/browse/relation_view.rhtml [new file with mode: 0644]

index c35bb821a00e587b23da28457778faac762992b9..1806558f2d43146747f4ab068bcd7c7f42fcac12 100644 (file)
@@ -2,6 +2,21 @@ class BrowseController < ApplicationController
   before_filter :authorize_web  
   layout 'site'
 
+  def relation_view 
+    begin
+      @relation = Relation.find(params[:id])
+     
+      @name = @relation.tags['name'].to_s 
+      if @name.length == 0:
+       @name = "#" + @relation.id.to_s
+      end
+       
+      @title = 'Relation | ' + (@name)
+    rescue ActiveRecord::RecordNotFound
+      render :nothing => true, :status => :not_found
+    end
+  end
+  
   def way_view 
     begin
       @way = Way.find(params[:id])
index a90a3fffd5a6710c3c306271d9379df70b31e862..466c9b6cc488729605bcb4fb7ff09047def892ad 100644 (file)
@@ -9,17 +9,25 @@
   var obj_type = '<%= type %>';
   var obj_id = <%= id %>;
   var url = "/api/<%= "#{API_VERSION}" %>/<%= type %>/<%= id %>";
-  if (obj_type == "way") {
+  if (obj_type != "node") {
     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 = getMapCenter();
-    $("larger_map").href = '/?lat='+center.lat+'&lon='+center.lon+'&zoom='+this.map.getZoom();
-    $("larger_map").innerHTML = "View Larger Map";
+    $("loading").innerHTML = "";
+    if (this.features.length) { 
+        var extent =  this.features[0].geometry.getBounds();
+        for (var i = 1; i < this.features.length; i++) {
+            extent.extend(this.features[i].geometry.getBounds());
+        }
+        this.map.zoomToExtent(extent);
+        var center = getMapCenter();
+        $("larger_map").href = '/?lat='+center.lat+'&lon='+center.lon+'&zoom='+this.map.getZoom();
+        $("larger_map").innerHTML = "View Larger Map";
+    } else {
+        $("small_map").style.display = "none";
+    }
   })   
   map.addLayer(osm_layer);
   osm_layer.loadGML();
diff --git a/app/views/browse/_member.rhtml b/app/views/browse/_member.rhtml
new file mode 100644 (file)
index 0000000..f3b6cf0
--- /dev/null
@@ -0,0 +1,7 @@
+<% if member.member.visible %>
+<tr>
+  <td><%= h(member.member.id.to_s) %></td>
+  <td><%= h(member.member_type) %></td>
+  <td><%= h(member.member_role) %></td>
+</tr> 
+<% end %>
diff --git a/app/views/browse/_relation_members.rhtml b/app/views/browse/_relation_members.rhtml
new file mode 100644 (file)
index 0000000..0e77721
--- /dev/null
@@ -0,0 +1,11 @@
+<% if relation.members.length != 0 %>
+<h3>Members</h3> 
+<table id="keyvalue" cellpadding="3">
+  <tr>
+    <th>ID</th>
+    <th>Type</th>
+    <th>Role</th>
+  </tr>
+  <%= render :partial => 'member', :collection => relation.relation_members  %>
+</table>
+<% end %>
index 9b87234cd38ac8f0e8d2a4a8e1aeebb7a70e758c..dca1c0ab1a755ac86c58d9043e37171ae15ac44f 100644 (file)
@@ -1,4 +1,5 @@
 <% if tags.length != 0 %>
+<h3>Tags</h3>
 <table id="keyvalue" cellpadding="3">
   <tr>
     <th>Key</th>
diff --git a/app/views/browse/relation_view.rhtml b/app/views/browse/relation_view.rhtml
new file mode 100644 (file)
index 0000000..c75e485
--- /dev/null
@@ -0,0 +1,4 @@
+<h2>Relation Browser: <%= h(@name) %></h2>
+<%= render :partial => 'common', :locals => { :obj => @relation, :type => "relation" } %>
+<%= render :partial => 'tag_table', :locals => { :tags => @relation.tags } %>
+<%= render :partial => 'relation_members', :locals => { :relation => @relation } %>