Class: Itinerary::View::KML

Inherits:
Itinerary::View show all
Defined in:
lib/itinerary/views/kml.rb

Instance Attribute Summary

Attributes inherited from Itinerary::View

#hide_fields, #name, #show_fields

Instance Method Summary collapse

Methods inherited from Itinerary::View

#initialize

Constructor Details

This class inherits a constructor from Itinerary::View

Instance Method Details

#render(entries) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/itinerary/views/kml.rb', line 5

def render(entries)
  @kml = Builder::XmlMarkup.new
  @kml.instruct!(:xml, :version => '1.0', :encoding => 'UTF-8')
  @kml.kml(:xmlns => 'http://www.opengis.net/kml/2.2') do
    @kml.Document do
      @kml.name(@name)
      super
      render_route if @itinerary.route
    end
  end
  @kml.target!
end

#render_record(rec) ⇒ Object

draw points for entries



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/itinerary/views/kml.rb', line 20

def render_record(rec)
  @kml.Placemark(:id => rec.path) do
    @kml.name(rec.name)
    @kml.description do
      @kml.cdata!(rec.to_html(:use_dl => false, :field_keys => @field_keys))
    end
    @kml.Point do
      #FIXME: fuzz if required
      @kml.coordinates([rec.longitude, rec.latitude, 0].join(','))
    end
  end
end

#render_routeObject

draw lines for legs of route



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/itinerary/views/kml.rb', line 35

def render_route
  @kml.Placemark(:id => 'route') do
    @kml.LineString do
      @kml.extrude(1)
      @kml.tessellate(1)
      @kml.coordinates do
        @kml << @itinerary.route.map { |leg| [leg.longitude, leg.latitude].join(',') }.join("\n")
      end
    end
  end
end