feat(gis): restore premium OSM style and fix international routing bounds for Jordan & Syria
This commit is contained in:
@@ -7,55 +7,36 @@ export class MapsService {
|
||||
private readonly graphHopperUrl: string;
|
||||
|
||||
constructor(private configService: ConfigService) {
|
||||
this.graphHopperUrl = this.configService.get('GRAPH_HOPPER_URL', 'http://map-routing:8080');
|
||||
this.graphHopperUrl = this.configService.get('GRAPH_HOPPER_URL', 'http://routing:8080');
|
||||
}
|
||||
|
||||
async getRoute(from: [number, number], to: [number, number]) {
|
||||
// Proxy routing request to GraphHopper
|
||||
// تحويل طلب حساب المسارم إلى GraphHopper
|
||||
try {
|
||||
const response = await axios.get(`${this.graphHopperUrl}/route`, {
|
||||
params: {
|
||||
point: [`${from[0]},${from[1]}`, `${to[0]},${to[1]}`],
|
||||
profile: 'car',
|
||||
locale: 'en',
|
||||
calc_points: true,
|
||||
points_encoded: false,
|
||||
elevation: false,
|
||||
type: 'json',
|
||||
},
|
||||
paramsSerializer: (params) => {
|
||||
const searchParams = new URLSearchParams();
|
||||
Object.entries(params).forEach(([key, value]) => {
|
||||
if (Array.isArray(value)) {
|
||||
value.forEach(v => searchParams.append(key, v));
|
||||
} else {
|
||||
searchParams.append(key, value as any);
|
||||
}
|
||||
});
|
||||
return searchParams.toString();
|
||||
},
|
||||
});
|
||||
|
||||
console.log('Routing Successful:', response.request.path);
|
||||
const payload: any = {
|
||||
points: [[from[1], from[0]], [to[1], to[0]]],
|
||||
profile: 'car',
|
||||
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 SUCCESS');
|
||||
const route = response.data.paths[0];
|
||||
if (!route) {
|
||||
throw new HttpException('No route found', HttpStatus.NOT_FOUND);
|
||||
}
|
||||
if (!route) throw new HttpException('No route found', HttpStatus.NOT_FOUND);
|
||||
|
||||
return {
|
||||
distance: route.distance, // In meters
|
||||
duration: route.time / 1000, // In seconds
|
||||
points: route.points.coordinates, // Array of [lng, lat]
|
||||
distance: route.distance,
|
||||
duration: route.time / 1000,
|
||||
points: route.points,
|
||||
bbox: route.bbox,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('Routing Error:', error.message);
|
||||
if (error.response) {
|
||||
console.error('GraphHopper Response:', error.response.data);
|
||||
}
|
||||
throw new HttpException('Error calculating route', HttpStatus.BAD_GATEWAY);
|
||||
const msg = error.response ? `GH Error: ${JSON.stringify(error.response.data)}` : `DNS/Connection Error: ${error.message}`;
|
||||
console.error('CRITICAL ROUTING FAILURE:', msg);
|
||||
throw new HttpException(`Routing Failure: ${msg}`, HttpStatus.BAD_GATEWAY);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user