Class: Map::DownloadTilesService

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/map/download_tiles_service.rb

Constant Summary collapse

TILES_OVERHEAD =
1
MIN_FILE_SIZE =
500
SERVERS_OPEN_STREET_MAPS =
[
  'http://a.tile.openstreetmap.org',
  'http://b.tile.openstreetmap.org',
  'http://c.tile.openstreetmap.org'
].freeze
MAP_BOX_SERVER =
'https://api.mapbox.com/styles/v1/mapbox/satellite-v9/tiles/256'
MAP_BOX_TOKEN =
'pk.eyJ1IjoiaW5vdmFjYW8tYWdybzEiLCJhIjoiY2xoczRiNGx1MnVucTNkcGJ5cXN6bTZtMCJ9.0tT_B-kqD_GL0-VKvY15iw'

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ DownloadTilesService

Returns a new instance of DownloadTilesService.



18
19
20
21
22
23
24
25
# File 'lib/map/download_tiles_service.rb', line 18

def initialize(options = {})
  @zoom_min = options[:zoom] || options[:zoom_min]
  @zoom_max = options[:zoom] || options[:zoom_max]
  @boundary_ne = options[:boundary] || options[:boundary_ne]
  @boundary_sw = options[:boundary] || options[:boundary_sw]
  @output_directory = options[:output_directory]
  @server = options[:server]
end

Instance Method Details

#downloadObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/map/download_tiles_service.rb', line 27

def download
  ret = []

  (@zoom_min..@zoom_max).each do |zoom|
    tile_NE = Map::TileService.new(@boundary_ne.second, @boundary_ne.first, zoom).points
    tile_SW = Map::TileService.new(@boundary_sw.second, @boundary_sw.first, zoom).points

    tile_x = [tile_SW[:x] - TILES_OVERHEAD, 0].max # avoid negative values 
    tile_y = [tile_SW[:y] - TILES_OVERHEAD, 0].max # avoid negative values
    (tile_x..tile_NE[:x]+TILES_OVERHEAD).each do |point_x|
      (tile_y..tile_SW[:y]+TILES_OVERHEAD).each do |point_y|
        ret << {
          x: point_x,
          y: point_y,
          z: zoom,
          file: get_tile([point_x, point_y], zoom)
        }
      end
    end
  end

  ret
end