2026-04-14-8 auth and commercial 0
This commit is contained in:
@@ -43,7 +43,10 @@ export class MapsController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const profile = query.profile || 'car';
|
const profile = query.profile || 'car';
|
||||||
return this.mapsService.getRoute(waypoints, profile);
|
const steps = query.steps === 'true';
|
||||||
|
const locale = query.locale || 'en';
|
||||||
|
|
||||||
|
return this.mapsService.getRoute(waypoints, profile, steps, locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get('config')
|
@Get('config')
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ export class MapsService {
|
|||||||
this.graphHopperUrl = this.configService.get('GRAPH_HOPPER_URL', 'http://routing:8080');
|
this.graphHopperUrl = this.configService.get('GRAPH_HOPPER_URL', 'http://routing:8080');
|
||||||
}
|
}
|
||||||
|
|
||||||
async getRoute(waypoints: [number, number][], profile: string = 'car') {
|
async getRoute(waypoints: [number, number][], profile: string = 'car', steps: boolean = false, locale: string = 'en') {
|
||||||
if (waypoints.length < 2) {
|
if (waypoints.length < 2) {
|
||||||
throw new HttpException('At least two waypoints are required', HttpStatus.BAD_REQUEST);
|
throw new HttpException('At least two waypoints are required', HttpStatus.BAD_REQUEST);
|
||||||
}
|
}
|
||||||
@@ -57,9 +57,10 @@ export class MapsService {
|
|||||||
const payload: any = {
|
const payload: any = {
|
||||||
points: ghPoints,
|
points: ghPoints,
|
||||||
profile: profile,
|
profile: profile,
|
||||||
locale: 'en',
|
locale: locale,
|
||||||
calc_points: true,
|
calc_points: true,
|
||||||
points_encoded: true,
|
points_encoded: true,
|
||||||
|
instructions: steps,
|
||||||
};
|
};
|
||||||
|
|
||||||
// GraphHopper ONLY supports alternative routes if there are exactly 2 points (Start and End)
|
// GraphHopper ONLY supports alternative routes if there are exactly 2 points (Start and End)
|
||||||
@@ -71,7 +72,7 @@ export class MapsService {
|
|||||||
payload['alternative_route.max_share_factor'] = 0.6;
|
payload['alternative_route.max_share_factor'] = 0.6;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`Routing Request: ${waypoints.length} points via ${profile} on ${this.graphHopperUrl}`);
|
console.log(`Routing Request: ${waypoints.length} points via ${profile} on ${this.graphHopperUrl} | Steps: ${steps} | Locale: ${locale}`);
|
||||||
const response = await axios.post(`${this.graphHopperUrl}/route`, payload, { timeout: 10000 });
|
const response = await axios.post(`${this.graphHopperUrl}/route`, payload, { timeout: 10000 });
|
||||||
|
|
||||||
console.log('Routing SUCCESS');
|
console.log('Routing SUCCESS');
|
||||||
@@ -96,7 +97,8 @@ export class MapsService {
|
|||||||
distance: alt.distance,
|
distance: alt.distance,
|
||||||
duration: Math.round(alt.time / 1000),
|
duration: Math.round(alt.time / 1000),
|
||||||
points: alt.points,
|
points: alt.points,
|
||||||
bbox: alt.bbox
|
bbox: alt.bbox,
|
||||||
|
instructions: alt.instructions // Include instructions for alternatives if requested
|
||||||
}));
|
}));
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -108,7 +110,8 @@ export class MapsService {
|
|||||||
endName,
|
endName,
|
||||||
points: route.points,
|
points: route.points,
|
||||||
bbox: route.bbox,
|
bbox: route.bbox,
|
||||||
alternatives: alternatives // NEW: array of other routes
|
instructions: route.instructions, // Added: turn-by-turn maneuvers
|
||||||
|
alternatives: alternatives
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const msg = error.response ? `GH Error: ${JSON.stringify(error.response.data)}` : `DNS/Connection Error: ${error.message}`;
|
const msg = error.response ? `GH Error: ${JSON.stringify(error.response.data)}` : `DNS/Connection Error: ${error.message}`;
|
||||||
|
|||||||
Reference in New Issue
Block a user