Top Level Namespace

Defined Under Namespace

Classes: AbstractView, Alias, AnimatedUpdate, BalloonStyle, Camera, ColorStyle, Container, CoordinateList, Document, Feature, FlyTo, Folder, Geocoder, Geometry, GroundOverlay, Icon, IconStyle, ImagePyramid, KMLObject, KMLPoint, KMLxy, LabelStyle, LatLonBox, LatLonQuad, LineString, LineStyle, LinearRing, Link, ListStyle, Lod, LookAt, Model, NDPointList, OneDPointList, Orientation, Overlay, PhotoOverlay, Placemark, PolyStyle, Region, ResourceMap, Scale, ScreenOverlay, Snippet, SoundCue, Style, StyleMap, StyleSelector, ThreeDPointList, TimePrimitive, TimeSpan, TimeStamp, Tour, TourControl, TourPrimitive, TwoDPointList, ViewVolume, Wait, YahooGeocoder

Constant Summary collapse

@@sequence =
0

Instance Method Summary collapse

Instance Method Details

#convert_coord(a) ⇒ Object

– Accepts XdX’X.X“, XDXmX.XXs, XdXmX.XXs, or X.XXXX with either /- or N/E/S/W +



45
46
47
48
49
50
51
52
53
54
55
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
# File 'lib/kamelopard/classes.rb', line 45

def 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

#fly_to(p, d = 0, r = 100, m = nil) ⇒ Object

vim:ts=4:sw=4:et:smartindent:nowrap



2
3
4
5
# File 'lib/kamelopard/functions.rb', line 2

def fly_to(p, d = 0, r = 100, m = nil)
    m = Document.instance.flyto_mode if m.nil?
    FlyTo.new(p, r, d, m)
end

#get_kmlObject

Returns the KML that makes up the current Document, as a string.



33
34
35
# File 'lib/kamelopard/functions.rb', line 33

def get_kml
    Document.instance.to_kml
end

#get_next_idObject

:nodoc



12
13
14
15
# File 'lib/kamelopard/classes.rb', line 12

def get_next_id   # :nodoc
    @@sequence += 1
    @@sequence
end

#get_stack_traceObject

:nodoc



672
673
674
675
676
# File 'lib/kamelopard/classes.rb', line 672

def get_stack_trace   # :nodoc
    k = ''
    caller.each do |a| k << "#{a}\n" end
    k
end

#hide_popup_for(p) ⇒ Object



20
21
22
# File 'lib/kamelopard/functions.rb', line 20

def hide_popup_for(p)
    mod_popup_for(p, 0)
end

#kml_array(m, indent = 0) ⇒ Object

– Print out a set of kml fields. Expects an array argument. Each entry in the array is itself an array, containing two strings and a boolean. If the first string is nil, the function won’t print anything for that element. If it’s not null, it consults the boolean. True values tell the function to treat the second string as a KML element name, and print it along with XML decorators and the field value. False values mean just print the second string, with no decorators and no other values ++



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/kamelopard/classes.rb', line 26

def kml_array(m, indent = 0) # :nodoc
    k = ''
    m.map do |a|
        r = ''
        if ! a[0].nil? then
            if a[2] then
                r << "#{ ' ' * indent}<" << a[1] << '>' << a[0].to_s << '</' << a[1] << ">\n"
            else
                r << a[1] << "\n"
            end
        end
        k << r
    end
    k
end

#mod_popup_for(p, v) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/kamelopard/functions.rb', line 11

def mod_popup_for(p, v)
    a = AnimatedUpdate.new
    if ! p.is_a? Placemark then
        raise "Can't show popups for things that aren't placemarks"
    end
    a << "<Change><Placemark targetId=\"#{p.id}\"><visibility>#{v}</visibility></Placemark></Change>"
    a
end

#name_folder(a) ⇒ Object



49
50
51
# File 'lib/kamelopard/functions.rb', line 49

def name_folder(a)
    Document.instance.folder.name = a
end

#name_tour(a) ⇒ Object



41
42
43
# File 'lib/kamelopard/functions.rb', line 41

def name_tour(a)
    Document.instance.tour.name = a
end

#new_folder(name) ⇒ Object



45
46
47
# File 'lib/kamelopard/functions.rb', line 45

def new_folder(name)
    Folder.new(name)
end

#orbit(center, range = 100, tilt = 0, startHeading = 0, endHeading = 360) ⇒ Object

Creates a list of FlyTo elements to orbit and look at a given point (center), at a given range (in meters), starting and ending at given angles (in degrees) from the center, where 0 and 360 (and -360, and 720, and -980, etc.) are north. To orbit clockwise, make startHeading less than endHeading. Otherwise, it will orbit counter-clockwise. To orbit multiple times, add or subtract 360 from the endHeading. The tilt argument matches the KML LookAt tilt argument



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/kamelopard/functions.rb', line 67

def orbit(center, range = 100, tilt = 0, startHeading = 0, endHeading = 360)
    fly_to LookAt.new(center, startHeading, tilt, range), 2, nil

    # We want at least 5 points (arbitrarily chosen value), plus at least 5 for
    # each full revolution

    # When I tried this all in one step, ruby told me 360 / 10 = 1805. I'm sure
    # there's some reason why this is a feature and not a bug, but I'd rather
    # not look it up right now.
    num = (endHeading - startHeading).abs
    den = ((endHeading - startHeading) / 360.0).to_i.abs * 5 + 5
    step = num / den
    step = 1 if step < 1
    step = step * -1 if startHeading > endHeading

    lastval = startHeading
    startHeading.step(endHeading, step) do |theta|
        lastval = theta
        fly_to LookAt.new(center, theta, tilt, range), 2, nil, 'smooth'
    end
    if lastval != endHeading then
        fly_to LookAt.new(center, endHeading, tilt, range), 2, nil, 'smooth'
    end
end

#pause(p) ⇒ Object



37
38
39
# File 'lib/kamelopard/functions.rb', line 37

def pause(p)
    Wait.new p
end

#point(lo, la, alt = 0, mode = nil, extrude = false) ⇒ Object



28
29
30
# File 'lib/kamelopard/functions.rb', line 28

def point(lo, la, alt=0, mode=nil, extrude = false)
    KMLPoint.new(lo, la, alt, mode.nil? ? :clampToGround : mode, extrude)
end

#set_flyto_mode_to(a) ⇒ Object



7
8
9
# File 'lib/kamelopard/functions.rb', line 7

def set_flyto_mode_to(a)
    Document.instance.flyto_mode = a
end

#show_popup_for(p) ⇒ Object



24
25
26
# File 'lib/kamelopard/functions.rb', line 24

def show_popup_for(p)
    mod_popup_for(p, 1)
end

#sound_cue(href, ds = nil) ⇒ Object



92
93
94
# File 'lib/kamelopard/functions.rb', line 92

def sound_cue(href, ds = nil)
    SoundCue.new href, ds
end

#zoom_out(dist = 1000, dur = 0, mode = nil) ⇒ Object



53
54
55
56
57
58
# File 'lib/kamelopard/functions.rb', line 53

def zoom_out(dist = 1000, dur = 0, mode = nil)
    l = Document.instance.tour.last_abs_view
    raise "No current position to zoom out from\n" if l.nil?
    l.range += dist
    FlyTo.new(l, nil, dur, mode)
end