Class: Map::KmlCreatorLineService

Inherits:
Object
  • Object
show all
Defined in:
lib/map/kml_creator_line_service.rb

Instance Method Summary collapse

Constructor Details

#initializeKmlCreatorLineService

Returns a new instance of KmlCreatorLineService.



4
5
6
# File 'lib/map/kml_creator_line_service.rb', line 4

def initialize
  @lines = []
end

Instance Method Details

#add_line(coordinates) ⇒ Object



8
9
10
11
# File 'lib/map/kml_creator_line_service.rb', line 8

def add_line(coordinates)
  @lines << coordinates
  self
end

#to_xmlObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/map/kml_creator_line_service.rb', line 13

def to_xml
  Nokogiri::XML::Builder.new do |xml|
    xml.kml do
      xml.Document do
        xml.name 'KML_GENERATED'
        @lines.each_with_index do |coordinates, index|
          xml.Placemark do
            xml.name "Line#{index}"
            xml.LineString do
              xml.tessellate 1
              xml.coordinates coordinates.map{ |item| "#{item.second},#{item.first},0" }.join("\n")
            end
          end
        end
      end
    end
  end.to_xml
end