aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Florisson2012-08-14 14:22:30 +0200
committerMarc Florisson2012-08-14 14:22:30 +0200
commit7913533a4e49fb023bfc61c2a218d0748891b4c2 (patch)
treef9970dd067effd588e58fa8693f6661b471cf22f
parent40dd4517d2c8fe85c608d42d95d70489fb04ce02 (diff)
downloadchouette-core-7913533a4e49fb023bfc61c2a218d0748891b4c2.tar.bz2
display linestring on connection_link kml. Refs #99
-rw-r--r--app/controllers/connection_links_controller.rb1
-rw-r--r--app/maps/connection_link_map.rb1
-rw-r--r--app/maps/style_map/connection_link_style_map.rb42
-rw-r--r--app/views/connection_links/show.kml.erb20
4 files changed, 64 insertions, 0 deletions
diff --git a/app/controllers/connection_links_controller.rb b/app/controllers/connection_links_controller.rb
index dc6ba78c9..cbb8346c6 100644
--- a/app/controllers/connection_links_controller.rb
+++ b/app/controllers/connection_links_controller.rb
@@ -7,6 +7,7 @@ class ConnectionLinksController < ChouetteController
end
respond_to :html, :xml, :json
+ respond_to :kml, :only => :show
def show
@map = ConnectionLinkMap.new(resource).with_helpers(self)
diff --git a/app/maps/connection_link_map.rb b/app/maps/connection_link_map.rb
index dd642c47d..d26bba33b 100644
--- a/app/maps/connection_link_map.rb
+++ b/app/maps/connection_link_map.rb
@@ -18,6 +18,7 @@ class ConnectionLinkMap < ApplicationMap
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_layer( kml_layer([connection_link.referential, connection_link], :styleMap => StyleMap::ConnectionLinkStyleMap.new.style_map))
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))
#page << map.add_layer(kml_layer(polymorphic_path([referential, connection_link, :stop_areas], :format => :kml), :styleMap => StyleMap::StopAreasStyleMap.new.style_map))
diff --git a/app/maps/style_map/connection_link_style_map.rb b/app/maps/style_map/connection_link_style_map.rb
new file mode 100644
index 000000000..39a8c7fd8
--- /dev/null
+++ b/app/maps/style_map/connection_link_style_map.rb
@@ -0,0 +1,42 @@
+class StyleMap::ConnectionLinkStyleMap < StyleMap::GenericStyleMap
+ attr_accessor :style
+
+ def initialize(options = {})
+ @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 => -15,
+ :strokeColor => "#000000",
+ :strokeOpacity => 1,
+ :strokeWidth => 3,
+ :strokeLineCap => "round",
+ :strokeDashstyle => "solid",
+ :externalGraphic => "/assets/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/views/connection_links/show.kml.erb b/app/views/connection_links/show.kml.erb
new file mode 100644
index 000000000..fa355d7b5
--- /dev/null
+++ b/app/views/connection_links/show.kml.erb
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<kml xmlns="http://www.opengis.net/kml/2.2">
+ <Document>
+ <% if @connection_link.geometry %>
+ <Placemark id="route_<%= @connection_link.id %>" >
+ <name><%= @connection_link.name %></name>
+ <%= @connection_link.geometry.kml_representation.html_safe %>
+ </Placemark>
+ <Placemark id="<%= @connection_link.departure.id %>" >
+ <departure>true</departure>
+ <%= @connection_link.departure.geometry.kml_representation.html_safe %>
+ </Placemark>
+ <Placemark id="<%= @connection_link.arrival.id %>" >
+ <arrival>true</arrival>
+ <%= @connection_link.arrival.geometry.kml_representation.html_safe %>
+ </Placemark>
+ <% end %>
+ </Document>
+</kml>
+