]> git.openstreetmap.org Git - rails.git/commitdiff
Introducing a new /browse/{node,way,relation,changeset}/{id}/map page
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>
Sat, 27 Jun 2009 09:30:10 +0000 (09:30 +0000)
committerÆvar Arnfjörð Bjarmason <avarab@gmail.com>
Sat, 27 Jun 2009 09:30:10 +0000 (09:30 +0000)
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.

app/controllers/browse_controller.rb
app/views/browse/_big_map.html.erb [new file with mode: 0644]
app/views/browse/_map.html.erb
app/views/browse/changeset_map.html.erb [new file with mode: 0644]
app/views/browse/node_map.html.erb [new file with mode: 0644]
app/views/browse/relation_map.html.erb [new file with mode: 0644]
app/views/browse/way_map.html.erb [new file with mode: 0644]
config/locales/en.yml
config/locales/is.yml
config/routes.rb

index 8124d4a339ec2d509ff29e2fdffc9fa2cf7039f0..4de490b2cf84a5c35d77bf27313c808a13aef5ce 100644 (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
diff --git a/app/views/browse/_big_map.html.erb b/app/views/browse/_big_map.html.erb
new file mode 100644 (file)
index 0000000..3290170
--- /dev/null
@@ -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 %>
index 7c242d861d6d529a0a22f48023fe41ec2a2aa66b..9a150ae05f7b9fe672408fc2cadc24478d3132d7 100644 (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 %>
 
         $("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 %>;
             }
 
             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";
           }
diff --git a/app/views/browse/changeset_map.html.erb b/app/views/browse/changeset_map.html.erb
new file mode 100644 (file)
index 0000000..8c3bdbe
--- /dev/null
@@ -0,0 +1,5 @@
+<%
+@name = printable_name @changeset
+@title = t('browse.changeset.map_title', :name => @name)
+%>
+<%= render :partial => "big_map", :object => @changeset %>
diff --git a/app/views/browse/node_map.html.erb b/app/views/browse/node_map.html.erb
new file mode 100644 (file)
index 0000000..4404e0c
--- /dev/null
@@ -0,0 +1,5 @@
+<%
+@name = printable_name @node
+@title = t('browse.node.map_title', :name => @name)
+%>
+<%= render :partial => "big_map", :object => @node %>
diff --git a/app/views/browse/relation_map.html.erb b/app/views/browse/relation_map.html.erb
new file mode 100644 (file)
index 0000000..15f0013
--- /dev/null
@@ -0,0 +1,5 @@
+<%
+@name = printable_name @relation
+@title = t('browse.relation.map_title', :name => @name)
+%>
+<%= render :partial => "big_map", :object => @relation %>
diff --git a/app/views/browse/way_map.html.erb b/app/views/browse/way_map.html.erb
new file mode 100644 (file)
index 0000000..2b4d8b2
--- /dev/null
@@ -0,0 +1,5 @@
+<%
+@name = printable_name @way
+@title = t('browse.way.map_title', :name => @name)
+%>
+<%= render :partial => "big_map", :object => @way %>
index f8dc9535f3cc6d7725867baf51b938536f01241c..b475335d5e24306d9f192d6aff746d20df0accf7 100644 (file)
@@ -79,6 +79,7 @@ en:
   browse:
     changeset:
       title: "Changeset"
+      map_title: "Changeset | {{name}}"
       changeset: "Changeset:"
       download: "Download {{changeset_xml_link}} or {{osmchange_xml_link}}"
       changesetxml: "Changeset XML"
@@ -106,6 +107,7 @@ en:
       loading: "Loading..."
       deleted: "Deleted"
       view_larger_map: "View Larger Map"
+      view_main_map: "View on main map"
     node_details:
       coordinates: "Coordinates: "
       part_of: "Part of:"
@@ -117,6 +119,7 @@ en:
       view_details: "view details"
     node:
       node: "Node"
+      map_title: "Node | {{name}}"
       node_title: "Node: {{node_name}}"
       download: "{{download_xml_link}}, {{view_history_link}} or {{edit_link}}"
       download_xml: "Download XML"
@@ -141,6 +144,7 @@ en:
       as: "as"
     relation:
       relation: "Relation"
+      map_title: "Relation | {{name}}"
       relation_title: "Relation: {{relation_name}}"
       download: "{{download_xml_link}} or {{view_history_link}}"
       download_xml: "Download XML"
@@ -199,6 +203,7 @@ en:
       view_details: "view details"
     way:
       way: "Way"
+      map_title: "Way | {{name}}"
       way_title: "Way: {{way_name}}"
       download: "{{download_xml_link}}, {{view_history_link}} or {{edit_link}}"
       download_xml: "Download XML"
index 883621ff18fc08da5774f6739a20982c5d88f744..88412a6e9ae23e63dc93afd826f367b911b2dd16 100644 (file)
@@ -79,6 +79,7 @@ is:
   browse:
     changeset:
       title: "Breytingarsett"
+      map_title: "Breytingarsett | {{name}}"
       changeset: "Breytingarsett:"
       download: "Niðurhala breytingunni á {{changeset_xml_link}} eða á {{osmchange_xml_link}}"
       changesetxml: "Breytingarsetts XML sniði"
@@ -110,6 +111,7 @@ is:
       loading: "Hleð..."
       deleted: "Eytt"
       view_larger_map: "Skoða á stærra korti"
+      view_main_map: "Skoða á aðalkorti"
     node_details:
       coordinates: "Hnit: "
       part_of: "Hluti af:"
@@ -121,6 +123,7 @@ is:
       view_details: "sýna breytingarsögu"
     node:
       node: "Hnútur"
+      map_title: "Hnútur | {{name}}"
       node_title: "Hnútur: {{node_name}}"
       download: "{{download_xml_link}} eða {{view_history_link}} eða {{edit_link}}"
       download_xml: "Hala niður á XML sniði"
@@ -145,6 +148,7 @@ is:
       as: "sem"
     relation:
       relation: "Vensl"
+      map_title: "Vensl | {{name}}"
       relation_title: "Vensl: {{relation_name}}"
       download: "{{download_xml_link}} eða {{view_history_link}}"
       download_xml: "Hala niður á XML sniði"
@@ -202,6 +206,7 @@ is:
       view_details: "sýna breytingarsögu"
     way:
       way: "Vegur"
+      map_title: "Vegur | {{name}}"
       way_title: "Vegur: {{way_name}}"
       download: "{{download_xml_link}} eða {{view_history_link}} eða {{edit_link}}"
       download_xml: "Hala niður á XML sniði"
index 6dd3860dcf0f74221afeea9446bb9253280ece5a..8ca792a614977f1c730106126f32b8f831f566e3 100644 (file)
@@ -76,12 +76,16 @@ ActionController::Routing::Routes.draw do |map|
   map.connect '/browse', :controller => 'changeset', :action => 'list'
   map.connect '/browse/start', :controller => 'browse', :action => 'start'
   map.connect '/browse/way/:id', :controller => 'browse', :action => 'way', :id => /\d+/
+  map.connect '/browse/way/:id/map', :controller => 'browse', :action => 'way_map', :id => /\d+/
   map.connect '/browse/way/:id/history', :controller => 'browse', :action => 'way_history', :id => /\d+/
   map.connect '/browse/node/:id', :controller => 'browse', :action => 'node', :id => /\d+/
+  map.connect '/browse/node/:id/map', :controller => 'browse', :action => 'node_map', :id => /\d+/
   map.connect '/browse/node/:id/history', :controller => 'browse', :action => 'node_history', :id => /\d+/
   map.connect '/browse/relation/:id', :controller => 'browse', :action => 'relation', :id => /\d+/
+  map.connect '/browse/relation/:id/map', :controller => 'browse', :action => 'relation_map', :id => /\d+/
   map.connect '/browse/relation/:id/history', :controller => 'browse', :action => 'relation_history', :id => /\d+/
   map.connect '/browse/changeset/:id', :controller => 'browse', :action => 'changeset', :id => /\d+/
+  map.connect '/browse/changeset/:id/map', :controller => 'browse', :action => 'changeset_map', :id => /\d+/
   map.connect '/browse/changesets', :controller => 'changeset', :action => 'list'
   
   # web site