Class: StyleMap

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

Overview

Corresponds to KML’s StyleMap object.

Instance Attribute Summary

Attributes inherited from StyleSelector

#attached

Attributes inherited from KMLObject

#comment, #id

Instance Method Summary collapse

Methods inherited from StyleSelector

#attach, #attached?

Constructor Details

#initialize(pairs = {}) ⇒ 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



1053
1054
1055
1056
# File 'lib/kamelopard/classes.rb', line 1053

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

Instance Method Details

#merge(a) ⇒ Object

Adds a new Style to the StyleMap.



1059
1060
1061
# File 'lib/kamelopard/classes.rb', line 1059

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

#to_kml(indent = 0) ⇒ Object



1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
# File 'lib/kamelopard/classes.rb', line 1063

def to_kml(indent = 0)
    t = super + "#{ ' ' * indent }<StyleMap id=\"#{@id}\">\n"
    @pairs.each do |k, v|
        t << "#{ ' ' * indent }    <Pair>\n"
        t << "#{ ' ' * indent }        <key>#{ k }</key>\n"
        if v.kind_of? Style then
            t << ( ' ' * indent ) << v.to_kml(indent + 8)
        else
            t << "#{ ' ' * indent }        <styleUrl>#{ v }</styleUrl>\n"
        end
        t << "#{ ' ' * indent }    </Pair>\n"
    end
    t << "#{ ' ' * indent }</StyleMap>\n"
    t
end