diff options
| author | Marc Florisson | 2012-05-04 14:07:12 +0200 |
|---|---|---|
| committer | Marc Florisson | 2012-05-04 14:07:12 +0200 |
| commit | 09c55792e887dea709df29cae2e4fb8fbd86901c (patch) | |
| tree | 5ef824a3144995bd1ab552eea4c852b23f99c35f /app | |
| parent | ac3a3153fa18da97cc120703f9a62061a211b581 (diff) | |
| download | chouette-core-09c55792e887dea709df29cae2e4fb8fbd86901c.tar.bz2 | |
add map on route view
Diffstat (limited to 'app')
| -rw-r--r-- | app/assets/images/map/arrival.png | bin | 0 -> 598 bytes | |||
| -rw-r--r-- | app/assets/images/map/departure.png | bin | 0 -> 568 bytes | |||
| -rw-r--r-- | app/assets/images/map/interstop.png | bin | 0 -> 937 bytes | |||
| -rw-r--r-- | app/assets/stylesheets/routes.css.scss | 4 | ||||
| -rw-r--r-- | app/controllers/routes_controller.rb | 2 | ||||
| -rw-r--r-- | app/maps/route_map.rb | 35 | ||||
| -rw-r--r-- | app/maps/style_map/route_style_map.rb | 44 | ||||
| -rw-r--r-- | app/views/routes/show.html.erb | 5 | ||||
| -rw-r--r-- | app/views/routes/show.kml.erb | 21 |
9 files changed, 109 insertions, 2 deletions
diff --git a/app/assets/images/map/arrival.png b/app/assets/images/map/arrival.png Binary files differnew file mode 100644 index 000000000..844b8c6c6 --- /dev/null +++ b/app/assets/images/map/arrival.png diff --git a/app/assets/images/map/departure.png b/app/assets/images/map/departure.png Binary files differnew file mode 100644 index 000000000..22a3244ee --- /dev/null +++ b/app/assets/images/map/departure.png diff --git a/app/assets/images/map/interstop.png b/app/assets/images/map/interstop.png Binary files differnew file mode 100644 index 000000000..2fcd04b99 --- /dev/null +++ b/app/assets/images/map/interstop.png diff --git a/app/assets/stylesheets/routes.css.scss b/app/assets/stylesheets/routes.css.scss index c55a4646d..3e2e5b5ed 100644 --- a/app/assets/stylesheets/routes.css.scss +++ b/app/assets/stylesheets/routes.css.scss @@ -70,6 +70,10 @@ @include content_to_clear; } + .route_stop_areas { + clear: both; + } + .stop_area { @include div_for_object; /* to create multi-column index */ diff --git a/app/controllers/routes_controller.rb b/app/controllers/routes_controller.rb index 55a700315..2ed39b0ac 100644 --- a/app/controllers/routes_controller.rb +++ b/app/controllers/routes_controller.rb @@ -2,6 +2,7 @@ class RoutesController < ChouetteController defaults :resource_class => Chouette::Route respond_to :html, :xml, :json + respond_to :kml, :only => :show belongs_to :referential do belongs_to :line, :parent_class => Chouette::Line, :optional => true, :polymorphic => true @@ -14,6 +15,7 @@ class RoutesController < ChouetteController end def show + @map = RouteMap.new referential, resource @stop_areas = resource.stop_areas.paginate(:page => params[:page], :per_page => 10) show! end diff --git a/app/maps/route_map.rb b/app/maps/route_map.rb new file mode 100644 index 000000000..417b6037a --- /dev/null +++ b/app/maps/route_map.rb @@ -0,0 +1,35 @@ +class RouteMap < ApplicationMap + + attr_reader :referential, :route, :style + + def initialize(referential, route, style = nil) + @referential = referential + @route = route + @style = style + end + + def map + @map ||= MapLayers::Map.new(id, :projection => projection("EPSG:900913"), :controls => controls) do |map, page| + page << map.add_layer(MapLayers::OSM_MAPNIK) + page << map.add_layer(google_physical) + page << map.add_layer(google_streets) + page << map.add_layer(google_hybrid) + 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.zoom_to_extent(bounds) if bounds + end + end + + def bounds + wgs84_bounds = ( route.geometry.empty?) ? Chouette::StopArea.bounds : route.geometry.envelope + + @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 + diff --git a/app/maps/style_map/route_style_map.rb b/app/maps/style_map/route_style_map.rb new file mode 100644 index 000000000..136cecba5 --- /dev/null +++ b/app/maps/style_map/route_style_map.rb @@ -0,0 +1,44 @@ +class StyleMap::RouteStyleMap < StyleMap::GenericStyleMap + attr_accessor :style + + def initialize(options = {}) + @style = options[:style].present? ? default_style.merge(options[:style]) : default_style + end + + def default_style + { + :label => "${label}", + :fontColor => "black", + :fontSize => "11px", + :fontWeight => "bold", + :labelAlign => "ct", + :labelXOffset => 0, + :labelYOffset => -15, + :strokeColor => "#000000", + :strokeOpacity => 1, + :strokeWidth => 3, + :strokeLineCap => "round", + :strokeDashstyle => "solid", + :externalGraphic => "/assets/map/${positionType}.png", + :graphicWidth => 12, + :graphicHeight => 12, + :graphicOpacity => 1, + :graphicXOffset => -6, + :graphicYOffset => -6, + :display => true + } + end + + def context + context = { + :label => :" function(feature) {if(feature.layer.map.getZoom() > 13) { return feature.attributes.name;} else {return '';}} ", + :positionType => :" function(feature) { if (feature.attributes.departure != undefined) { return 'departure'; } else if (feature.attributes.arrival != undefined) { return 'arrival'; } else { return 'interstop'; }} " + } + end + + def style_map + OpenLayers::StyleMap.new(:default => OpenLayers::Style.new(style, { :context => context})) + end + +end + diff --git a/app/views/routes/show.html.erb b/app/views/routes/show.html.erb index 2b48f8829..15eb8780e 100644 --- a/app/views/routes/show.html.erb +++ b/app/views/routes/show.html.erb @@ -1,6 +1,7 @@ -<%= title_tag t('routes.show.title', :route => @route.name, :line => @line.name ) %> +<%= title_tag t('routes.show.title', :route => @route.name, :line => @route.line.name ) %> <div class="route_show"> + <%= @map.to_html.html_safe %> <div class="summary"> <p> @@ -63,7 +64,7 @@ </div> -<h3><%= t('.stop_areas') %></h3> +<h3 class="route_stop_areas"><%= t('.stop_areas') %></h3> <%= will_paginate @stop_areas %> <div class="stop_areas paginated_content"> <%= render :partial => "stop_areas/stop_area", :collection => @stop_areas %> diff --git a/app/views/routes/show.kml.erb b/app/views/routes/show.kml.erb new file mode 100644 index 000000000..4e90fa963 --- /dev/null +++ b/app/views/routes/show.kml.erb @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="UTF-8"?> +<kml xmlns="http://www.opengis.net/kml/2.2"> + <Document> + <Placemark id="route_<%= @route.id %>" > + <name><%= @route.name %></name> + <%= @route.geometry.kml_representation.html_safe %> + </Placemark> + <% @route.stop_areas.where("latitude is not null and longitude is not null").each_with_index do |stop_area, index| %> + <Placemark id="<%= stop_area.id %>" > + <name><%= "#{stop_area.name} (#{index+1})" %></name> + <% if stop_area.id==@route.stop_areas.first.id %> + <departure>true</departure> + <% elsif stop_area.id==@route.stop_areas.last.id %> + <arrival>true</arrival> + <% end %> + <%= stop_area.geometry.kml_representation.html_safe %> + </Placemark> + <% end %> + </Document> +</kml> + |
