Offline routing phase 2: route panel, /api/route via Valhalla, vehicle profile, save a route to the library
This commit is contained in:
1 parent
d93c77727f
commit
3146478c23
11 files changed
+577
-12
No files matched your search
@@ -447,6 +447,33 @@ module Maptool
|
||||
json Routing.build_status(DATA_DIR)
|
||||
end
|
||||
|
||||
# A route through the posted points ({"locations": [[lon, lat], ...]})
|
||||
# for the stored vehicle. Open to anyone, like viewing the map; only
|
||||
# saving it to the library needs a login.
|
||||
post "/api/route" do
|
||||
locations = JSON.parse(request.body.read)["locations"]
|
||||
halt 400, json(error: "locations must be a list of [lon, lat]") unless locations.is_a?(Array) && locations.all?(Array)
|
||||
|
||||
json Routing.route(VALHALLA_URL, locations, Routing.vehicle(DATA_DIR))
|
||||
rescue JSON::ParserError
|
||||
halt 400, json(error: "invalid JSON")
|
||||
rescue Routing::RouteError => e
|
||||
halt 422, json(error: e.message)
|
||||
rescue Routing::Unavailable => e
|
||||
halt 503, json(error: e.message)
|
||||
end
|
||||
|
||||
get "/api/vehicle" do
|
||||
json Routing.vehicle(DATA_DIR)
|
||||
end
|
||||
|
||||
put "/api/vehicle" do
|
||||
require_login!
|
||||
json Routing.save_vehicle(DATA_DIR, params)
|
||||
rescue ArgumentError, KeyError => e
|
||||
halt 400, json(error: e.message)
|
||||
end
|
||||
|
||||
# Same reasoning as DELETE /api/offline-tiles above.
|
||||
delete "/api/terrain-tiles" do
|
||||
require_login!
|
||||
|
||||
Reference in new issue
Block a user