aboutsummaryrefslogtreecommitdiffstats
path: root/app/maps
diff options
context:
space:
mode:
authorMarc Florisson2012-08-21 11:57:46 +0200
committerMarc Florisson2012-08-21 11:57:46 +0200
commit13cdfc734313ea6288fa88a0f27960bfbc966e78 (patch)
tree250c428c6542e176c421b75ff06d8b69bbb11987 /app/maps
parent2d756b1c5880986928ae1bc5912ee9038cf9c38f (diff)
downloadchouette-core-13cdfc734313ea6288fa88a0f27960bfbc966e78.tar.bz2
hover on stop points. Refs #108
Diffstat (limited to 'app/maps')
-rw-r--r--app/maps/journey_pattern_map.rb40
-rw-r--r--app/maps/style_map/journey_pattern_style_map.rb47
2 files changed, 87 insertions, 0 deletions
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
+