aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/controllers/connection_links_controller.rb2
-rw-r--r--app/controllers/journey_patterns_controller.rb3
-rw-r--r--app/controllers/lines_controller.rb2
-rw-r--r--app/controllers/networks_controller.rb2
-rw-r--r--app/controllers/routes_controller.rb2
-rw-r--r--app/controllers/stop_areas_controller.rb9
-rw-r--r--app/maps/application_map.rb51
-rw-r--r--app/maps/connection_link_map.rb15
-rw-r--r--app/maps/line_map.rb16
-rw-r--r--app/maps/network_map.rb13
-rw-r--r--app/maps/route_map.rb7
-rw-r--r--app/maps/stop_area_map.rb5
-rw-r--r--app/models/referential.rb12
-rw-r--r--spec/controllers/routes_controller_spec.rb3
14 files changed, 95 insertions, 47 deletions
diff --git a/app/controllers/connection_links_controller.rb b/app/controllers/connection_links_controller.rb
index 3da6b1417..ab5cbf8ef 100644
--- a/app/controllers/connection_links_controller.rb
+++ b/app/controllers/connection_links_controller.rb
@@ -9,7 +9,7 @@ class ConnectionLinksController < ChouetteController
respond_to :html, :xml, :json
def show
- @map = ConnectionLinkMap.new referential, resource
+ @map = ConnectionLinkMap.new(resource).with_helpers(self)
show!
end
diff --git a/app/controllers/journey_patterns_controller.rb b/app/controllers/journey_patterns_controller.rb
index d8611d6f9..fe1b601d4 100644
--- a/app/controllers/journey_patterns_controller.rb
+++ b/app/controllers/journey_patterns_controller.rb
@@ -13,13 +13,12 @@ class JourneyPatternsController < ChouetteController
alias_method :route, :parent
def show
- #@map = RouteMap.new referential, route
+ #@map = RouteMap.new(route).with_helpers(self)
@stop_points = resource.stop_points.paginate(:page => params[:page], :per_page => 10)
show!
end
def new_vehicle_journey
- puts resource.inspect
@vehicle_journey = Chouette::VehicleJourney.new(:route_id => route.id)
@vehicle_journey.update_journey_pattern(resource)
render "vehicle_journeys/select_journey_pattern"
diff --git a/app/controllers/lines_controller.rb b/app/controllers/lines_controller.rb
index e14baf211..57be0f6b3 100644
--- a/app/controllers/lines_controller.rb
+++ b/app/controllers/lines_controller.rb
@@ -7,7 +7,7 @@ class LinesController < ChouetteController
belongs_to :referential
def show
- @map = LineMap.new referential, resource
+ @map = LineMap.new(resource).with_helpers(self)
@routes = @line.routes
show!
end
diff --git a/app/controllers/networks_controller.rb b/app/controllers/networks_controller.rb
index ce65d158f..6522ad502 100644
--- a/app/controllers/networks_controller.rb
+++ b/app/controllers/networks_controller.rb
@@ -7,7 +7,7 @@ class NetworksController < ChouetteController
belongs_to :referential
def show
- @map = NetworkMap.new referential, resource
+ @map = NetworkMap.new(resource).with_helpers(self)
show!
end
diff --git a/app/controllers/routes_controller.rb b/app/controllers/routes_controller.rb
index fed76f23b..99b9899fa 100644
--- a/app/controllers/routes_controller.rb
+++ b/app/controllers/routes_controller.rb
@@ -15,7 +15,7 @@ class RoutesController < ChouetteController
end
def show
- @map = RouteMap.new referential, route
+ @map = RouteMap.new(route).with_helpers(self)
@stop_points = route.stop_points.paginate(:page => params[:page], :per_page => 10)
show!
end
diff --git a/app/controllers/stop_areas_controller.rb b/app/controllers/stop_areas_controller.rb
index 55bf713a7..8d68fd1d5 100644
--- a/app/controllers/stop_areas_controller.rb
+++ b/app/controllers/stop_areas_controller.rb
@@ -40,7 +40,7 @@ class StopAreasController < ChouetteController
end
def show
- @map = StopAreaMap.new referential, stop_area
+ map.editable = false
show! do |format|
unless stop_area.position or params[:default]
format.kml {
@@ -54,8 +54,7 @@ class StopAreasController < ChouetteController
def edit
stop_area.position ||= stop_area.default_position
- @map = StopAreaMap.new referential, stop_area
- @map.editable = true
+ map.editable = true
edit!
end
@@ -68,6 +67,10 @@ class StopAreasController < ChouetteController
alias_method :stop_area, :resource
+ def map
+ @map = StopAreaMap.new(stop_area).with_helpers(self)
+ end
+
def collection
@q = parent.present? ? parent.stop_areas.search(params[:q]) : referential.stop_areas.search(params[:q])
@stop_areas ||=
diff --git a/app/maps/application_map.rb b/app/maps/application_map.rb
index d7ee0b5a1..f1b1d103d 100644
--- a/app/maps/application_map.rb
+++ b/app/maps/application_map.rb
@@ -2,9 +2,27 @@ class ApplicationMap
include MapLayers
include MapLayers::ViewHelpers
- #delegate :url_helpers, :to => :'Rails.application.routes'
- include Rails.application.routes.url_helpers
-
+
+ attr_accessor :helpers
+
+ def helpers
+ @helper ||= Helpers.new
+ end
+
+ # For example, in a controller :
+ #
+ # @map = MyMap.new(...).with_helpers(self)
+ #
+ def with_helpers(helpers)
+ self.helpers = helpers
+ self
+ end
+
+ class Helpers
+ include ActionDispatch::Routing::UrlFor
+ include Rails.application.routes.url_helpers
+ end
+
def projection(name)
OpenLayers::Projection.new(name)
end
@@ -25,13 +43,10 @@ class ApplicationMap
@map ||= MapLayers::Map.new(id, :projection => projection("EPSG:900913"), :controls => controls)
end
- def default_class
- self.class.name.underscore.gsub(/_map$/, '')
- end
-
def name
self.class.name.underscore.gsub(/_map$/, '')
end
+ alias_method :default_class, :name
def to_html(options = {})
if not respond_to?(:ready?) or ready?
@@ -91,8 +106,26 @@ class ApplicationMap
} } )
end
- def kml_layer(url, options = {})
- url = polymorphic_path([url.referential, url], :format => :kml) unless String === url
+ def kml_layer(url_or_object, options_or_url_options = {}, options = nil)
+ unless options
+ url_options = {}
+ options = options_or_url_options
+ else
+ url_options = options_or_url_options
+ end
+
+ url_options = url_options.merge(:format => :kml)
+
+ url =
+ case url_or_object
+ when String
+ url_or_object
+ when Array
+ helpers.polymorphic_path(url_or_object, url_options)
+ else
+ helpers.polymorphic_path([url_or_object.referential, url_or_object], url_options)
+ end
+
protocol = OpenLayers::Protocol::HTTP.new :url => url, :format => kml
OpenLayers::Layer::Vector.new name, {:projection => projection("EPSG:4326"), :strategies => [strategy_fixed], :protocol => protocol, :displayInLayerSwitcher => false}.merge(options)
end
diff --git a/app/maps/connection_link_map.rb b/app/maps/connection_link_map.rb
index 897da8a5d..8071c5f0f 100644
--- a/app/maps/connection_link_map.rb
+++ b/app/maps/connection_link_map.rb
@@ -1,10 +1,9 @@
class ConnectionLinkMap < ApplicationMap
- attr_reader :referential, :connection_link, :connection_link_style
+ attr_reader :connection_link, :connection_link_style
- def initialize(referential, connection_link, connection_link_style = nil)
- @referential = referential
+ def initialize(connection_link, connection_link_style = nil)
@connection_link = connection_link
@connection_link_style = connection_link_style
end
@@ -17,7 +16,7 @@ class ConnectionLinkMap < ApplicationMap
page << map.add_layer(google_hybrid)
page << map.add_layer(google_satellite)
- page.assign "stop_areas_layer", kml_layer(polymorphic_path([referential, connection_link, :stop_areas], :format => :kml), :styleMap => StyleMap::StopAreasStyleMap.new.style_map)
+ page.assign "stop_areas_layer", kml_layer([connection_link.referential, connection_link, :stop_areas], :styleMap => StyleMap::StopAreasStyleMap.new.style_map)
page << map.add_layer(:stop_areas_layer)
page << map.add_control( hover_control_display_name(:stop_areas_layer) )
#page << map.add_layer(kml_layer(connection_link, :styleMap => StyleMap::ConnectionLinkStyleMap.new( :style => connection_link_style).style_map))
@@ -31,9 +30,11 @@ class ConnectionLinkMap < ApplicationMap
end
def bounds
- wgs84_bounds = Chouette::StopArea.bounds
- @bounds ||= OpenLayers::Bounds.new(wgs84_bounds.lower_corner.x, wgs84_bounds.lower_corner.y, wgs84_bounds.upper_corner.x, wgs84_bounds.upper_corner.y).transform(OpenLayers::Projection.new("EPSG:4326"), OpenLayers::Projection.new("EPSG:900913"))
-
+ @bounds ||=
+ begin
+ wgs84_bounds = Chouette::StopArea.bounds
+ OpenLayers::Bounds.new(wgs84_bounds.lower_corner.x, wgs84_bounds.lower_corner.y, wgs84_bounds.upper_corner.x, wgs84_bounds.upper_corner.y).transform(OpenLayers::Projection.new("EPSG:4326"), OpenLayers::Projection.new("EPSG:900913"))
+ end
end
end
diff --git a/app/maps/line_map.rb b/app/maps/line_map.rb
index 4d363b070..e451f452d 100644
--- a/app/maps/line_map.rb
+++ b/app/maps/line_map.rb
@@ -1,10 +1,9 @@
class LineMap < ApplicationMap
- attr_reader :referential, :line, :line_style
+ attr_reader :line, :line_style
- def initialize(referential, line, line_style = nil)
- @referential = referential
+ def initialize(line, line_style = nil)
@line = line
@line_style = line_style
end
@@ -18,7 +17,7 @@ class LineMap < ApplicationMap
page << map.add_layer(google_satellite)
#page << map.add_layer(kml_layer(line, :styleMap => StyleMap::LineStyleMap.new( :style => line_style).style_map))
- page.assign "stop_areas_layer", kml_layer(polymorphic_path([referential, line, :stop_areas], :format => :kml), :styleMap => StyleMap::StopAreasStyleMap.new.style_map)
+ page.assign "stop_areas_layer", kml_layer([line.referential, line, :stop_areas], :styleMap => StyleMap::StopAreasStyleMap.new.style_map)
page << map.add_layer(:stop_areas_layer)
page << map.add_control( hover_control_display_name(:stop_areas_layer) )
@@ -28,13 +27,16 @@ class LineMap < ApplicationMap
end
def bounds
- wgs84_bounds = Chouette::StopArea.bounds
- @bounds ||= OpenLayers::Bounds.new(wgs84_bounds.lower_corner.x, wgs84_bounds.lower_corner.y, wgs84_bounds.upper_corner.x, wgs84_bounds.upper_corner.y).transform(OpenLayers::Projection.new("EPSG:4326"), OpenLayers::Projection.new("EPSG:900913"))
+ @bounds ||=
+ begin
+ wgs84_bounds = GeoRuby::SimpleFeatures::Point.bounds(line.stop_areas.map(&:geometry))
+ OpenLayers::Bounds.new(wgs84_bounds.lower_corner.x, wgs84_bounds.lower_corner.y, wgs84_bounds.upper_corner.x, wgs84_bounds.upper_corner.y).transform(OpenLayers::Projection.new("EPSG:4326"), OpenLayers::Projection.new("EPSG:900913")) if wgs84_bounds
+ end
end
def ready?
- Chouette::StopArea.bounds.present?
+ bounds.present?
end
end
diff --git a/app/maps/network_map.rb b/app/maps/network_map.rb
index 760948a2a..cee54ed1b 100644
--- a/app/maps/network_map.rb
+++ b/app/maps/network_map.rb
@@ -2,8 +2,7 @@ class NetworkMap < ApplicationMap
attr_reader :referential, :network, :network_style
- def initialize(referential, network, network_style = nil)
- @referential = referential
+ def initialize(network, network_style = nil)
@network = network
@network_style = network_style
end
@@ -16,7 +15,7 @@ class NetworkMap < ApplicationMap
page << map.add_layer(google_hybrid)
page << map.add_layer(google_satellite)
- page.assign "stop_areas_layer", kml_layer(polymorphic_path([referential, network, :stop_areas], :format => :kml), :styleMap => StyleMap::StopAreasStyleMap.new.style_map)
+ page.assign "stop_areas_layer", kml_layer([network.referential, network, :stop_areas], :styleMap => StyleMap::StopAreasStyleMap.new.style_map)
page << map.add_layer(:stop_areas_layer)
page << map.add_control( hover_control_display_name(:stop_areas_layer) )
@@ -27,9 +26,11 @@ class NetworkMap < ApplicationMap
end
def bounds
- wgs84_bounds = Chouette::StopArea.bounds
- @bounds ||= OpenLayers::Bounds.new(wgs84_bounds.lower_corner.x, wgs84_bounds.lower_corner.y, wgs84_bounds.upper_corner.x, wgs84_bounds.upper_corner.y).transform(OpenLayers::Projection.new("EPSG:4326"), OpenLayers::Projection.new("EPSG:900913"))
-
+ @bounds ||=
+ begin
+ wgs84_bounds = Chouette::StopArea.bounds
+ OpenLayers::Bounds.new(wgs84_bounds.lower_corner.x, wgs84_bounds.lower_corner.y, wgs84_bounds.upper_corner.x, wgs84_bounds.upper_corner.y).transform(OpenLayers::Projection.new("EPSG:4326"), OpenLayers::Projection.new("EPSG:900913")) if wgs84_bounds
+ end
end
def ready?
diff --git a/app/maps/route_map.rb b/app/maps/route_map.rb
index 7cc525dde..c28c22e62 100644
--- a/app/maps/route_map.rb
+++ b/app/maps/route_map.rb
@@ -1,9 +1,8 @@
class RouteMap < ApplicationMap
- attr_reader :referential, :route, :style
+ attr_reader :route, :style
- def initialize(referential, route, style = nil)
- @referential = referential
+ def initialize(route, style = nil)
@route = route
@style = style
end
@@ -17,7 +16,7 @@ class RouteMap < ApplicationMap
page << map.add_layer(google_satellite)
#page << map.add_layer(kml_layer(line, :styleMap => StyleMap::LineStyleMap.new( :style => line_style).style_map))
- page << map.add_layer(kml_layer(polymorphic_path([referential, route.line, route], :format => :kml), :styleMap => StyleMap::RouteStyleMap.new.style_map))
+ page << map.add_layer(kml_layer([route.referential, route.line, route], :styleMap => StyleMap::RouteStyleMap.new.style_map))
page << map.zoom_to_extent(bounds) if bounds
end
end
diff --git a/app/maps/stop_area_map.rb b/app/maps/stop_area_map.rb
index b7c060dce..0e02654e9 100644
--- a/app/maps/stop_area_map.rb
+++ b/app/maps/stop_area_map.rb
@@ -5,8 +5,7 @@ class StopAreaMap < ApplicationMap
attr_accessor :editable
alias_method :editable?, :editable
- def initialize(referential, stop_area)
- @referential = referential
+ def initialize(stop_area)
@stop_area = stop_area
end
@@ -18,7 +17,7 @@ class StopAreaMap < ApplicationMap
page << map.add_layer(google_hybrid)
page << map.add_layer(google_satellite)
- page.assign "edit_stop_area_layer", kml_layer( polymorphic_path( [referential, stop_area], :format => :kml, :default => editable?), :style_map => StyleMap::EditStopAreaStyleMap.new.style_map)
+ page.assign "edit_stop_area_layer", kml_layer(stop_area, { :default => editable? }, :style_map => StyleMap::EditStopAreaStyleMap.new.style_map)
page << map.add_layer(:edit_stop_area_layer)
if editable?
diff --git a/app/models/referential.rb b/app/models/referential.rb
index 3f4a62bb6..639e4de12 100644
--- a/app/models/referential.rb
+++ b/app/models/referential.rb
@@ -65,3 +65,15 @@ class Referential < ActiveRecord::Base
end
end
+
+Rails.application.config.after_initialize do
+ Chouette::ActiveRecord
+ puts "patch Chouette::ActiveRecord (#{__FILE__})"
+ class Chouette::ActiveRecord
+
+ def referential
+ @referential ||= Referential.where(:slug => Apartment::Database.current_database).first!
+ end
+
+ end
+end
diff --git a/spec/controllers/routes_controller_spec.rb b/spec/controllers/routes_controller_spec.rb
index 9356e1a9a..e0485b77d 100644
--- a/spec/controllers/routes_controller_spec.rb
+++ b/spec/controllers/routes_controller_spec.rb
@@ -67,9 +67,8 @@ describe RoutesController do
it_behaves_like "route, line and referential linked"
- it "assigns RouteMap.new( referential, route) as @map" do
+ it "assigns RouteMap.new(route) as @map" do
assigns[:map].should be_an_instance_of(RouteMap)
- assigns[:map].referential.should == referential
assigns[:map].route.should == route
end