Class: Kamel::Overlay
- Inherits:
-
Object
- Object
- Kamel::Overlay
- Defined in:
- lib/kamel/overlay.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#placemarks ⇒ Object
Returns the value of attribute placemarks.
-
#prefix ⇒ Object
Returns the value of attribute prefix.
Instance Method Summary collapse
-
#initialize(prefix = '') ⇒ Overlay
constructor
A new instance of Overlay.
- #placemark!(attributes) ⇒ Object
- #to_kml ⇒ Object
Constructor Details
#initialize(prefix = '') ⇒ Overlay
Returns a new instance of Overlay.
15 16 17 18 |
# File 'lib/kamel/overlay.rb', line 15 def initialize(prefix = '') self.prefix = prefix.to_s self.placemarks = [] end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
12 13 14 |
# File 'lib/kamel/overlay.rb', line 12 def name @name end |
#placemarks ⇒ Object
Returns the value of attribute placemarks.
13 14 15 |
# File 'lib/kamel/overlay.rb', line 13 def placemarks @placemarks end |
#prefix ⇒ Object
Returns the value of attribute prefix.
11 12 13 |
# File 'lib/kamel/overlay.rb', line 11 def prefix @prefix end |
Instance Method Details
#placemark!(attributes) ⇒ Object
20 21 22 |
# File 'lib/kamel/overlay.rb', line 20 def placemark!(attributes) self.placemarks << attributes end |
#to_kml ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/kamel/overlay.rb', line 24 def to_kml doc = KML::Document.new doc.name = self.name unless self.name.to_s.length == 0 self.icons.each_with_index {|icon, index| doc.styles << KML::Style.new( :id => [prefix, 'style', index].join('-'), :icon_style => KML::IconStyle.new( :icon => KML::Icon.new(:href => icon) ) ) } self.placemarks.each do |placemark| attrs = {} attrs[:name] = placemark[:name].to_s unless placemark[:name].nil? attrs[:description] = placemark[:description].to_s unless placemark[:description].nil? attrs[:geometry] = KML::Point.new(:coordinates => placemark[:location]) unless placemark[:location].nil? attrs[:style_url] = '#' + [prefix, 'style', self.icons.index(placemark[:icon])].join('-') unless placemark[:icon].nil? doc.features << KML::Placemark.new(attrs) end kml = KMLFile.new kml.objects << doc kml.render end |