Class: Map::KmlCreatorService

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

Instance Method Summary collapse

Instance Method Details

#add_polygon(polygon) ⇒ Object



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

def add_polygon(polygon)
  (@polygons ||= []) << polygon
  self
end

#to_xmlObject



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

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