Class: Wukong::Geo::Quadtile
- Inherits:
-
Object
- Object
- Wukong::Geo::Quadtile
- Includes:
- Gorillib::Model
- Defined in:
- lib/wu/geo/quadtile.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#basename(options = {}) ⇒ Object
A.
-
#fetch ⇒ Object
Fetch the contents of a map tile from a tileserver.
- #packed_qk ⇒ Object
- #quadkey ⇒ Object
- #tile_url ⇒ Object
Class Method Details
.from_whatever(hsh) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/wu/geo/quadtile.rb', line 19 def self.from_whatever(hsh) zl = hsh[:zl] ? hsh[:zl].to_i : nil case when hsh[:tile_x].present? && hsh[:tile_y].present? && zl.present? tile_x, tile_y = [hsh[:tile_x], hsh[:tile_y]] when hsh[:longitude].present? && hsh[:latitude].present? && zl.present? tile_x, tile_y = Wukong::Geolocated.lng_lat_zl_to_tile_xy(hsh[:longitude], hsh[:latitude], zl) when hsh[:quadkey].present? quadkey = hsh[:quadkey] quadkey = quadkey[0..zl] if zl.to_i > 0 tile_x, tile_y, zl = Wukong::Geolocated.quadkey_to_tile_xy_zl(quadkey) else raise ArgumentError, "You must supply keys for either `:longitude`, `:latitude` and `:zl`; `:tile_x`, `:tile_y` and `:zl`; or `:quadkey`: #{hsh.inspect}" end return new(tile_x, tile_y, zl, hsh.to_hash) end |
.tileserver_conn ⇒ Object
36 37 38 |
# File 'lib/wu/geo/quadtile.rb', line 36 def self.tileserver_conn @tileserver_conn = Faraday.new(:url => tileserver_url_base) end |
Instance Method Details
#basename(options = {}) ⇒ Object
A
52 53 54 55 56 57 |
# File 'lib/wu/geo/quadtile.rb', line 52 def basename(={}) = { sep: '-', ext: 'png'} sep = [:sep] # "%s%s%02d%s%04d%s%04d.%s" % [slug, sep, zl, sep, tile_x, sep, tile_y, options[:ext]] "%s/%02d/%s%s%s.%s" % [slug, zl, slug, sep, quadkey, [:ext]] end |
#fetch ⇒ Object
Fetch the contents of a map tile from a tileserver
You are responsible for requiring the faraday library and its adapter
63 64 65 |
# File 'lib/wu/geo/quadtile.rb', line 63 def fetch self.class.tileserver_conn.get(tile_url) end |
#packed_qk ⇒ Object
12 |
# File 'lib/wu/geo/quadtile.rb', line 12 def packed_qk ; Wukong::Geolocated.tile_xy_zl_to_packed_qk(tile_x, tile_y, zl) ; end |
#quadkey ⇒ Object
11 |
# File 'lib/wu/geo/quadtile.rb', line 11 def quadkey ; Wukong::Geolocated.tile_xy_zl_to_quadkey( tile_x, tile_y, zl) ; end |
#tile_url ⇒ Object
40 41 42 |
# File 'lib/wu/geo/quadtile.rb', line 40 def tile_url [tileserver_url_base, zl, tile_x, tile_y].join('/') << ".png" end |