Class: Map::DownloadTilesService
- Inherits:
-
Object
- Object
- Map::DownloadTilesService
- 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
- #download ⇒ Object
-
#initialize(options = {}) ⇒ DownloadTilesService
constructor
A new instance of DownloadTilesService.
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( = {}) @zoom_min = [:zoom] || [:zoom_min] @zoom_max = [:zoom] || [:zoom_max] @boundary_ne = [:boundary] || [:boundary_ne] @boundary_sw = [:boundary] || [:boundary_sw] @output_directory = [:output_directory] @server = [:server] end |
Instance Method Details
#download ⇒ Object
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 |