Class: MapPrint::Tile
- Inherits:
-
Object
- Object
- MapPrint::Tile
- Defined in:
- lib/map_print/tiles/tile.rb
Instance Method Summary collapse
- #cache_name ⇒ Object
- #coords ⇒ Object
- #download ⇒ Object
- #file_path ⇒ Object
-
#initialize(x, y, z, base_url) ⇒ Tile
constructor
A new instance of Tile.
- #provider_name ⇒ Object
- #tile_number_to_lat_lng ⇒ Object
- #tile_url ⇒ Object
Constructor Details
#initialize(x, y, z, base_url) ⇒ Tile
Returns a new instance of Tile.
6 7 8 9 10 11 |
# 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 |
Instance Method Details
#cache_name ⇒ Object
41 42 43 |
# File 'lib/map_print/tiles/tile.rb', line 41 def cache_name raise 'SubClasses should overwrite this method' end |
#coords ⇒ Object
13 14 15 |
# File 'lib/map_print/tiles/tile.rb', line 13 def coords {x: @x, y: @y, z: @z} end |
#download ⇒ Object
17 18 19 20 21 22 |
# 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 ⇒ Object
33 34 35 |
# File 'lib/map_print/tiles/tile.rb', line 33 def file_path File.join(folder_name, "#{@y}.png") end |
#provider_name ⇒ Object
37 38 39 |
# File 'lib/map_print/tiles/tile.rb', line 37 def provider_name raise 'SubClasses should overwrite this method' end |
#tile_number_to_lat_lng ⇒ Object
24 25 26 27 28 29 30 31 |
# 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 ⇒ Object
45 46 47 |
# File 'lib/map_print/tiles/tile.rb', line 45 def tile_url raise 'SubClasses should overwrite this method' end |