Module: Kamelopard
- Defined in:
- lib/kamelopard/classes.rb
Overview
Classes to manage various KML objects. See code.google.com/apis/kml/documentation/kmlreference.html for a description of KML
Defined Under Namespace
Modules: CoordinateList, Icon, ImagePyramid, Snippet, ViewVolume Classes: AbstractView, Alias, AnimatedUpdate, BalloonStyle, Camera, ColorStyle, Container, Document, Feature, FlyTo, Folder, Geometry, GroundOverlay, IconStyle, LabelStyle, LatLonBox, LatLonQuad, LineString, LineStyle, LinearRing, Link, ListStyle, Lod, LookAt, Model, MultiGeometry, NetworkLink, Object, Orientation, Overlay, PhotoOverlay, Placemark, Point, PolyStyle, Polygon, Region, ResourceMap, Scale, ScreenOverlay, SoundCue, Style, StyleMap, StyleSelector, TimePrimitive, TimeSpan, TimeStamp, Tour, TourControl, TourPrimitive, Wait, XY
Constant Summary collapse
- @@sequence =
0
Class Method Summary collapse
-
.add_altitudeMode(mode, e) ⇒ Object
Helper function for altitudeMode / gx:altitudeMode elements.
-
.convert_coord(a) ⇒ Object
– Accepts XdX’X.X“, XDXmX.XXs, XdXmX.XXs, or X.XXXX with either /- or N/E/S/W +.
- .get_document ⇒ Object
-
.get_next_id ⇒ Object
:nodoc.
-
.kml_array(e, m) ⇒ Object
– Intelligently adds elements to a KML object.
Instance Method Summary collapse
-
#get_stack_trace ⇒ Object
:nodoc.
Class Method Details
.add_altitudeMode(mode, e) ⇒ Object
Helper function for altitudeMode / gx:altitudeMode elements
94 95 96 97 98 99 100 101 102 103 |
# File 'lib/kamelopard/classes.rb', line 94 def Kamelopard.add_altitudeMode(mode, e) return if mode.nil? if mode == :clampToGround or mode == :relativeToGround or mode == :absolute then t = XML::Node.new 'altitudeMode' else t = XML::Node.new 'gx:altitudeMode' end t << mode.to_s e << t end |
.convert_coord(a) ⇒ Object
– Accepts XdX’X.X“, XDXmX.XXs, XdXmX.XXs, or X.XXXX with either /- or N/E/S/W +
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/kamelopard/classes.rb', line 56 def Kamelopard.convert_coord(a) # :nodoc a = a.to_s.upcase.strip mult = 1 if a =~ /^-/ then mult *= -1 end a = a.sub /^\+|-/, '' a = a.strip if a =~ /[SW]$/ then mult *= -1 end a = a.sub /[NESW]$/, '' a = a.strip if a =~ /^\d+(\.\d+)?$/ then # coord needs no transformation 1 elsif a =~ /^\d+D\d+M\d+(\.\d+)?S$/ then # coord is in dms p = a.split /[D"']/ a = p[0].to_f + (p[2].to_f / 60.0 + p[1].to_f) / 60.0 elsif a =~ /^\d+D\d+'\d+(\.\d+)?"$/ then # coord is in d'" p = a.split /[D"']/ a = p[0].to_f + (p[2].to_f / 60.0 + p[1].to_f) / 60.0 else raise "Couldn't determine coordinate format for #{a}" end # check that it's within range a = a.to_f * mult raise "Coordinate #{a} out of range" if a > 180 or a < -180 return a end |
.get_document ⇒ Object
15 16 17 |
# File 'lib/kamelopard/classes.rb', line 15 def Kamelopard.get_document Document.instance end |
.get_next_id ⇒ Object
:nodoc
19 20 21 22 |
# File 'lib/kamelopard/classes.rb', line 19 def Kamelopard.get_next_id # :nodoc @@sequence += 1 @@sequence end |
.kml_array(e, m) ⇒ Object
– Intelligently adds elements to a KML object. Expects the KML object as the first argument, an array as the second. Each entry in the array is itself an array, containing first an Object, and second either a string or a Proc object. If the first Object is nil, nothing happens. If it’s not nil, then:
* if the second element is a string, add a new element to the KML. This
string is the element name, and the stringified form of the first element
is its text value
* if the second element is a proc, call the proc, passing it the KML
object, and let the Proc (presumably) add itself to the KML
++
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/kamelopard/classes.rb', line 35 def Kamelopard.kml_array(e, m) # :nodoc m.map do |a| if ! a[0].nil? then if a[1].kind_of? Proc then a[1].call(e) elsif a[0].kind_of? XML::Node then d = XML::Node.new(a[1]) d << a[0] e << d else t = XML::Node.new a[1] t << a[0].to_s e << t end end end end |
Instance Method Details
#get_stack_trace ⇒ Object
:nodoc
760 761 762 763 764 |
# File 'lib/kamelopard/classes.rb', line 760 def get_stack_trace # :nodoc k = '' caller.each do |a| k << "#{a}\n" end k end |