Class: Tile

Inherits:
Object
  • Object
show all
Defined in:
lib/tiler/tile.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Tile

Returns a new instance of Tile.



8
9
10
11
12
13
# File 'lib/tiler/tile.rb', line 8

def initialize(args)
  @x        = args[:x]
  @y        = args[:y]
  @z        = args[:z]
  @source   = args[:source] || "sattelite"
end

Instance Attribute Details

#fileObject

Returns the value of attribute file.



6
7
8
# File 'lib/tiler/tile.rb', line 6

def file
  @file
end

#xObject (readonly)

Returns the value of attribute x.



4
5
6
# File 'lib/tiler/tile.rb', line 4

def x
  @x
end

#yObject (readonly)

Returns the value of attribute y.



4
5
6
# File 'lib/tiler/tile.rb', line 4

def y
  @y
end

#zObject (readonly)

Returns the value of attribute z.



4
5
6
# File 'lib/tiler/tile.rb', line 4

def z
  @z
end

Instance Method Details

#downloadObject



19
20
21
22
23
24
25
26
27
# File 'lib/tiler/tile.rb', line 19

def download
  open(remote_url) do |image|
    file = Tempfile.new("x_#{x}_y_#{y}_z_#{z}")
    file.write(image.read)
    puts "downloaded #{remote_url} to #{file.path}"
    @file = file
    @local_file_name = file.path
  end
end

#downloaded?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/tiler/tile.rb', line 33

def downloaded?
  !@local_file_name.nil?
end

#local_file_nameObject



29
30
31
# File 'lib/tiler/tile.rb', line 29

def local_file_name
  @local_file_name
end

#remote_urlObject



15
16
17
# File 'lib/tiler/tile.rb', line 15

def remote_url
  "https://khms0.google.com/kh/v=143&src=app&x=#{x}&y=#{y}&z=#{z.to_s}"
end