Vehicle profiles (Car, Camper, ...), avoid tolls/motorways, per-country vignette and toll km for a route
CI / check (push) Successful in 19s
CI / deploy (push) Successful in 17s

This commit is contained in:
randy committed 2026-11-14 21:20:23 +01:00
1 parent 58ca871662
commit 69aa284e36
8 files changed
+328 -80

No files matched your search

+13 -10
View File
@@ -448,13 +448,14 @@ module Maptool
end
# A route through the posted points ({"locations": [[lon, lat], ...]})
# for the stored vehicle. Open to anyone, like viewing the map; only
# for the vehicle profile "vehicle" (an id, default the first). 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"]
body = JSON.parse(request.body.read)
locations = body["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))
json Routing.route(VALHALLA_URL, locations, Routing.vehicle(DATA_DIR, body["vehicle"]), body["avoid"])
rescue JSON::ParserError
halt 400, json(error: "invalid JSON")
rescue Routing::RouteError => e
@@ -463,11 +464,11 @@ module Maptool
halt 503, json(error: e.message)
end
# Where the stored vehicle gets in each of `minutes` from `center`
# Where the vehicle profile gets in each of `minutes` from `center`
# ({"center": [lon, lat], "minutes": [30, 60]}). Open like /api/route.
post "/api/isochrone" do
body = JSON.parse(request.body.read)
json Routing.isochrone(VALHALLA_URL, body["center"], body["minutes"], Routing.vehicle(DATA_DIR))
json Routing.isochrone(VALHALLA_URL, body["center"], body["minutes"], Routing.vehicle(DATA_DIR, body["vehicle"]), body["avoid"])
rescue JSON::ParserError
halt 400, json(error: "invalid JSON")
rescue Routing::RouteError => e
@@ -476,14 +477,16 @@ module Maptool
halt 503, json(error: e.message)
end
get "/api/vehicle" do
json Routing.vehicle(DATA_DIR)
get "/api/vehicles" do
json Routing.vehicles(DATA_DIR)
end
put "/api/vehicle" do
put "/api/vehicles" do
require_login!
json Routing.save_vehicle(DATA_DIR, params)
rescue ArgumentError, KeyError => e
json Routing.save_vehicles(DATA_DIR, JSON.parse(request.body.read))
rescue JSON::ParserError
halt 400, json(error: "invalid JSON")
rescue ArgumentError => e
halt 400, json(error: e.message)
end