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