Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/routes/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import * as journeyService from '../services/journey';
import * as reminderService from '../services/reminder';
import * as graphBuilder from '../services/graphBuilder';
import { startBackgroundJobs } from '../jobs';
import * as walking from '../walking/walkingMap';

/**
* Express router for the MBus API v3.
Expand Down Expand Up @@ -400,6 +401,31 @@ export async function planJourney(req: express.Request, res: express.Response) {
}
router.get('/plan-journey', planJourney);

export const PlanWalkingQuery = z.object({
originLat: z.coerce.number(), originLon: z.coerce.number(),
destLat: z.coerce.number(), destLon: z.coerce.number()
});

/** Calculates just the new walking path and responds with a [WalkingResponse] */
export async function planWalking(req: express.Request, res: express.Response) {
try {
const query = PlanWalkingQuery.safeParse(req.query);
if (!query.success) {
res.status(400);
res.send(query.error.message);
return;
}
const { originLat, originLon, destLat, destLon } = query.data;
const walkingResponse = await walking.getWalkingResponse(originLat, originLon, destLat, destLon);

res.json(walkingResponse);
} catch (error) {
console.error("Journey plan error:", error);
res.status(500).json({ error: 'Journey planning failed' });
}
}
router.get('/plan-walking', planWalking);

/**
* Saves the current graph state to a file (DEV mode only).
* @param req - Express request
Expand Down
8 changes: 8 additions & 0 deletions src/walking/walkingMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ export interface WalkingResponse {
distance: number;
/** Ordered list of coordinates representing the walking path geometry. */
path_coords: { lat: number, lon: number }[];
/** Turn by turn directions. */
directions: { path_index: number, turn: Turn }[];
}

export interface Turn {
/** [-180, 180]ish range, a positive number represents a left turn */
degrees: number,
landmark: string,
}

/**
Expand Down
Loading