]> git.openstreetmap.org Git - rails.git/blob - lib/map_boundary.rb
Reuse the map_bug_comment table as a more general history table of map_bugs including...
[rails.git] / lib / map_boundary.rb
1 module MapBoundary
2   # Take an array of length 4, and return the min_lon, min_lat, max_lon and 
3   # max_lat within their respective boundaries.
4   def sanitise_boundaries(bbox)
5     min_lon = [[bbox[0].to_f,-180].max,180].min
6     min_lat = [[bbox[1].to_f,-90].max,90].min
7     max_lon = [[bbox[2].to_f,+180].min,-180].max
8     max_lat = [[bbox[3].to_f,+90].min,-90].max
9     return min_lon, min_lat, max_lon, max_lat
10   end
11
12   def check_boundaries(min_lon, min_lat, max_lon, max_lat, limit_small_area = :true)
13     # check the bbox is sane
14     unless min_lon <= max_lon
15       raise OSM::APIBadBoundingBox.new("The minimum longitude must be less than the maximum longitude, but it wasn't")
16     end
17     unless min_lat <= max_lat
18       raise OSM::APIBadBoundingBox.new("The minimum latitude must be less than the maximum latitude, but it wasn't")
19     end
20     unless min_lon >= -180 && min_lat >= -90 && max_lon <= 180 && max_lat <= 90
21       # Due to sanitize_boundaries, it is highly unlikely we'll actually get here
22       raise OSM::APIBadBoundingBox.new("The latitudes must be between -90 and 90, and longitudes between -180 and 180")
23     end
24
25         return unless limit_small_area == :true
26
27     # check the bbox isn't too large
28     requested_area = (max_lat-min_lat)*(max_lon-min_lon)
29     if requested_area > APP_CONFIG['max_request_area']
30       raise OSM::APIBadBoundingBox.new("The maximum bbox size is " + APP_CONFIG['max_request_area'].to_s + 
31         ", and your request was too large. Either request a smaller area, or use planet.osm")
32     end
33   end
34 end