diff options
| author | Michel Etienne | 2012-11-13 16:18:13 +0100 | 
|---|---|---|
| committer | Michel Etienne | 2012-11-13 16:18:13 +0100 | 
| commit | eeaf81e645de6f073b84b22b19e04ac63024399e (patch) | |
| tree | 5c0664cc51d2ad7d42ec8ff3322d540ac2413972 /app/maps | |
| parent | 0c9781ac6c9927c4631826c2319c0c14436587d6 (diff) | |
| download | chouette-core-eeaf81e645de6f073b84b22b19e04ac63024399e.tar.bz2 | |
add some features on maps
Diffstat (limited to 'app/maps')
| -rw-r--r-- | app/maps/access_link_map.rb | 37 | ||||
| -rw-r--r-- | app/maps/access_point_map.rb | 4 | ||||
| -rw-r--r-- | app/maps/stop_area_map.rb | 39 | ||||
| -rw-r--r-- | app/maps/style_map/access_link_style_map.rb | 43 | ||||
| -rw-r--r-- | app/maps/style_map/access_points_style_map.rb | 27 | ||||
| -rw-r--r-- | app/maps/style_map/stop_areas_style_map.rb | 26 | 
6 files changed, 159 insertions, 17 deletions
diff --git a/app/maps/access_link_map.rb b/app/maps/access_link_map.rb new file mode 100644 index 000000000..daf49738a --- /dev/null +++ b/app/maps/access_link_map.rb @@ -0,0 +1,37 @@ + +class AccessLinkMap < ApplicationMap + +  attr_reader :access_link, :access_link_style + +  def initialize(access_link, access_link_style = nil) +    @access_link = access_link +    @access_link_style = access_link_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.assign "access_points_layer", kml_layer([access_link.referential, access_link.access_point], :styleMap => StyleMap::AccessPointsStyleMap.new(helpers).style_map)  +      page << map.add_layer(:access_points_layer) +      page.assign "stop_areas_layer", kml_layer([access_link.referential, access_link.stop_area], :styleMap => StyleMap::StopAreasStyleMap.new(helpers).style_map)  +      page << map.add_layer(:stop_areas_layer) +      page << map.add_layer( kml_layer([access_link.referential, access_link.access_point, access_link], :styleMap => StyleMap::AccessLinkStyleMap.new(helpers).style_map)) +      page << map.add_control( hover_control_display_name([:access_points_layer,:stop_areas_layer]) ) +      page << map.zoom_to_extent(bounds.to_google.to_openlayers) if bounds +    end +  end + +  def ready? +    Chouette::StopArea.bounds.present? +  end + +  def bounds +    @bounds ||= GeoRuby::SimpleFeatures::Point.bounds([access_link.stop_area.geometry,access_link.access_point.geometry]) +  end + +end diff --git a/app/maps/access_point_map.rb b/app/maps/access_point_map.rb index ebb513ab0..bf763e6c6 100644 --- a/app/maps/access_point_map.rb +++ b/app/maps/access_point_map.rb @@ -17,6 +17,8 @@ class AccessPointMap < ApplicationMap        page << map.add_layer(google_hybrid)         page << map.add_layer(google_satellite)  +      page.assign "parent_layer", kml_layer(access_point.stop_area,  :style_map => StyleMap::StopAreasStyleMap.new(helpers).style_map) +      page << map.add_layer(:parent_layer)        page.assign "edit_access_point_layer", kml_layer(access_point, { :default => editable? }, :style_map => StyleMap::EditAccessPointStyleMap.new(helpers).style_map)        page << map.add_layer(:edit_access_point_layer) @@ -41,6 +43,8 @@ class AccessPointMap < ApplicationMap  EOF          page << map.add_control(OpenLayers::Control::ModifyFeature.new(:edit_access_point_layer, :mode => 8, :autoActivate => true)) +      else +        page << map.add_control( hover_control_display_name(:parent_layer) )        end        page << map.set_center(center.to_google.to_openlayers, 16, false, true) diff --git a/app/maps/stop_area_map.rb b/app/maps/stop_area_map.rb index 3e172c523..2fc329dce 100644 --- a/app/maps/stop_area_map.rb +++ b/app/maps/stop_area_map.rb @@ -17,15 +17,26 @@ class StopAreaMap < ApplicationMap        page << map.add_layer(google_hybrid)         page << map.add_layer(google_satellite)  -      page.assign "edit_stop_area_layer", kml_layer(stop_area, { :default => editable? }, :style_map => StyleMap::EditStopAreaStyleMap.new(helpers).style_map) -      page << map.add_layer(:edit_stop_area_layer) +      if stop_area.children.present? +        page.assign "children_layer", kml_layer(stop_area, { :children => true }, :style_map => StyleMap::StopAreasStyleMap.new(helpers).style_map) +        page << map.add_layer(:children_layer) +      end +      if stop_area.routing_stops.present? +        page.assign "routing_layer", kml_layer(stop_area, { :routing => true }, :style_map => StyleMap::StopAreasStyleMap.new(helpers).style_map) +        page << map.add_layer(:routing_layer) +        page << map.add_control( hover_control_display_name(:routing_layer) ) +        page << map.zoom_to_extent(bounds.to_google.to_openlayers) if bounds +      else +       +        page.assign "edit_stop_area_layer", kml_layer(stop_area, { :default => editable? }, :style_map => StyleMap::EditStopAreaStyleMap.new(helpers).style_map) +        page << map.add_layer(:edit_stop_area_layer) -      if editable? -       page.assign "referential_projection", projection_type.present? ? projection("EPSG:" + projection_type) : JsVar.new("undefined")   -        # TODO virer ce code inline        -        page << <<EOF -        edit_stop_area_layer.events.on({  +        if editable? +          page.assign "referential_projection", projection_type.present? ? projection("EPSG:" + projection_type) : JsVar.new("undefined")   +          # TODO virer ce code inline        +          page << <<EOF +          edit_stop_area_layer.events.on({                             'afterfeaturemodified': function(event) {                               geometry = event.feature.geometry.clone().transform(new OpenLayers.Projection("EPSG:900913"), new OpenLayers.Projection("EPSG:4326"));                              $('#stop_area_longitude').val(geometry.x); @@ -39,11 +50,14 @@ class StopAreaMap < ApplicationMap                             }                          });  EOF -        page << map.add_control(OpenLayers::Control::ModifyFeature.new(:edit_stop_area_layer, :mode => 8, :autoActivate => true)) +          page << map.add_control(OpenLayers::Control::ModifyFeature.new(:edit_stop_area_layer, :mode => 8, :autoActivate => true)) +        elsif stop_area.children.present? +          page << map.add_control( hover_control_display_name(:children_layer) ) -      end +        end -      page << map.set_center(center.to_google.to_openlayers, 16, false, true) +        page << map.set_center(center.to_google.to_openlayers, 16, false, true) +      end      end    end @@ -59,4 +73,9 @@ EOF      stop_area.geometry or stop_area.default_position    end +  def bounds +    # for ITL only +    @bounds ||= GeoRuby::SimpleFeatures::Point.bounds(stop_area.routing_stops.collect(&:geometry).compact) +  end +  end diff --git a/app/maps/style_map/access_link_style_map.rb b/app/maps/style_map/access_link_style_map.rb new file mode 100644 index 000000000..07ef5952b --- /dev/null +++ b/app/maps/style_map/access_link_style_map.rb @@ -0,0 +1,43 @@ +class StyleMap::AccessLinkStyleMap < StyleMap::GenericStyleMap +  attr_accessor :style + +  def initialize(helpers,options = {}) +    @helpers= helpers +    @style = options[:style].present? ? default_style.merge(options[:style]) : default_style +  end + +  def default_style +    { +      :fontColor => "black",  +      :fontSize => "11px", +      :fontWeight => "bold", +      :labelAlign => "ct", +      :labelXOffset => 0, +      :labelYOffset => -10, +      :strokeColor => "#000000", +      :strokeOpacity => 1, +      :strokeWidth => 3, +      :strokeLineCap => "round", +      :strokeDashstyle => "solid", +      :externalGraphic => @helpers.assets_path_patch( "map/${positionType}.png"), +      :graphicWidth => 36, +      :graphicHeight => 36,  +      :graphicOpacity => 1,	 +      :graphicXOffset => -18, +      :graphicYOffset => -18, +      :display => true +    } +  end + +  def context +    context = {  +      :positionType => :" function(feature) { if (feature.attributes.departure != undefined) { return 'departure'; } else { return 'arrival'; }} "  +    } +  end + +  def style_map +    OpenLayers::StyleMap.new(:default => OpenLayers::Style.new(style, { :context => context})) +  end + +end + diff --git a/app/maps/style_map/access_points_style_map.rb b/app/maps/style_map/access_points_style_map.rb index c3bf2586f..57cf8dfb3 100644 --- a/app/maps/style_map/access_points_style_map.rb +++ b/app/maps/style_map/access_points_style_map.rb @@ -1,5 +1,5 @@  class StyleMap::AccessPointsStyleMap < StyleMap::GenericStyleMap -  attr_accessor :style, :context +  attr_accessor :style, :context, :temporary    def default_style      raise "Helpers nil" if @helpers.nil? @@ -9,7 +9,24 @@ class StyleMap::AccessPointsStyleMap < StyleMap::GenericStyleMap       :fontWeight => "bold",       :labelAlign => "ct",       :labelXOffset => 0, -     :labelYOffset => -40, +     :labelYOffset => -20, +     :pointRadius => 1,  +     :externalGraphic => @helpers.assets_path_patch( "map/access_${accessType}.png"),       +     :graphicWidth => 25, +     :graphicHeight => 25,  +     :graphicOpacity => 1,     +     :graphicXOffset => -12.5, +     :graphicYOffset => -12.5 } +  end +  def temporary_style +    raise "Helpers nil" if @helpers.nil? +    {:label => "${label}", +     :fontColor => "darkblue", +     :fontSize => "12px", +     :fontWeight => "bold", +     :labelAlign => "ct", +     :labelXOffset => 0, +     :labelYOffset => -20,       :pointRadius => 1,        :externalGraphic => @helpers.assets_path_patch( "map/access_${accessType}.png"),             :graphicWidth => 25, @@ -22,18 +39,20 @@ class StyleMap::AccessPointsStyleMap < StyleMap::GenericStyleMap    def initialize(helpers,options = {})      @helpers= helpers      @style = options[:style].present? ? default_style.merge(options[:style]) : default_style +    @temporary = options[:style].present? ? temporary_style.merge(options[:style]) : temporary_style    end    def context      {        :label => :" function(feature) {if(feature.layer.map.getZoom() > 13) { return feature.attributes.name;} else {return '';}} ",  -      :accessType => :" function(feature) { return feature.attributes.access_type.toLowerCase();} "  +      :accessType => :" function(feature) { return feature.attributes.access_point_type.toLowerCase();} "       }    end    def style_map -    OpenLayers::StyleMap.new(:default => OpenLayers::Style.new(style, { :context => context})                             ) +    OpenLayers::StyleMap.new(:default => OpenLayers::Style.new(style, { :context => context}), +                             :temporary => OpenLayers::Style.new(temporary, { :context => context}) )    end  end diff --git a/app/maps/style_map/stop_areas_style_map.rb b/app/maps/style_map/stop_areas_style_map.rb index 398748a22..f23b58136 100644 --- a/app/maps/style_map/stop_areas_style_map.rb +++ b/app/maps/style_map/stop_areas_style_map.rb @@ -1,5 +1,5 @@  class StyleMap::StopAreasStyleMap < StyleMap::GenericStyleMap -  attr_accessor :style, :context +  attr_accessor :style, :context, :temporary    def default_style      raise "Helpers nil" if @helpers.nil? @@ -9,7 +9,7 @@ class StyleMap::StopAreasStyleMap < StyleMap::GenericStyleMap       :fontWeight => "bold",       :labelAlign => "ct",       :labelXOffset => 0, -     :labelYOffset => -40, +     :labelYOffset => -20,       :pointRadius => 1,        :externalGraphic => @helpers.assets_path_patch( "map/${areaType}.png"),             :graphicWidth => 25, @@ -18,10 +18,29 @@ class StyleMap::StopAreasStyleMap < StyleMap::GenericStyleMap       :graphicXOffset => -12.5,       :graphicYOffset => -12.5 }    end +  def temporary_style +    raise "Helpers nil" if @helpers.nil? +    {:label => "${label}", +     :fontColor => "darkblue", +     :fontSize => "12px", +     :fontWeight => "bold", +     :labelAlign => "ct", +     :labelXOffset => 0, +     :labelYOffset => -20, +     :pointRadius => 1,  +     :externalGraphic => @helpers.assets_path_patch( "map/${areaType}.png"),       +     :graphicWidth => 25, +     :graphicHeight => 25,  +     :graphicOpacity => 1,     +     :graphicXOffset => -12.5, +     :graphicYOffset => -12.5 } +  end +    def initialize(helpers,options = {})      @helpers= helpers      @style = options[:style].present? ? default_style.merge(options[:style]) : default_style +    @temporary = options[:style].present? ? temporary_style.merge(options[:style]) : temporary_style    end @@ -33,7 +52,8 @@ class StyleMap::StopAreasStyleMap < StyleMap::GenericStyleMap    end    def style_map -    OpenLayers::StyleMap.new(:default => OpenLayers::Style.new(style, { :context => context})                             ) +    OpenLayers::StyleMap.new(:default => OpenLayers::Style.new(style, { :context => context}), +                             :temporary => OpenLayers::Style.new(temporary, { :context => context}) )    end  end  | 
