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)
17 format("%.7f", self).to_f
21 # This scaling factor is used to convert between the float lat/lon that is
22 # returned by the API, and the integer lat/lon equivalent that is stored in
27 scope :bbox, ->(bbox) { where(OSM.sql_for_area(bbox, "#{table_name}.")) }
28 before_save :update_tile
31 # Is this node within -90 >= latitude >= 90 and -180 >= longitude >= 180
32 # * returns true/false
34 return false if lat < -90 || lat > 90
35 return false if lon < -180 || lon > 180
41 self.tile = QuadTile.tile_for_point(lat, lon)
45 self.latitude = (l * SCALE).round
49 self.longitude = (l * SCALE).round
52 # Return WGS84 latitude
54 Coord.new(latitude.to_f / SCALE)
57 # Return WGS84 longitude
59 Coord.new(longitude.to_f / SCALE)