This commit is contained in:
Андрей Дувакин 2024-10-08 09:52:31 +05:00
parent 6ef4ec1fda
commit f7301f9635

View File

@ -98,6 +98,8 @@ const DeliveryOrdersList = ({
}) })
); );
const fullCoordinates = [...coords, DELIVERY_CITY];
if (fullCoordinates.length > 1) { if (fullCoordinates.length > 1) {
const waypoints = fullCoordinates const waypoints = fullCoordinates
.map(({ longitude, latitude }) => `${longitude},${latitude}`) .map(({ longitude, latitude }) => `${longitude},${latitude}`)
@ -120,24 +122,6 @@ const DeliveryOrdersList = ({
); );
} }
} }
const fullCoordinates = [...coords, DELIVERY_CITY];
const routeUrl = `https://router.project-osrm.org/route/v1/driving/${order.start_longitude},${order.start_latitude};${order.end_longitude},${order.end_latitude}?overview=full`;
const response = await fetch(routeUrl);
const data = await response.json();
if (data.routes && data.routes.length > 0) {
const duration = data.routes[0].duration;
const geometry = data.routes[0].geometry;
const decodedRoute = polyline.decode(geometry);
await updateDeliveryOrderRoute(
order.id,
duration / 60,
decodedRoute
);
}
} catch (error) { } catch (error) {
console.error("Ошибка при расчете маршрута для подзаказа:", error); console.error("Ошибка при расчете маршрута для подзаказа:", error);
} }
@ -145,7 +129,8 @@ const DeliveryOrdersList = ({
); );
fetchDeliveryOrders(); fetchDeliveryOrders();
}; };
const ordersToCalculate = deliveryOrders.filter( const ordersToCalculate = deliveryOrders.filter(
(order) => !order.estimated_route_time_in_minutes (order) => !order.estimated_route_time_in_minutes