Module: Worldize::WebMercator

Included in:
Countries
Defined in:
lib/worldize/web_mercator.rb

Instance Method Summary collapse

Instance Method Details

#lat2y(lat, max_y) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/worldize/web_mercator.rb', line 13

def lat2y(lat, max_y)
  π = Math::PI
  φ = -lat * π / 180
  
  Math.log(Math.tan(π / 4 + φ / 2)).
    rescale(-π..π, 0..max_y)
end

#lng2x(lng, max_x) ⇒ Object



9
10
11
# File 'lib/worldize/web_mercator.rb', line 9

def lng2x(lng, max_x)
  lng.rescale(-180..180, 0..max_x)
end