- session :off
- before_filter :check_read_availability, :except => [:capabilities]
- after_filter :compress_output
-
- # Help methods for checking boundary sanity and area size
- include MapBoundary
-
- #COUNT is the number of map requests to allow before exiting and starting a new process
- @@count = COUNT
-
- # The maximum area you're allowed to request, in square degrees
- MAX_REQUEST_AREA = APP_CONFIG['max_request_area']
-
- # Number of GPS trace/trackpoints returned per-page
- TRACEPOINTS_PER_PAGE = APP_CONFIG['tracepoints_per_page']
-
- # Get an XML response containing a list of tracepoints that have been uploaded
- # within the specified bounding box, and in the specified page.
- def trackpoints
- @@count+=1
- #retrieve the page number
- page = params['page'].to_i
- unless page
- page = 0;
- end
-
- unless page >= 0
- report_error("Page number must be greater than or equal to 0")
- return
- end
-
- offset = page * TRACEPOINTS_PER_PAGE
-
- # 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 => 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
-
- track = XML::Node.new 'trk'
- doc.root << track
-
- trkseg = XML::Node.new 'trkseg'
- track << trkseg
-
- points.each do |point|
- trkseg << point.to_xml_node()
- end
-
- #exit when we have too many requests
- if @@count > MAX_COUNT
- render :text => doc.to_s, :content_type => "text/xml"
- @@count = COUNT
- exit!