Class: Kamel::Overlay

Inherits:
Object
  • Object
show all
Defined in:
lib/kamel/overlay.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(prefix = '') ⇒ Overlay

Returns a new instance of Overlay.



9
10
11
12
# File 'lib/kamel/overlay.rb', line 9

def initialize(prefix = '')
  self.prefix = prefix.to_s
  self.placemarks = []
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/kamel/overlay.rb', line 6

def name
  @name
end

#placemarksObject

Returns the value of attribute placemarks.



7
8
9
# File 'lib/kamel/overlay.rb', line 7

def placemarks
  @placemarks
end

#prefixObject

Returns the value of attribute prefix.



5
6
7
# File 'lib/kamel/overlay.rb', line 5

def prefix
  @prefix
end

Instance Method Details

#placemark!(attributes) ⇒ Object



14
15
16
# File 'lib/kamel/overlay.rb', line 14

def placemark!(attributes)
  self.placemarks << attributes
end

#to_kmlObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/kamel/overlay.rb', line 18

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