module MapProject
Constants
- FACTOR_TO_DEG
- FACTOR_TO_RAD
- GOOGLE_MAPS_MAX_LAT
- GOOGLE_MAPS_MAX_LONG
- LN2
- PIXEL_PER_DEG
- PIXEL_PER_RAD
- TILE_SIZE
- VERSION
- WORLD_PX
- ZERO_ZERO_PX
- ZOOM_MAX
Public Instance Methods
get_bounds_zoom_level(bounds, viewport_w, viewport_h)
click to toggle source
Get the zoom level for a viewport given latlng boundary
# File lib/map_project.rb, line 8 def get_bounds_zoom_level(bounds, viewport_w, viewport_h) ne = bounds[:ne] sw = bounds[:sw] lat_fraction = (lat_rad(ne[0]) - lat_rad(sw[0])) / Math::PI lng_diff = ne[1] - sw[1] lng_fraction = ((lng_diff < 0) ? (lng_diff + 360) : lng_diff) / 360 lat_zoom = zoom(viewport_h, WORLD_PX, lat_fraction) lng_zoom = zoom(viewport_w, WORLD_PX, lng_fraction) [[lat_zoom, lng_zoom].min, ZOOM_MAX].min end
lat_rad(lat)
click to toggle source
# File lib/map_project.rb, line 19 def lat_rad(lat) sin = Math.sin(Rational(lat * Math::PI, 180)) rad_x2 = Math.log((1 + sin) / (1 - sin)) / 2 [[rad_x2, Math::PI].min, -Math::PI].max / 2 end
zoom(map_px, world_px, fraction)
click to toggle source
# File lib/map_project.rb, line 25 def zoom(map_px, world_px, fraction) (Math.log(Rational(map_px, world_px) / fraction) / LN2).floor end