Class: KML::Point

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

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

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

Class Method Details

.parse(node) ⇒ Object



46
47
48
# File 'lib/kml/point.rb', line 46

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

Instance Method Details

#coordinatesObject

A single tuple consisting of floating point values for longitude, latitude, and altitude (in that order). Longitude and latitude values are in degrees, where:

  • longitude >= -180 and <= 180

  • latitude >= -90 and <= 90

  • altitude values (optional) are in meters above sea level



18
19
20
# File 'lib/kml/point.rb', line 18

def coordinates
  @coordinates
end

#coordinates=(c) ⇒ Object

Set the coordinates



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/kml/point.rb', line 23

def coordinates=(c)
  case c
  when String
    @coordinates = c.strip.split(',')
    unless @coordinates.length == 2 || @coordinates.length == 3
      raise "Coordinates string may only have 2 parts (indicating lat and long) or 3 parts (lat, long and altitude)"
    end
  when Array
    @coordinates = c
  when Hash
    @coordinates = [:lng, :lat, :alt].collect {|attr| c[attr]}.compact
  else
    raise ArgumentError, "Coordinates must be either a String, Hash or an Array"
  end
end

#parse(node) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/kml/point.rb', line 50

def parse(node)
  super(node) do |cld|
    case cld.name
    when 'coordinates'
      self.coordinates = cld.content
    else
      puts "Point"
      p cld
      puts
    end
  end
  self
end

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



39
40
41
42
43
44
# File 'lib/kml/point.rb', line 39

def render(xm=Builder::XmlMarkup.new(:indent => 2))
  xm.Point {
    super
    xm.coordinates(coordinates.join(","))
  }
end