Class: GeoMonitor::LatLngPoint
- Inherits:
-
Object
- Object
- GeoMonitor::LatLngPoint
- Defined in:
- lib/geo_monitor/lat_lng_point.rb
Instance Attribute Summary collapse
-
#lat ⇒ Object
Returns the value of attribute lat.
-
#lng ⇒ Object
Returns the value of attribute lng.
Class Method Summary collapse
-
.from_number(xtile, ytile, zoom) ⇒ Object
Get the lat/lng for a specific tile at a zoom level From wiki.openstreetmap.org/wiki/Slippy_map_tilenames#Pseudo-code.
Instance Method Summary collapse
-
#initialize(lat: 0, lng: 0) ⇒ LatLngPoint
constructor
A new instance of LatLngPoint.
-
#to_3857 ⇒ Object
This needs better documentation, but projecting from EPSG:4326 to EPSG:3857.
Constructor Details
#initialize(lat: 0, lng: 0) ⇒ LatLngPoint
Returns a new instance of LatLngPoint.
4 5 6 7 |
# File 'lib/geo_monitor/lat_lng_point.rb', line 4 def initialize(lat: 0, lng: 0) @lat = lat.to_f @lng = lng.to_f end |
Instance Attribute Details
#lat ⇒ Object
Returns the value of attribute lat.
3 4 5 |
# File 'lib/geo_monitor/lat_lng_point.rb', line 3 def lat @lat end |
#lng ⇒ Object
Returns the value of attribute lng.
3 4 5 |
# File 'lib/geo_monitor/lat_lng_point.rb', line 3 def lng @lng end |
Class Method Details
.from_number(xtile, ytile, zoom) ⇒ Object
Get the lat/lng for a specific tile at a zoom level From wiki.openstreetmap.org/wiki/Slippy_map_tilenames#Pseudo-code
24 25 26 27 28 29 30 |
# File 'lib/geo_monitor/lat_lng_point.rb', line 24 def self.from_number(xtile, ytile, zoom) n = 2.0**zoom lng = xtile / n * 360.0 - 180.0 lat_rad = Math.atan(Math.sinh(Math::PI * (1 - 2 * ytile / n))) lat = 180.0 * (lat_rad / Math::PI) new(lat: lat, lng: lng) end |
Instance Method Details
#to_3857 ⇒ Object
This needs better documentation, but projecting from EPSG:4326 to EPSG:3857
12 13 14 15 16 17 18 19 20 |
# File 'lib/geo_monitor/lat_lng_point.rb', line 12 def to_3857 d = Math::PI / 180 max = 1 - 1E-15 sin = [[Math.sin(lat * d), max].min, -max].max self.class.new( lng: ::GeoMonitor::Constants::R * lng * d, lat: ::GeoMonitor::Constants::R * Math.log((1 + sin) / (1 - sin)) / 2 ) end |