]> git.openstreetmap.org Git - rails.git/blob - app/controllers/api/tracepoints_controller.rb
Merge pull request #5333 from AntonKhorev/auth-buttons-same-as-preferred
[rails.git] / app / controllers / api / tracepoints_controller.rb
1 module Api
2   class TracepointsController < ApiController
3     authorize_resource
4
5     # Get an XML response containing a list of tracepoints that have been uploaded
6     # within the specified bounding box, and in the specified page.
7     def index
8       # retrieve the page number
9       page = params["page"].to_s.to_i
10
11       unless page >= 0
12         report_error("Page number must be greater than or equal to 0")
13         return
14       end
15
16       offset = page * Settings.tracepoints_per_page
17
18       # Figure out the bbox
19       # check boundary is sane and area within defined
20       # see /config/application.yml
21       begin
22         raise OSM::APIBadUserInput, "The parameter bbox is required" unless params[:bbox]
23
24         bbox = BoundingBox.from_bbox_params(params)
25         bbox.check_boundaries
26         bbox.check_size
27       rescue StandardError => e
28         report_error(e.message)
29         return
30       end
31
32       # get all the points
33       ordered_points = Tracepoint.bbox(bbox).joins(:trace).where(:gpx_files => { :visibility => %w[trackable identifiable] }).order("gpx_id DESC, trackid ASC, timestamp ASC")
34       unordered_points = Tracepoint.bbox(bbox).joins(:trace).where(:gpx_files => { :visibility => %w[public private] }).order("gps_points.latitude", "gps_points.longitude", "gps_points.timestamp")
35       @points = ordered_points.union_all(unordered_points).offset(offset).limit(Settings.tracepoints_per_page).preload(:trace)
36
37       response.headers["Content-Disposition"] = "attachment; filename=\"tracks.gpx\""
38
39       render :formats => [:gpx]
40     end
41   end
42 end