diff options
Diffstat (limited to 'app')
| -rw-r--r-- | app/assets/javascripts/public/journey_pattern.js.coffee | 19 | ||||
| -rw-r--r-- | app/assets/stylesheets/journey_patterns.css.scss | 6 | ||||
| -rw-r--r-- | app/controllers/journey_patterns_controller.rb | 9 | ||||
| -rw-r--r-- | app/helpers/journey_patterns_helper.rb | 14 | ||||
| -rw-r--r-- | app/maps/journey_pattern_map.rb | 40 | ||||
| -rw-r--r-- | app/maps/style_map/journey_pattern_style_map.rb | 47 | ||||
| -rw-r--r-- | app/views/journey_patterns/_stop_points_detail.html.erb | 10 | ||||
| -rw-r--r-- | app/views/journey_patterns/show.html.erb | 17 | ||||
| -rw-r--r-- | app/views/journey_patterns/show.js.erb | 4 | ||||
| -rw-r--r-- | app/views/journey_patterns/show.kml.erb | 19 |
10 files changed, 162 insertions, 23 deletions
diff --git a/app/assets/javascripts/public/journey_pattern.js.coffee b/app/assets/javascripts/public/journey_pattern.js.coffee new file mode 100644 index 000000000..6ea0c01de --- /dev/null +++ b/app/assets/javascripts/public/journey_pattern.js.coffee @@ -0,0 +1,19 @@ +jQuery -> + select_stop_on_map = (event) -> + if (event.type == 'mouseenter') + if event.target.id.match(/^stop_point_(\w+)$/) + stopAreaId = $("#"+event.target.id+" a").attr('href').match(/\d+$/)[0] + placeMark = selectFeature.layer.getFeatureByFid( stopAreaId) + selectFeature.unselectAll() + selectFeature.select( placeMark) + else + selectFeature.unselectAll() + + $('.journey_patterns.show div.stop_points .stop_point').live("hover", select_stop_on_map) + + make_ajax_pagination = () -> + $.get(this.href, null, null, 'script') + false + + $('.stop_points_detail .pagination a').live("click", make_ajax_pagination) + diff --git a/app/assets/stylesheets/journey_patterns.css.scss b/app/assets/stylesheets/journey_patterns.css.scss index 186bfd8f4..0e9113f41 100644 --- a/app/assets/stylesheets/journey_patterns.css.scss +++ b/app/assets/stylesheets/journey_patterns.css.scss @@ -22,6 +22,10 @@ .summary p label { font-weight: bold; } + + .stop_points_detail div.page_info { + margin-top: 0px; + } .stop_point:after { @include after_div_for_object; @@ -44,7 +48,7 @@ .stop_point { @include div_for_object; /* to create multi-column index */ - width: 350px; + width: 250px; float: left; padding-right: 10px; diff --git a/app/controllers/journey_patterns_controller.rb b/app/controllers/journey_patterns_controller.rb index 6b8855dc1..377ddf7c8 100644 --- a/app/controllers/journey_patterns_controller.rb +++ b/app/controllers/journey_patterns_controller.rb @@ -2,7 +2,8 @@ class JourneyPatternsController < ChouetteController defaults :resource_class => Chouette::JourneyPattern respond_to :html - respond_to :js, :only => [:new_vehicle_journey] + respond_to :js, :only => [:new_vehicle_journey, :show] + respond_to :kml, :only => :show belongs_to :referential do belongs_to :line, :parent_class => Chouette::Line do @@ -11,6 +12,7 @@ class JourneyPatternsController < ChouetteController end alias_method :route, :parent + alias_method :journey_pattern, :resource def index index! do |format| @@ -23,8 +25,8 @@ class JourneyPatternsController < ChouetteController end def show - #@map = RouteMap.new(route).with_helpers(self) - @stop_points = resource.stop_points.paginate(:page => params[:page]) + @map = JourneyPatternMap.new(journey_pattern).with_helpers(self) + @stop_points = journey_pattern.stop_points.paginate(:page => params[:page]) show! end @@ -33,4 +35,5 @@ class JourneyPatternsController < ChouetteController @vehicle_journey.update_journey_pattern(resource) render "vehicle_journeys/select_journey_pattern" end + end diff --git a/app/helpers/journey_patterns_helper.rb b/app/helpers/journey_patterns_helper.rb index bcfb71cd1..6897b88c9 100644 --- a/app/helpers/journey_patterns_helper.rb +++ b/app/helpers/journey_patterns_helper.rb @@ -13,5 +13,19 @@ module JourneyPatternsHelper "#{journey_pattern.human_attribute_name(:stop_point_ids)}. #{t('journey_patterns.form.warning', :count => journey_pattern.vehicle_journeys.count)}" end + def icon_code(stop_point, journey) + code = "stop_area" + if stop_point.stop_area.id == journey.route.stop_areas.first.id + code << "_green" + elsif stop_point.stop_area.id == journey.route.stop_areas.last.id + code << "_red" + else + code << "_black" + end + unless journey.stop_points.include?( stop_point) + code << "_unselected" + end + code + end end diff --git a/app/maps/journey_pattern_map.rb b/app/maps/journey_pattern_map.rb new file mode 100644 index 000000000..d690b3212 --- /dev/null +++ b/app/maps/journey_pattern_map.rb @@ -0,0 +1,40 @@ +class JourneyPatternMap < ApplicationMap + + attr_reader :journey_pattern, :style + + def initialize(journey_pattern, style = nil) + @journey_pattern = journey_pattern + @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)) + layer = kml_layer([journey_pattern.referential, journey_pattern.route.line, journey_pattern.route, journey_pattern], :styleMap => StyleMap::JourneyPatternStyleMap.new.style_map) + page.assign "journeyPatternLayer", layer + + selectFeature = OpenLayers::Control::SelectFeature.new( :journeyPatternLayer) + page.assign "selectFeature", selectFeature + + page << map.add_layer( :journeyPatternLayer) + page << map.add_control( hover_control_display_name(:journeyPatternLayer) ) + page << map.zoom_to_extent(bounds.to_google.to_openlayers) if bounds + end + end + + def ready? + bounds.present? + end + + def bounds + @bounds ||= journey_pattern.route.geometry.bounds + end + +end + diff --git a/app/maps/style_map/journey_pattern_style_map.rb b/app/maps/style_map/journey_pattern_style_map.rb new file mode 100644 index 000000000..c0d08ba77 --- /dev/null +++ b/app/maps/style_map/journey_pattern_style_map.rb @@ -0,0 +1,47 @@ +class StyleMap::JourneyPatternStyleMap < StyleMap::GenericStyleMap + attr_accessor :style + + def initialize(options = {}) + @style = options[:style].present? ? default_style.merge(options[:style]) : default_style + end + + def select_style + default_style.merge :externalGraphic => "/assets/icons/stop_area_hover.png" + 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/icons/${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.iconCode != undefined) {return feature.attributes.iconCode;} else { return '';} } " + } + end + + def style_map + OpenLayers::StyleMap.new(:default => OpenLayers::Style.new(style, { :context => context}), :select => OpenLayers::Style.new(style.merge( select_style), { :context => context})) + end + +end + diff --git a/app/views/journey_patterns/_stop_points_detail.html.erb b/app/views/journey_patterns/_stop_points_detail.html.erb new file mode 100644 index 000000000..6c9e4afae --- /dev/null +++ b/app/views/journey_patterns/_stop_points_detail.html.erb @@ -0,0 +1,10 @@ + <div class="page_info"> + <span class="search"> <%= t("will_paginate.page_entries_info.list") %></span> <%= page_entries_info @stop_points %> + </div> + <div class="stop_points paginated_content"> + <%= render :partial => "stop_points/stop_point", :collection => @stop_points %> + </div> + <div class="pagination"> + <%= will_paginate @stop_points, :container => false %> + </div> + diff --git a/app/views/journey_patterns/show.html.erb b/app/views/journey_patterns/show.html.erb index 9962e4d8b..507a71cca 100644 --- a/app/views/journey_patterns/show.html.erb +++ b/app/views/journey_patterns/show.html.erb @@ -1,6 +1,7 @@ <%= title_tag t('journey_patterns.show.title', :journey_pattern => journey_name( @journey_pattern), :route => @route.name ) %> -<div class="route_show"> +<div class="journey_pattern_show"> + <%= @map.to_html %> <div class="summary"> <p> @@ -39,18 +40,10 @@ </div> +<p class="after_map" /> <h3 class="journey_pattern_stop_points"><%= t('.stop_points') %></h3> -<div class="pagination"> - <div class="page_info"> - <%= page_entries_info @stop_points %> - </div> - <%= will_paginate @stop_points, :container => false %> -</div> -<div class="stop_points paginated_content"> - <%= render :partial => "stop_points/stop_point", :collection => @stop_points %> -</div> -<div class="pagination"> - <%= will_paginate @stop_points, :container => false %> +<div class="stop_points_detail" > + <%= render :partial => "stop_points_detail" %> </div> <% content_for :sidebar do %> diff --git a/app/views/journey_patterns/show.js.erb b/app/views/journey_patterns/show.js.erb new file mode 100644 index 000000000..aedb0fb9e --- /dev/null +++ b/app/views/journey_patterns/show.js.erb @@ -0,0 +1,4 @@ +$(function (){ + $(".stop_points_detail").html("<%= escape_javascript(render(:partial => "stop_points_detail")) %>"); +}); + diff --git a/app/views/journey_patterns/show.kml.erb b/app/views/journey_patterns/show.kml.erb index e08eb2255..75ca50ab5 100644 --- a/app/views/journey_patterns/show.kml.erb +++ b/app/views/journey_patterns/show.kml.erb @@ -3,18 +3,23 @@ <Document> <Placemark id="route_<%= @journey_pattern.id %>" > <name><%= @journey_pattern.name %></name> - <%= @journey_pattern.geometry.kml_representation.html_safe %> + <inactive>true</inactive> + <%= @journey_pattern.route.geometry.kml_representation.html_safe %> </Placemark> - <% @journey_pattern.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==@journey_pattern.stop_areas.first.id %> + <% @journey_pattern.route.stop_points.each_with_index do |stop_point, index| %> + <% if stop_point.stop_area.geometry %> + <Placemark id="<%= stop_point.stop_area.id %>" > + <name><%= "#{stop_point.stop_area.name} (#{index+1})" %></name> + <stop><%= @journey_pattern.stop_points.include?( stop_point) ? "true" : "false" %></stop> + <% if stop_point.stop_area.id==@route.stop_areas.first.id %> <departure>true</departure> - <% elsif stop_area.id==@journey_pattern.stop_areas.last.id %> + <% elsif stop_point.stop_area.id==@route.stop_areas.last.id %> <arrival>true</arrival> <% end %> - <%= stop_area.geometry.kml_representation.html_safe %> + <iconCode><%= icon_code(stop_point, @journey_pattern)%></iconCode> + <%= stop_point.stop_area.geometry.kml_representation.html_safe %> </Placemark> + <% end %> <% end %> </Document> </kml> |
