class Geospatial::Tiles
Constants
- D2R
- R2D
Radians to degrees multiplier
Attributes
box[R]
zoom[R]
Public Class Methods
new(box, zoom = 5)
click to toggle source
# File lib/geospatial/tiles.rb, line 29 def initialize(box, zoom = 5) @box = box @zoom = zoom end
Public Instance Methods
each(zoom = @zoom) { |zoom, x, y| ... }
click to toggle source
# File lib/geospatial/tiles.rb, line 54 def each(zoom = @zoom) return to_enum(:each, zoom) unless block_given? min = map(*@box.min, zoom) max = map(*@box.max, zoom) (min[0].floor...max[0].ceil).each do |x| # The y axis is reversed... (i.e. the origin is in the top left) (max[1].floor...min[1].ceil).each do |y| yield zoom, x, y end end end
map(longitude, latitude, zoom = @zoom)
click to toggle source
# File lib/geospatial/tiles.rb, line 37 def map(longitude, latitude, zoom = @zoom) n = 2 ** zoom x = n * ((longitude + 180.0) / 360.0) y = n * (1.0 - (Math::log(Math::tan(latitude * D2R) + (1.0 / Math::cos(latitude * D2R))) / Math::PI)) / 2.0 return x, y end
unmap(x, y, zoom = @zoom)
click to toggle source
# File lib/geospatial/tiles.rb, line 46 def unmap(x, y, zoom = @zoom) n = 2 ** zoom longitude = x / n * 360.0 - 180.0 latitude = Math::arctan(Math::sinh(Math::PI * (1.0 - 2.0 * y / n))) * R2D return longitude, latitude end