class Tiler

Attributes

end_lat[RW]
end_lon[RW]
end_x[RW]
end_y[RW]
output[RW]
source[RW]
start_lat[RW]
start_lon[RW]
start_x[RW]
start_y[RW]
zoom[RW]

Public Class Methods

new(args = {}) click to toggle source
# File lib/tiler.rb, line 31
def initialize(args = {})
  set_rectangle(args)
  args = defaults.merge(args)

  self.zoom   = args[:zoom]
  self.source = args[:source]
  self.output = args[:output]
end

Public Instance Methods

defaults() click to toggle source
# File lib/tiler.rb, line 40
def defaults
  { zoom: 1, source: "sattelite", start_x: 0, start_y: 0, end_x: 0, end_y: 0}
end
run() click to toggle source
# File lib/tiler.rb, line 48
def run
  download
  stitch
  cleanup
end
tiles() click to toggle source
# File lib/tiler.rb, line 44
def tiles
  @tiles ||= TilesCollection.new(zoom: zoom, source: source, start_x: start_x, start_y: start_y, end_x: end_x, end_y: end_y, output: output)
end

Private Instance Methods

given_lat_lon?(args) click to toggle source
# File lib/tiler.rb, line 95
def given_lat_lon?(args)
  args.has_key?(:start_lat) && args[:start_lat].is_a?(Float) &&
  args.has_key?(:start_lon) && args[:start_lon].is_a?(Float) &&
  args.has_key?(:end_lat)   && args[:end_lat].is_a?(Float)   &&
  args.has_key?(:end_lon)   && args[:end_lon].is_a?(Float)
end
given_x_y?(args) click to toggle source
# File lib/tiler.rb, line 88
def given_x_y?(args)
  args.has_key?(:start_x) && args[:start_x].is_a?(Integer) &&
  args.has_key?(:start_y) && args[:start_y].is_a?(Integer) &&
  args.has_key?(:end_x)   && args[:end_x].is_a?(Integer)   &&
  args.has_key?(:end_y)   && args[:end_y].is_a?(Integer)   
end
set_lat_lon(args) click to toggle source
# File lib/tiler.rb, line 81
def set_lat_lon(args)
  self.start_lat    = args[:start_lat]
  self.start_lon    = args[:start_lon]
  self.end_lat      = args[:end_lat]
  self.end_lon      = args[:end_lon]
end
set_rectangle(args) click to toggle source
# File lib/tiler.rb, line 56
def set_rectangle(args)
  if given_lat_lon?(args)
    set_lat_lon(args)
    set_x_y_from_lat_lon(args)
  elsif given_x_y?(args)
    set_x_y(args)
  end
end
set_x_y(args) click to toggle source
# File lib/tiler.rb, line 74
def set_x_y(args)
  self.start_x      = args[:start_x]
  self.start_y      = args[:start_y]
  self.end_x        = args[:end_x]
  self.end_y        = args[:end_y]
end
set_x_y_from_lat_lon(args) click to toggle source
# File lib/tiler.rb, line 65
def set_x_y_from_lat_lon(args)
  start        = SimpleMercatorLocation.new(lat: args[:start_lat], lon: args[:start_lon], zoom: args[:zoom])
  finish       = SimpleMercatorLocation.new(lat: args[:end_lat],   lon: args[:end_lon],   zoom: args[:zoom])
  self.start_x = start.to_tile.first
  self.start_y = start.to_tile.last
  self.end_x   = finish.to_tile.first
  self.end_y   = finish.to_tile.last
end