2   extend ActiveSupport::Concern
 
   4   # Ensure that when coordinates are printed that they are always in decimal degrees,
 
   6   # Unfortunately you can't extend Numeric classes directly (e.g. `Coord < Float`).
 
   7   class Coord < DelegateClass(Float)
 
   9       format("%<coord>.7f", :coord => self)
 
  13       format("%<coord>.7f", :coord => self).to_f
 
  17   # This scaling factor is used to convert between the float lat/lon that is
 
  18   # returned by the API, and the integer lat/lon equivalent that is stored in
 
  23     scope :bbox, ->(bbox) { where(OSM.sql_for_area(bbox, "#{table_name}.")) }
 
  24     before_save :update_tile
 
  27   # Is this node within -90 >= latitude >= 90 and -180 >= longitude >= 180
 
  28   # * returns true/false
 
  30     return false if lat < -90 || lat > 90
 
  31     return false if lon < -180 || lon > 180
 
  37     self.tile = QuadTile.tile_for_point(lat, lon)
 
  41     self.latitude = (l * SCALE).round
 
  45     self.longitude = (l * SCALE).round
 
  48   # Return WGS84 latitude
 
  50     Coord.new(latitude.to_f / SCALE)
 
  53   # Return WGS84 longitude
 
  55     Coord.new(longitude.to_f / SCALE)