Class: KML::LineString

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

Overview

Defines a connected set of line segments. Use LineStyle to specify the color, color mode, and width of the line. When a LineString is extruded, the line is extended to the ground, forming a polygon that looks somewhat like a wall. For extruded LineStrings, the line itself uses the current LineStyle, and the extrusion uses the current PolyStyle. See the <a href=“earth.google.com/kml/kml_tut.html”>KML Tutorial</a> for examples of LineStrings (or paths).

Instance Attribute Summary

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

Instance Method Summary collapse

Methods inherited from Geometry

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

Methods inherited from Container

#parse

Methods inherited from Feature

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

Methods inherited from Object

#initialize, #parse

Constructor Details

This class inherits a constructor from KML::Object

Instance Method Details

#coordinatesObject

Two or more coordinate tuples, each consisting of floating point values for longitude, latitude, and altitude. The altitude component is optional.



10
11
12
# File 'lib/kml/line_string.rb', line 10

def coordinates
  @coordinates
end

#coordinates=(c) ⇒ Object

Set the coordinates. When specifying as a String, insert a space or linebreak between tuples. Do not include spaces within a tuple.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/kml/line_string.rb', line 16

def coordinates=(c)
  case c
  when String
    @coordinates = c.strip.split(/\s+/).collect { |coord| coord.split(',') }
  when Array
    c.each do |coord_array|
      unless coord_array.is_a?(Array)
        raise ArgumentError, "If set with an array, coordinates must be specified as an array of arrays"
      end
    end
    @coordinates = c
  else
    raise ArgumentError, "Coordinates must either be a String or an Array of Arrays"
  end
end

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

Raises:

  • (ArgumentError)


32
33
34
35
36
37
38
# File 'lib/kml/line_string.rb', line 32

def render(xm=Builder::XmlMarkup.new(:indent => 2))
  raise ArgumentError, "Coordinates required" if coordinates.nil?
  xm.LineString {
    super
    xm.coordinates(coordinates.collect { |c| c.join(',') }.join(" "))
  }
end