class Gull::Polygon

Attributes

coordinates[RW]

Public Class Methods

new(polygon) click to toggle source
# File lib/gull/polygon.rb, line 5
def initialize(polygon)
  self.coordinates = polygon.split(' ')
                            .map { |point| point.split(',').map(&:to_f) }
end

Public Instance Methods

image_url(api_key, options = {}) click to toggle source
# File lib/gull/polygon.rb, line 10
def image_url(api_key, options = {})
  options = {
    width: 640,
    height: 640,
    color: '0xff0000',
    weight: 3,
    fillcolor: '0xff000060',
    maptype: 'roadmap'
  }.merge(options)

  url_base = 'http://maps.googleapis.com/maps/api/staticmap'
  "#{url_base}?size=#{options[:width]}x#{options[:height]}" \
  "&maptype=#{options[:maptype]}&path=color:#{options[:color]}" \
  "|weight:#{options[:weight]}|fillcolor:#{options[:fillcolor]}" \
  "|#{coordinates_piped}&key=#{api_key}"
end
to_s() click to toggle source
# File lib/gull/polygon.rb, line 27
def to_s
  coordinates.map { |pair| pair.join(',') }.join(' ')
end
to_wkt() click to toggle source

Returns well-known text (WKT) formatted polygon

# File lib/gull/polygon.rb, line 32
def to_wkt
  pairs = coordinates.map { |pair| "#{pair.last} #{pair.first}" }
                     .join(', ')
  "POLYGON((#{pairs}))"
end

Private Instance Methods

coordinates_piped() click to toggle source
# File lib/gull/polygon.rb, line 40
def coordinates_piped
  coordinates.map { |pair| pair.join ',' }.join '|'
end