Class: Kamelopard::StyleMap

Inherits:
StyleSelector show all
Defined in:
lib/kamelopard/classes.rb

Overview

Corresponds to KML’s StyleMap object.

Instance Attribute Summary

Attributes inherited from Object

#comment, #kml_id, #master_only

Instance Method Summary collapse

Methods inherited from StyleSelector

#attach, #attached?

Methods inherited from Object

#_alternate_to_kml, #change, #master_only?, parse

Constructor Details

#initialize(pairs = {}, options = {}) ⇒ StyleMap

StyleMap manages pairs. The first entry in each pair is a string key, the second is either a Style or a styleUrl. It will be assumed to be the latter if its kind_of? method doesn’t claim it’s a Style object



1551
1552
1553
1554
# File 'lib/kamelopard/classes.rb', line 1551

def initialize(pairs = {}, options = {})
    super options
    @pairs = pairs
end

Instance Method Details

#merge(a) ⇒ Object

Adds a new Style to the StyleMap.



1557
1558
1559
# File 'lib/kamelopard/classes.rb', line 1557

def merge(a)
    @pairs.merge!(a)
end

#to_kml(elem = nil) ⇒ Object



1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
# File 'lib/kamelopard/classes.rb', line 1561

def to_kml(elem = nil)
    t = XML::Node.new 'StyleMap'
    super t
    @pairs.each do |k, v|
        p = XML::Node.new 'Pair'
        key = XML::Node.new 'key'
        key << k.to_s
        p. << key
        if v.kind_of? Style then
            v.to_kml(p)
        else
            s = XML::Node.new 'styleUrl'
            s << v.to_s
            p << s
        end
        t << p
    end
    elem << t unless elem.nil?
    t
end