class MapPrint::Tile
Public Class Methods
new(x, y, z, base_url)
click to toggle source
# File lib/map_print/tiles/tile.rb, line 6 def initialize(x, y, z, base_url) @base_url = base_url @x = x @y = y @z = z end
Public Instance Methods
cache_name()
click to toggle source
# File lib/map_print/tiles/tile.rb, line 41 def cache_name raise 'SubClasses should overwrite this method' end
coords()
click to toggle source
# File lib/map_print/tiles/tile.rb, line 13 def coords {x: @x, y: @y, z: @z} end
download()
click to toggle source
# File lib/map_print/tiles/tile.rb, line 17 def download unless File.exists?(file_path) content = open(tile_url).read write_file(content) end end
file_path()
click to toggle source
# File lib/map_print/tiles/tile.rb, line 33 def file_path File.join(folder_name, "#{@y}.png") end
provider_name()
click to toggle source
# File lib/map_print/tiles/tile.rb, line 37 def provider_name raise 'SubClasses should overwrite this method' end
tile_number_to_lat_lng()
click to toggle source
# File lib/map_print/tiles/tile.rb, line 24 def tile_number_to_lat_lng n = 2.0 ** @z lon_deg = @x / n * 360.0 - 180.0 lat_rad = Math::atan(Math::sinh(Math::PI * (1 - 2 * @y / n))) lat_deg = 180.0 * (lat_rad / Math::PI) { lat: lat_deg, lng: lon_deg } end
tile_url()
click to toggle source
# File lib/map_print/tiles/tile.rb, line 45 def tile_url raise 'SubClasses should overwrite this method' end
Private Instance Methods
folder_name()
click to toggle source
# File lib/map_print/tiles/tile.rb, line 59 def folder_name "cache/#{cache_name}/#{@z}/#{@x}" end
write_file(content)
click to toggle source
# File lib/map_print/tiles/tile.rb, line 51 def write_file(content) FileUtils.mkdir_p(folder_name) File.open file_path, 'wb' do |f| f.write content end end