]> git.openstreetmap.org Git - rails.git/blob - lib/map_boundary.rb
Fixed xml method of old way model.
[rails.git] / lib / map_boundary.rb
1 module MapBoundary
2   def sanitise_boundaries(bbox)
3     min_lon = [bbox[0].to_f,-180].max
4     min_lat = [bbox[1].to_f,-90].max
5     max_lon = [bbox[2].to_f,+180].min
6     max_lat = [bbox[3].to_f,+90].min
7
8     return min_lon, min_lat, max_lon, max_lat
9   end
10
11   def check_boundaries(min_lon, min_lat, max_lon, max_lat)
12     # check the bbox is sane
13     unless min_lon <= max_lon
14       raise("The minimum longitude must be less than the maximum longitude, but it wasn't")
15     end
16     unless min_lat <= max_lat
17       raise("The minimum latitude must be less than the maximum latitude, but it wasn't")
18     end
19     unless min_lon >= -180 && min_lat >= -90 && max_lon <= 180 && max_lat <= 90
20       raise("The latitudes must be between -90 and 90, and longitudes between -180 and 180")
21     end
22
23     # check the bbox isn't too large
24     requested_area = (max_lat-min_lat)*(max_lon-min_lon)
25     if requested_area > APP_CONFIG['max_request_area']
26       raise("The maximum bbox size is " + APP_CONFIG['max_request_area'].to_s + 
27         ", and your request was too large. Either request a smaller area, or use planet.osm")
28     end
29   end
30 end