class Tile

Attributes

file[RW]
x[R]
y[R]
z[R]

Public Class Methods

new(args) click to toggle source
# File lib/tiler/tile.rb, line 11
def initialize(args)
  @x        = args[:x]
  @y        = args[:y]
  @z        = args[:z]
  @source   = args[:source] || "sattelite"
end

Public Instance Methods

download(dir) click to toggle source
# File lib/tiler/tile.rb, line 24
def download(dir)
  uri = URI.parse(remote_url)
  Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http|
    resp = http.get(uri.path)
    file = Tempfile.new("x_#{x}_y_#{y}_z_#{z}", dir, 'wb+')
    file.write(resp.body)
    file.flush
    puts "downloaded #{remote_url} to #{file.path}"
    @file = file
    @local_file_name = file.path
    file.close
    file
  end
end
downloaded?() click to toggle source
# File lib/tiler/tile.rb, line 45
def downloaded?
  !@local_file_name.nil?
end
local_file_name() click to toggle source
# File lib/tiler/tile.rb, line 40
def local_file_name
  @local_file_name
end
remote_url() click to toggle source
# File lib/tiler/tile.rb, line 19
def remote_url
  "https://khms0.google.com/kh/v=143&src=app&x=#{x}&y=#{y}&z=#{z.to_s}"
end