From 8d2592fcb78d35a64d838bb4e2e92087c690cf2c Mon Sep 17 00:00:00 2001 From: mam17 Date: Fri, 25 Sep 2020 10:37:53 -0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Adding=20Distance=20and=20Duration?= =?UTF-8?q?=20for=20each=20waypoint?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/MapViewDirections.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/MapViewDirections.js b/src/MapViewDirections.js index ac08d73..be2fae5 100644 --- a/src/MapViewDirections.js +++ b/src/MapViewDirections.js @@ -184,7 +184,7 @@ class MapViewDirections extends Component { ); })).then(results => { // Combine all Directions API Request results into one - const result = results.reduce((acc, { distance, duration, coordinates, fare, waypointOrder }) => { + const result = results.reduce((acc, { distance, duration, coordinates, fare, waypointOrder, steps }) => { acc.coordinates = [ ...acc.coordinates, ...coordinates, @@ -199,6 +199,13 @@ class MapViewDirections extends Component { ...acc.waypointOrder, waypointOrder, ]; + acc.splitedSteps = steps.reduce((accumulator, step) => [ + ...accumulator, + { + distance: step.distance.value, + duration: step.duration.value, + }, + ], []); return acc; }, { @@ -207,6 +214,7 @@ class MapViewDirections extends Component { duration: 0, fares: [], waypointOrder: [], + splitedSteps: [], }); // Plot it out and call the onReady callback @@ -269,6 +277,7 @@ class MapViewDirections extends Component { ]; }, []) ), + steps: route.legs, fare: route.fare, waypointOrder: route.waypoint_order, });