82 lines
2.4 KiB
TypeScript
82 lines
2.4 KiB
TypeScript
import type { LngLat } from "maplibre-gl";
|
|
|
|
class RoutePlanner {
|
|
fromPlace: LngLat;
|
|
toPlace: LngLat;
|
|
date: Date;
|
|
|
|
arriveBy = false;
|
|
routerId = "default";
|
|
optimize: OptimizeType = "QUICK";
|
|
walkSpeed = 1.1112;
|
|
walkReluctance = 10;
|
|
locale: string = "fr";
|
|
mode: Set<PlannerModes> = new Set(["WALK"]);
|
|
otpUrl = new URL("https://data.mobilites-m.fr/api/routers/default/plan");
|
|
|
|
showIntermediateStops?: boolean;
|
|
minTransferTime?: number;
|
|
transferPenalty?: number;
|
|
numItineraries?: number;
|
|
walkBoardCost?: number;
|
|
bannedAgencies?: string;
|
|
|
|
constructor(from: LngLat, to: LngLat) {
|
|
this.fromPlace = from;
|
|
this.toPlace = to;
|
|
this.date = new Date();
|
|
}
|
|
|
|
toURLSearchParams() {
|
|
const params: PlannerResource = {
|
|
fromPlace: `${this.fromPlace.lng},${this.fromPlace.lat}`,
|
|
toPlace: `${this.toPlace.lng},${this.toPlace.lat}`,
|
|
arriveBy: this.arriveBy.toString(),
|
|
date: this.date.toISOString().substring(0, 10),
|
|
time: this.date.toISOString().substring(11, 16),
|
|
routerId: this.routerId,
|
|
optimize: this.optimize,
|
|
walkSpeed: this.walkSpeed.toString(),
|
|
walkReluctance: this.walkReluctance.toString(),
|
|
locale: this.locale,
|
|
mode: Array.from(this.mode.values()).join(","),
|
|
};
|
|
if (this.showIntermediateStops) {
|
|
params["showIntermediateStops"] = this.showIntermediateStops.toString();
|
|
}
|
|
if (this.minTransferTime) {
|
|
params["minTransferTime"] = this.minTransferTime.toString();
|
|
}
|
|
if (this.transferPenalty) {
|
|
params["transferPenalty"] = this.transferPenalty.toString();
|
|
}
|
|
if (this.numItineraries) {
|
|
params["numItineraries"] = this.numItineraries.toString();
|
|
}
|
|
if (this.walkBoardCost) {
|
|
params["walkBoardCost"] = this.walkBoardCost.toString();
|
|
}
|
|
if (this.bannedAgencies) {
|
|
params["bannedAgencies"] = this.bannedAgencies.toString();
|
|
}
|
|
return new URLSearchParams(params);
|
|
}
|
|
|
|
async request() {
|
|
this.otpUrl.search = this.toURLSearchParams().toString();
|
|
return await $fetch<OTPPlanOutput>(this.otpUrl.toString());
|
|
}
|
|
}
|
|
|
|
class TransitRoutePlanner extends RoutePlanner {
|
|
override mode = new Set<PlannerModes>(["WALK", "TRANSIT"]);
|
|
override showIntermediateStops = true;
|
|
override minTransferTime = 60;
|
|
override transferPenalty = 60;
|
|
override numItineraries = 2;
|
|
override walkBoardCost = 300;
|
|
override bannedAgencies = "MCO:MCO";
|
|
}
|
|
|
|
export { RoutePlanner, TransitRoutePlanner };
|