This repository has been archived on 2025-11-09. You can view files and clone it, but cannot push or open issues or pull requests.
Files
trafficcue-client/src/lib/vehicles/ValhallaVehicles.ts
Jannik 03838bf714
Some checks failed
TrafficCue CI / check (push) Failing after 1m8s
TrafficCue CI / build (push) Successful in 9m46s
TrafficCue CI / build-android (push) Successful in 25m15s
feat: localize voice guidance
2025-09-30 19:23:46 +02:00

72 lines
1.6 KiB
TypeScript

import { m } from "$lang/messages";
import type {
ValhallaCosting,
ValhallaCostingOptions,
ValhallaRequest,
} from "$lib/services/navigation/ValhallaRequest";
import type { Vehicle } from "./vehicles.svelte";
function getVehicleCosting(vehicle: Vehicle): ValhallaCosting {
switch (vehicle.type) {
case "car":
case "motorcycle":
return "auto";
case "truck":
return "truck";
case "bicycle":
return "bicycle";
case "motor_scooter":
return "motor_scooter";
default:
throw new Error("Invalid vehicle type");
}
}
export function createValhallaRequest(
vehicle: Vehicle,
locations: WorldLocation[],
): ValhallaRequest {
const costing = getVehicleCosting(vehicle);
const costingOptions: ValhallaCostingOptions =
costing == "auto"
? {
auto: {
top_speed: vehicle.legalMaxSpeed,
fixed_speed: vehicle.actualMaxSpeed,
},
}
: costing == "motor_scooter"
? {
motor_scooter: {
top_speed: vehicle.legalMaxSpeed,
fixed_speed: vehicle.actualMaxSpeed,
},
}
: costing == "truck"
? {
truck: {
top_speed: vehicle.legalMaxSpeed,
fixed_speed: vehicle.actualMaxSpeed,
length: vehicle.length,
weight: vehicle.weight,
axle_load: vehicle.axisLoad,
},
}
: costing == "bicycle"
? {
bicycle: {
cycling_speed: vehicle.actualMaxSpeed,
},
}
: {};
return {
locations,
costing,
units: "kilometers",
alternates: 2,
language: m["language.valhalla"](),
costing_options: costingOptions,
turn_lanes: true,
};
}