]> git.openstreetmap.org Git - rails.git/blob - lib/map_boundary.rb
added translation for delete buttons, uptodate with en.yml 16657 now.
[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)
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     # check the bbox isn't too large
26     requested_area = (max_lat-min_lat)*(max_lon-min_lon)
27     if requested_area > APP_CONFIG['max_request_area']
28       raise OSM::APIBadBoundingBox.new("The maximum bbox size is " + APP_CONFIG['max_request_area'].to_s + 
29         ", and your request was too large. Either request a smaller area, or use planet.osm")
30     end
31   end
32 end