Class: KML::Feature

Inherits:
Object show all
Defined in:
lib/kml/feature.rb

Overview

A feature is an abstract base class.

Direct Known Subclasses

Container, Overlay

Instance Attribute Summary collapse

Attributes inherited from Object

#id

Instance Method Summary collapse

Methods inherited from Object

#initialize

Constructor Details

This class inherits a constructor from KML::Object

Instance Attribute Details

#addressObject

A string value representing an unstructured address written as a standard street, city, state address, and/or as a postal code. You can use the address attribute to specify the location of a point instead of using latitude and longitude coordinates. (However, if a Point is provided, it takes precedence over the address.) To find out which locales are supported for this tag in Google Earth, go to the <a href=“maps.google.com/support/bin/answer.py?answer=16634”>Google Maps Help</a>.



68
69
70
# File 'lib/kml/feature.rb', line 68

def address
  @address
end

#address_detailsObject

A structured address, formatted as xAL, or eXtensible Address Language, an international standard for address formatting. AddressDetails is used by KML for geocoding in Google Maps only. For details, see the Google Maps API documentation. Currently, Google Earth does not use this attribute; use address instead.



73
74
75
# File 'lib/kml/feature.rb', line 73

def address_details
  @address_details
end

#descriptionObject

User-supplied text that appears in the description balloon when the user clicks on either the feature name in the Places panel or the Placemark icon in the 3D viewer. This text also appears beneath the feature name in the Places panel if no Snippet is specified for the feature.

Description supports plain text as well as a subset of HTML formatting elements, including tables. It does not support other web-based technology, such as dynamic page markup (PHP, JSP, ASP), scripting languages (VBScript, Javascript), nor application languages (Java, Python).

If your description contains no HTML markup, Google Earth attempts to format it, replacing newlines with &lt;br&gt; and wrapping URLs with anchor tags. A valid URL string for the World Wide Web is automatically converted to a hyperlink to that URL (e.g., www.google.com). Consequently, you do not need to surround a URL with the &lt;a href=“http://..”&gt;&lt;/a&gt; tags in order to achieve a simple link.



106
107
108
# File 'lib/kml/feature.rb', line 106

def description
  @description
end

#look_atObject

Defines a camera viewpoint associated with any element derived from Feature. See LookAt.



109
110
111
# File 'lib/kml/feature.rb', line 109

def look_at
  @look_at
end

#metadataObject

Returns the value of attribute metadata.



130
131
132
# File 'lib/kml/feature.rb', line 130

def 
  @metadata
end

#nameObject

Accessor for the feature name



25
26
27
# File 'lib/kml/feature.rb', line 25

def name
  @name
end

#phone_numberObject

A string value representing a telephone number. This element is used by Google Maps Mobile only. The industry standard for Java-enabled cellular phones is RFC2806. For more information, see <a href=“www.ietf.org/rfc/rfc2806.txt”>www.ietf.org/rfc/rfc2806.txt</a>.



78
79
80
# File 'lib/kml/feature.rb', line 78

def phone_number
  @phone_number
end

#regionObject

Returns the value of attribute region.



129
130
131
# File 'lib/kml/feature.rb', line 129

def region
  @region
end

#snippetObject

Accessor for the snippet. See KML::Snippet



81
82
83
# File 'lib/kml/feature.rb', line 81

def snippet
  @snippet
end

#style_selectorObject

One or more Styles and StyleMaps can be defined to customize the appearance of any element derived from Feature or of the Geometry in a Placemark. (See BalloonStyle, ListStyle, StyleSelector, and the styles derived from ColorStyle.) A style defined within a Feature is called an “inline style” and applies only to the Feature that contains it. A style defined as the child of a Document is called a “shared style.” A shared style must have an id defined for it. This id is referenced by one or more Features within the <Document>. In cases where a style element is defined both in a shared style and in an inline style for a Feature—that is, a Folder, GroundOverlay, NetworkLink, Placemark, or ScreenOverlay—the value for the Feature’s inline style takes precedence over the value for the shared style.



128
129
130
# File 'lib/kml/feature.rb', line 128

def style_selector
  @style_selector
end

#style_urlObject

URI (a URI equals [URL]#ID) of a Style or StyleMap defined in a Document. If the style is in the same file, use a # reference. If the style is defined in an external file, use a full URL along with # referencing. Examples:

+style_url='#myIconStyleID'
+style_url='http://someserver.com/somestylefile.xml#restaurant'


118
119
120
# File 'lib/kml/feature.rb', line 118

def style_url
  @style_url
end

#time_primitiveObject

Returns the value of attribute time_primitive.



111
112
113
# File 'lib/kml/feature.rb', line 111

def time_primitive
  @time_primitive
end

Instance Method Details

#openObject

If the open has been set then return ‘0’ for false and ‘1’ for true. If the open has never been explicitly set then return nil (which means that the associated KML tag will not be rendered)



52
53
54
55
# File 'lib/kml/feature.rb', line 52

def open
  return nil if @open.nil?
  @open ? '1' : '0'
end

#open=(v) ⇒ Object

Set to true to indicate that the feature is expanded when displayed. Set to false to indicate that the feature is collapsed.



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

def open=(v)
  @open = v
end

#open?Boolean

Return true if the feature is expanded when initially displayed.

Returns:

  • (Boolean)


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

def open?
  @open || true
end

#parse(node) ⇒ Object



155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/kml/feature.rb', line 155

def parse(node)
  super(node) do |cld|
    case cld.name
    when 'name'
      self.name = cld.content
    when 'visibility'
      self.visibility = cld.content
    when 'description'
      self.description = cld.content
    when 'styleUrl'
      self.style_url = cld.content
    when 'Region'
      # TODO
    when 'ExtendedData'
      # TODO
    when 'Snippet'
      # TODO
    else
      yield cld
    end
  end
  self
end

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

Render the object and all of its sub-elements.



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/kml/feature.rb', line 133

def render(xm=Builder::XmlMarkup.new(:indent => 2))
  [:name, :visibility, :address].each do |a|
    xm.__send__(a, self.__send__(a)) unless self.__send__(a).nil?
  end

  xm.description { xm.cdata!(description) } unless description.nil?
  xm.open(self.open) unless open.nil?

  xm.phoneNumber(phone_number) unless phone_number.nil?
  xm.styleUrl(style_url) unless style_url.nil?

  unless address_details.nil?
    xm.AddressDetails(:xmlns => "urn:oasis:names:tc:ciq:xsdschema:xAL:2.0") { address_details.render(xm) } 
  end

  xm.Snippet(snippet.text, snippet.max_lines) unless snippet.nil?

  xm.LookAt { look_at.render(xm) } unless look_at.nil?
  xm.TimePrimitive { time_primitive.render(xm) } unless time_primitive.nil?
  xm.StyleSelector { style_selector.render(xm) } unless style_selector.nil?
end

#visibilityObject

If the visibility has been set then return ‘0’ for false and ‘1’ for true. If the visibility has never been explicitly set then return nil (which means that the associated KML tag will not be rendered)



35
36
37
38
# File 'lib/kml/feature.rb', line 35

def visibility
  return nil if @visibility.nil?
  @visibility ? '1' : '0'
end

#visibility=(v) ⇒ Object

Set to true to indicate that the feature is visible.



41
42
43
# File 'lib/kml/feature.rb', line 41

def visibility=(v)
  @visibility = v
end

#visibility?Boolean

Return true if the feature is visible

Returns:

  • (Boolean)


28
29
30
# File 'lib/kml/feature.rb', line 28

def visibility?
  @visibility || true
end