Class: Kamelopard::ColorStyle

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

Overview

Corresponds to KML’s ColorStyle object. Color is stored as an 8-character hex string, with two characters each of alpha, blue, green, and red values, in that order, matching the ordering the KML spec demands.

Direct Known Subclasses

IconStyle, LabelStyle, LineStyle, PolyStyle

Instance Attribute Summary collapse

Attributes inherited from Object

#comment, #kml_id, #master_only

Instance Method Summary collapse

Methods inherited from Object

#_alternate_to_kml, #change, #master_only?, parse

Constructor Details

#initialize(color = nil, options = {}) ⇒ ColorStyle

Returns a new instance of ColorStyle.



1297
1298
1299
1300
1301
# File 'lib/kamelopard/classes.rb', line 1297

def initialize(color = nil, options = {})
    super options
    @set_colorMode = false
    @color = color unless color.nil?
end

Instance Attribute Details

#colorObject

Returns the value of attribute color.



1294
1295
1296
# File 'lib/kamelopard/classes.rb', line 1294

def color
  @color
end

#colorModeObject

Returns the value of attribute colorMode.



1295
1296
1297
# File 'lib/kamelopard/classes.rb', line 1295

def colorMode
  @colorMode
end

Instance Method Details

#alphaObject



1313
1314
1315
# File 'lib/kamelopard/classes.rb', line 1313

def alpha
    @color[0,2]
end

#alpha=(a) ⇒ Object



1317
1318
1319
# File 'lib/kamelopard/classes.rb', line 1317

def alpha=(a)
    @color[0,2] = a
end

#blueObject



1321
1322
1323
# File 'lib/kamelopard/classes.rb', line 1321

def blue
    @color[2,2]
end

#blue=(a) ⇒ Object



1325
1326
1327
# File 'lib/kamelopard/classes.rb', line 1325

def blue=(a)
    @color[2,2] = a
end

#greenObject



1329
1330
1331
# File 'lib/kamelopard/classes.rb', line 1329

def green
    @color[4,2]
end

#green=(a) ⇒ Object



1333
1334
1335
# File 'lib/kamelopard/classes.rb', line 1333

def green=(a)
    @color[4,2] = a
end

#redObject



1337
1338
1339
# File 'lib/kamelopard/classes.rb', line 1337

def red
    @color[6,2]
end

#red=(a) ⇒ Object



1341
1342
1343
# File 'lib/kamelopard/classes.rb', line 1341

def red=(a)
    @color[6,2] = a
end

#to_kml(elem = nil) ⇒ Object



1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
# File 'lib/kamelopard/classes.rb', line 1345

def to_kml(elem = nil)
    k = elem.nil? ? XML::Node.new('ColorStyle') : elem
    super k
    e = XML::Node.new 'color'
    e << @color
    k << e
    if @set_colorMode then
        e = XML::Node.new 'colorMode'
        e << @colorMode
        k << e
    end
    k
end

#validate_colorMode(a) ⇒ Object



1303
1304
1305
# File 'lib/kamelopard/classes.rb', line 1303

def validate_colorMode(a)
    raise "colorMode must be either \"normal\" or \"random\"" unless a == :normal or a == :random
end