Class: MapPrint::TileFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/map_print/tiles/tile_factory.rb

Instance Method Summary collapse

Constructor Details

#initialize(base_url, type, sw_lat_lng, ne_lat_lng, zoom) ⇒ TileFactory

Returns a new instance of TileFactory.



8
9
10
11
12
13
14
# File 'lib/map_print/tiles/tile_factory.rb', line 8

def initialize(base_url, type, sw_lat_lng, ne_lat_lng, zoom)
  @base_url = base_url
  @type = type
  @sw_lat_lng = sw_lat_lng
  @ne_lat_lng = ne_lat_lng
  @zoom = zoom
end

Instance Method Details

#downloadObject



27
28
29
30
31
# File 'lib/map_print/tiles/tile_factory.rb', line 27

def download
  Parallel.each(tiles, in_processes: 20) do |tile|
    tile.download
  end
end

#px_offsetObject



16
17
18
19
20
21
22
23
24
25
# File 'lib/map_print/tiles/tile_factory.rb', line 16

def px_offset
  return @px_offset if @px_offset
  offset = {}

  offset[:top] = (ne_offset[:y] * 256).to_i
  offset[:right] = 256 - (ne_offset[:x] * 256).to_i
  offset[:bottom] = 256 - (sw_offset[:y] * 256).to_i
  offset[:left] = (sw_offset[:x] * 256).to_i
  @px_offset = offset
end

#tilesObject



41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/map_print/tiles/tile_factory.rb', line 41

def tiles
  return @tiles if @tiles

  @tiles = []
  y_array.each do |y|
    x_array.each do |x|
      @tiles << tile_class.new(x, y, @zoom, @base_url)
    end
  end

  @tiles
end

#x_sizeObject



33
34
35
# File 'lib/map_print/tiles/tile_factory.rb', line 33

def x_size
  x_array.size
end

#y_sizeObject



37
38
39
# File 'lib/map_print/tiles/tile_factory.rb', line 37

def y_size
  y_array.size
end