2026-04-16-1

This commit is contained in:
Hamza-Ayed
2026-04-16 03:39:49 +03:00
parent 3d61362602
commit 58f06eeba3
15 changed files with 579 additions and 106 deletions
+2 -1
View File
@@ -107,8 +107,9 @@ export class MapsController {
const profile = query.profile || 'car';
const steps = query.steps === 'true';
const locale = query.locale || 'en';
const alternatives = query.alternatives === 'true';
return this.mapsService.getRoute(waypoints, profile, steps, locale);
return this.mapsService.getRoute(waypoints, profile, steps, locale, alternatives);
}
@Get('config')
+4 -4
View File
@@ -22,7 +22,7 @@ export class MapsService {
this.graphHopperUrl = this.configService.get('GRAPH_HOPPER_URL', 'http://routing:8080');
}
async getRoute(waypoints: [number, number][], profile: string = 'car', steps: boolean = false, locale: string = 'en') {
async getRoute(waypoints: [number, number][], profile: string = 'car', steps: boolean = false, locale: string = 'en', alternatives: boolean = false) {
if (waypoints.length < 2) {
throw new HttpException('At least two waypoints are required', HttpStatus.BAD_REQUEST);
}
@@ -64,7 +64,7 @@ export class MapsService {
};
// GraphHopper ONLY supports alternative routes if there are exactly 2 points (Start and End)
if (waypoints.length === 2) {
if (alternatives && waypoints.length === 2) {
payload.algorithm = 'alternative_route';
payload['ch.disable'] = true; // Required for alternative routes
payload['alternative_route.max_paths'] = 2; // Return main route + 1 alternative
@@ -93,7 +93,7 @@ export class MapsService {
const trafficAwareDuration = baseDuration * trafficFactor;
// Process alternative routes if any without breaking existing frontend variables
const alternatives = paths.slice(1).map(alt => ({
const altRoutes = paths.slice(1).map(alt => ({
distance: alt.distance,
duration: Math.round(alt.time / 1000),
points: alt.points,
@@ -111,7 +111,7 @@ export class MapsService {
points: route.points,
bbox: route.bbox,
instructions: route.instructions, // Added: turn-by-turn maneuvers
alternatives: alternatives
alternatives: altRoutes
};
} catch (error) {
const msg = error.response ? `GH Error: ${JSON.stringify(error.response.data)}` : `DNS/Connection Error: ${error.message}`;