+ # Figure out the bbox
+ bbox = params['bbox']
+ unless bbox and bbox.count(',') == 3
+ report_error("The parameter bbox is required, and must be of the form min_lon,min_lat,max_lon,max_lat")
+ return
+ end
+
+ bbox = bbox.split(',')
+ min_lon, min_lat, max_lon, max_lat = sanitise_boundaries(bbox)
+ # check boundary is sane and area within defined
+ # see /config/application.yml
+ begin
+ check_boundaries(min_lon, min_lat, max_lon, max_lat)
+ rescue Exception => err
+ report_error(err.message)
+ return
+ end
+
+ # get all the points
+ points = Tracepoint.find_by_area(min_lat, min_lon, max_lat, max_lon, :offset => offset, :limit => APP_CONFIG['tracepoints_per_page'], :order => "timestamp DESC" )
+
+ doc = XML::Document.new
+ doc.encoding = XML::Encoding::UTF_8
+ root = XML::Node.new 'gpx'
+ root['version'] = '1.0'
+ root['creator'] = 'OpenStreetMap.org'
+ root['xmlns'] = "http://www.topografix.com/GPX/1/0/"
+
+ doc.root = root