2026-04-12-1

This commit is contained in:
Hamza-Ayed
2026-04-12 22:35:38 +03:00
parent e3799c422c
commit 5ebd7ea3b1
84 changed files with 532 additions and 5136 deletions
+12 -5
View File
@@ -10,18 +10,25 @@ export class MapsService {
this.graphHopperUrl = this.configService.get('GRAPH_HOPPER_URL', 'http://routing:8080');
}
async getRoute(from: [number, number], to: [number, number]) {
async getRoute(waypoints: [number, number][], profile: string = 'car') {
if (waypoints.length < 2) {
throw new HttpException('At least two waypoints are required', HttpStatus.BAD_REQUEST);
}
try {
// GraphHopper expects [lng, lat] order
const ghPoints = waypoints.map(wp => [wp[1], wp[0]]);
const payload: any = {
points: [[from[1], from[0]], [to[1], to[0]]],
profile: 'car',
points: ghPoints,
profile: profile,
locale: 'en',
calc_points: true,
points_encoded: true,
};
console.log(`Routing Request: ${from} -> ${to} via ${this.graphHopperUrl}`);
const response = await axios.post(`${this.graphHopperUrl}/route`, payload, { timeout: 5000 });
console.log(`Routing Request: ${waypoints.length} points via ${profile} on ${this.graphHopperUrl}`);
const response = await axios.post(`${this.graphHopperUrl}/route`, payload, { timeout: 10000 });
console.log('Routing SUCCESS');
const route = response.data.paths[0];