Class: KML::Polygon

Inherits:
Geometry show all
Defined in:
lib/kml/polygon.rb

Overview

A Polygon is defined by an outer boundary and 0 or more inner boundaries. The boundaries, in turn, are defined by LinearRings. When a Polygon is extruded, its boundaries are connected to the ground to form additional polygons, which gives the appearance of a building. When a Polygon is extruded, each point is extruded individually. Extruded Polygons use PolyStyle for their color, color mode, and fill.

Instance Attribute Summary collapse

Attributes inherited from Container

#features, #plain_children

Attributes inherited from Feature

#address, #address_details, #description, #look_at, #metadata, #name, #phone_number, #region, #snippet, #style_selector, #style_url, #time_primitive

Attributes inherited from Object

#id

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Geometry

#altitude_mode, #altitude_mode=, #altitude_mode_set?, #extrude, #extrude=, #extrude?, #tessellate, #tessellate=, #tessellate?

Methods inherited from Feature

#open, #open=, #open?, #visibility, #visibility=, #visibility?

Methods inherited from Object

#initialize

Constructor Details

This class inherits a constructor from KML::Object

Instance Attribute Details

#outer_boundary_isObject

Returns the value of attribute outer_boundary_is.



30
31
32
# File 'lib/kml/polygon.rb', line 30

def outer_boundary_is
  @outer_boundary_is
end

Class Method Details

.parse(node) ⇒ Object



59
60
61
# File 'lib/kml/polygon.rb', line 59

def self.parse(node)
  self.new.parse(node)
end

Instance Method Details

#inner_boundary_isObject



32
33
34
# File 'lib/kml/polygon.rb', line 32

def inner_boundary_is
  @inner_boundary_is ||= []
end

#inner_boundary_is=(ib) ⇒ Object

allow old semantics for adding inner boundaries



37
38
39
40
41
42
43
# File 'lib/kml/polygon.rb', line 37

def inner_boundary_is=(ib)
  if ib.kind_of?(Array)
    @inner_boundary_is = ib
  else
    self.inner_boundary_is << ib
  end
end

#parse(node) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/kml/polygon.rb', line 63

def parse(node)
  super(node) do |cld|
    case cld.name
    when 'outerBoundaryIs'
      self.outer_boundary_is = self.parse_boundary(cld)
    when 'innerBoundaryIs'
      self.inner_boundary_is << self.parse_boundary(cld)
    else
      puts "Polygon"
      p cld
      puts
    end
  end
  self
end

#parse_boundary(node) ⇒ Object

should only contain a LinearRing



80
81
82
83
84
85
86
87
88
89
# File 'lib/kml/polygon.rb', line 80

def parse_boundary(node)
  ring = nil
  node.element_children.each do |cld|
    case cld.name
    when 'LinearRing'
      ring = KML::LinearRing.parse(cld)
    end
  end
  ring
end

#render(xm = Builder::XmlMarkup.new(:indent => 2)) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/kml/polygon.rb', line 45

def render(xm=Builder::XmlMarkup.new(:indent => 2))
  xm.Polygon {
    super
    xm.outerBoundaryIs {
      outer_boundary_is.render(xm)
    }
    inner_boundary_is.each do |ib|
      xm.innerBoundaryIs {
        ib.render(xm)
      }
    end
  }
end