Class: Kamelopard::Document

Inherits:
Container show all
Defined in:
lib/kamelopard/classes.rb

Overview

Represents KML’s Document class.

Instance Attribute Summary collapse

Attributes inherited from Feature

#abstractView, #addressDetails, #atom_author, #atom_link, #description, #extendedData, #metadata, #name, #open, #phoneNumber, #region, #snippet, #styleSelector, #styleUrl, #styles, #timeprimitive, #visibility

Attributes included from Snippet

#maxLines, #snippet_text

Attributes inherited from Object

#comment, #kml_id, #master_only

Instance Method Summary collapse

Methods inherited from Container

#<<, #features=

Methods inherited from Feature

add_author, #extended_data_to_kml, #hide, #show, #styles_to_kml, #timespan, #timespan=, #timestamp, #timestamp=

Methods included from Snippet

#snippet_to_kml

Methods inherited from Object

#_alternate_to_kml, #change, #master_only?

Constructor Details

#initialize(options = {}) ⇒ Document

Returns a new instance of Document.



969
970
971
972
973
974
975
976
977
# File 'lib/kamelopard/classes.rb', line 969

def initialize(options = {})
    @tours = []
    @folders = []
    @vsr_actions = []
    @master_mode = false
    Kamelopard.log(:info, 'Document', "Adding myself to the document holder")
    DocumentHolder.instance << self
    super
end

Instance Attribute Details

#flyto_modeObject

Returns the value of attribute flyto_mode.



962
963
964
# File 'lib/kamelopard/classes.rb', line 962

def flyto_mode
  @flyto_mode
end

#foldersObject

Returns the value of attribute folders.



962
963
964
# File 'lib/kamelopard/classes.rb', line 962

def folders
  @folders
end

#master_modeObject

Is this KML destined for a master LG node, or a slave? True if this is a master node. This defaults to true, so tours that don’t need this function, and tours for non-LG targets, work normally.



967
968
969
# File 'lib/kamelopard/classes.rb', line 967

def master_mode
  @master_mode
end

#toursObject

Returns the value of attribute tours.



962
963
964
# File 'lib/kamelopard/classes.rb', line 962

def tours
  @tours
end

#uses_xalObject

Returns the value of attribute uses_xal.



962
963
964
# File 'lib/kamelopard/classes.rb', line 962

def uses_xal
  @uses_xal
end

#vsr_actionsObject

Returns the value of attribute vsr_actions.



962
963
964
# File 'lib/kamelopard/classes.rb', line 962

def vsr_actions
  @vsr_actions
end

Instance Method Details

#folderObject

Returns the current Folder object



997
998
999
1000
1001
1002
# File 'lib/kamelopard/classes.rb', line 997

def folder
    if @folders.size == 0 then
        Folder.new
    end
    @folders.last
end

#get_actionsObject

Returns viewsyncrelay actions as a hash



980
981
982
983
984
# File 'lib/kamelopard/classes.rb', line 980

def get_actions
    {
        'actions' => @vsr_actions.collect { |a| a.to_hash }
    }
end

#get_actions_yamlObject



986
987
988
# File 'lib/kamelopard/classes.rb', line 986

def get_actions_yaml
    get_actions.to_yaml
end

#get_kml_documentObject



1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
# File 'lib/kamelopard/classes.rb', line 1051

def get_kml_document
    k = XML::Document.new
    # XXX fix this
    #k << XML::XMLDecl.default
    k.root = XML::Node.new('kml')
    r = k.root
    if @uses_xal then
        r.attributes['xmlns:xal'] = "urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"
    end
    # XXX Should this be add_namespace instead?
    r.attributes['xmlns'] = 'http://www.opengis.net/kml/2.2'
    r.attributes['xmlns:gx'] = 'http://www.google.com/kml/ext/2.2'
    r.attributes['xmlns:kml'] = 'http://www.opengis.net/kml/2.2'
    r.attributes['xmlns:atom'] = 'http://www.w3.org/2005/Atom'
    r << self.to_kml
    k
end

#make_tour_index(erb = nil, options = {}) ⇒ Object

Makes a screenoverlay with a balloon containing links to the tours in this document The erb argument contains ERB to populate the description. It can be left nil The options hash is passed to the ScreenOverlay constructor



1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
# File 'lib/kamelopard/classes.rb', line 1007

def make_tour_index(erb = nil, options = {})
    options[:name] ||= 'Tour index'

    options[:screenXY] ||= Kamelopard::XY.new(0.0, 1.0, :fraction, :fraction)
    options[:overlayXY] ||= Kamelopard::XY.new(0.0, 1.0, :fraction, :fraction)
    s = Kamelopard::ScreenOverlay.new options
    t = ERB.new( erb || %{
        <html>
            <body>
                <ul><% @tours.each do |t| %>
                    <li><a href="#<%= t.kml_id %>;flyto"><% if t.icon.nil? %><%= t.name %><% else %><img src="<%= t.icon %>" /><% end %></a></li>
                <% end %></ul>
            </body>
        </html>
    })

    s.description = XML::Node.new_cdata t.result(binding)
    s.balloonVisibility = 1

    balloon_au = [0, 1].collect do |v|
        au = Kamelopard::AnimatedUpdate.new [], :standalone => true
        a = XML::Node.new 'Change'
        b = XML::Node.new 'ScreenOverlay'
        b.attributes['targetId'] = s.kml_id
        c = XML::Node.new 'gx:balloonVisibility'
        c << XML::Node.new_text(v.to_s)
        b << c
        a << b
        au << a
        au
    end

    # Handle hiding and displaying the index
    @tours.each do |t|
        q = Wait.new(0.1, :standalone => true)
        t.playlist.unshift balloon_au[0]
        t.playlist.unshift q
        t.playlist << balloon_au[1]
        t.playlist << q
    end

    s
end

#to_kmlObject



1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
# File 'lib/kamelopard/classes.rb', line 1069

def to_kml
    d = XML::Node.new 'Document'
    super d

    # Print styles first
    #! These get printed out in the call to super, in Feature.to_kml()
    #@styles.map do |a| d << a.to_kml unless a.attached? end

    # then folders
    @folders.map do |a|
        a.to_kml(d) unless a.has_parent?
    end

    # then tours
    @tours.map do |a| a.to_kml(d) end

    d
end

#tourObject

Returns the current Tour object



991
992
993
994
# File 'lib/kamelopard/classes.rb', line 991

def tour
    Tour.new if @tours.length == 0
    @tours.last
end