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?, parse

Constructor Details

#initialize(name = '', options = {}) ⇒ Document

Returns a new instance of Document.



1071
1072
1073
1074
1075
1076
1077
1078
1079
# File 'lib/kamelopard/classes.rb', line 1071

def initialize(name = '', 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.



1064
1065
1066
# File 'lib/kamelopard/classes.rb', line 1064

def flyto_mode
  @flyto_mode
end

#foldersObject

Returns the value of attribute folders.



1064
1065
1066
# File 'lib/kamelopard/classes.rb', line 1064

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.



1069
1070
1071
# File 'lib/kamelopard/classes.rb', line 1069

def master_mode
  @master_mode
end

#toursObject

Returns the value of attribute tours.



1064
1065
1066
# File 'lib/kamelopard/classes.rb', line 1064

def tours
  @tours
end

#uses_xalObject

Returns the value of attribute uses_xal.



1064
1065
1066
# File 'lib/kamelopard/classes.rb', line 1064

def uses_xal
  @uses_xal
end

#vsr_actionsObject

Returns the value of attribute vsr_actions.



1064
1065
1066
# File 'lib/kamelopard/classes.rb', line 1064

def vsr_actions
  @vsr_actions
end

Instance Method Details

#folderObject

Returns the current Folder object



1099
1100
1101
1102
1103
1104
# File 'lib/kamelopard/classes.rb', line 1099

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

#get_actionsObject

Returns viewsyncrelay actions as a hash



1082
1083
1084
1085
1086
# File 'lib/kamelopard/classes.rb', line 1082

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

#get_actions_yamlObject



1088
1089
1090
# File 'lib/kamelopard/classes.rb', line 1088

def get_actions_yaml
    get_actions.to_yaml
end

#get_kml_documentObject



1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
# File 'lib/kamelopard/classes.rb', line 1153

def get_kml_document
    k = XML::Document.new

#            # XXX Should this be add_namespace instead?
#            ns_arr = [
#                ['', 'http://www.opengis.net/kml/2.2'],
#                ['gx', 'http://www.google.com/kml/ext/2.2'],
#                ['kml', 'http://www.opengis.net/kml/2.2'],
#                ['atom', 'http://www.w3.org/2005/Atom'],
#                ['test', 'http://test.com']
#            ]
#            ns_arr.each do |a|
#                nm = 'xmlns'
#                nm = a[0] if a[0] != ''
#                k.context.register_namespace(nm, a[1])
#            end

    # XXX fix this
    #k << XML::XMLDecl.default
    k.root = XML::Node.new('kml')
    r = k.root
#            # 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'
    ns_values = [
        [nil, 'http://www.opengis.net/kml/2.2'],
        ['gx', 'http://www.google.com/kml/ext/2.2'],
        ['kml', 'http://www.opengis.net/kml/2.2'],
        ['atom', 'http://www.w3.org/2005/Atom'],
    ]
    if @uses_xal
        ns_values << ['xal', "urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"]
    end
    ns_values.each do |ns|
        n = XML::Namespace.new(r, ns[0], ns[1])
        r.namespaces.namespace = n if ns[0].nil?
    end

    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



1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
# File 'lib/kamelopard/classes.rb', line 1109

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



1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
# File 'lib/kamelopard/classes.rb', line 1197

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



1093
1094
1095
1096
# File 'lib/kamelopard/classes.rb', line 1093

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