fix(travel): Mapbox route optimized
This commit is contained in:
@@ -57,16 +57,9 @@ async function getUlysTollLegs(encodedPolyline) {
|
||||
if (process.env.MAPBOX_API_KEY && polylineCoords.length > 2) {
|
||||
logger.info('[Travel] MAPBOX_API_KEY is present. Recreating route with Mapbox for Ulys precision...');
|
||||
try {
|
||||
// Extraire jusqu'à 25 waypoints (limite Mapbox Directions API) équidistants
|
||||
const maxWaypoints = 25;
|
||||
const waypoints = [];
|
||||
const step = Math.max(1, Math.floor(polylineCoords.length / (maxWaypoints - 1)));
|
||||
for (let i = 0; i < polylineCoords.length; i += step) {
|
||||
waypoints.push(polylineCoords[i]);
|
||||
}
|
||||
if (waypoints[waypoints.length - 1] !== polylineCoords[polylineCoords.length - 1]) {
|
||||
waypoints[waypoints.length - 1] = polylineCoords[polylineCoords.length - 1]; // Ensure last point is exactly destination
|
||||
}
|
||||
// Envoyer uniquement le point de départ et le point d'arrivée
|
||||
// Mapbox s'occupe de recréer l'itinéraire complet de la meilleure façon
|
||||
const waypoints = [polylineCoords[0], polylineCoords[polylineCoords.length - 1]];
|
||||
|
||||
// Mapbox expects longitude,latitude
|
||||
const coordinatesString = waypoints.map(p => `${p[1]},${p[0]}`).join(';');
|
||||
@@ -363,3 +356,5 @@ function _parseDuration(durationStr) {
|
||||
const match = String(durationStr).match(/^(\d+)s?$/);
|
||||
return match ? parseInt(match[1]) : 0;
|
||||
}
|
||||
|
||||
exports.getUlysTollLegs = getUlysTollLegs;
|
||||
|
||||
Reference in New Issue
Block a user