use of com.mapbox.api.directions.v5.models.DirectionsRoute in project mapbox-navigation-android by mapbox.
the class SnapToRouteTest method setUp.
@Before
public void setUp() throws Exception {
Gson gson = new GsonBuilder().registerTypeAdapterFactory(DirectionsAdapterFactory.create()).create();
String body = loadJsonFixture(MULTI_LEG_ROUTE);
DirectionsResponse response = gson.fromJson(body, DirectionsResponse.class);
route = response.routes().get(0);
routeProgress = RouteProgress.builder().stepIndex(0).legIndex(0).legDistanceRemaining(100).stepDistanceRemaining(100).distanceRemaining(100).directionsRoute(route).build();
}
use of com.mapbox.api.directions.v5.models.DirectionsRoute in project mapbox-navigation-android by mapbox.
the class NavigationHelper method increaseIndex.
/**
* This is used when a user has completed a step maneuver and the indices need to be incremented.
* The main purpose of this class is to determine if an additional leg exist and the step index
* has met the first legs total size, a leg index needs to occur and step index should be reset.
* Otherwise, the step index is incremented while the leg index remains the same.
* <p>
* Rather than returning an int array, a new instance of Navigation Indices gets returned. This
* provides type safety and making the code a bit more readable.
* </p>
*
* @param routeProgress need a routeProgress in order to get the directions route leg list size
* @param previousIndices used for adjusting the indices
* @return a {@link NavigationIndices} object which contains the new leg and step indices
*/
static NavigationIndices increaseIndex(RouteProgress routeProgress, NavigationIndices previousIndices) {
DirectionsRoute route = routeProgress.directionsRoute();
int previousStepIndex = previousIndices.stepIndex();
int previousLegIndex = previousIndices.legIndex();
int routeLegSize = route.legs().size();
int legStepSize = route.legs().get(routeProgress.legIndex()).steps().size();
boolean isOnLastLeg = previousLegIndex == routeLegSize - 1;
boolean isOnLastStep = previousStepIndex == legStepSize - 1;
if (isOnLastStep && !isOnLastLeg) {
return NavigationIndices.create((previousLegIndex + 1), 0);
}
if (isOnLastStep) {
return previousIndices;
}
return NavigationIndices.create(previousLegIndex, (previousStepIndex + 1));
}
use of com.mapbox.api.directions.v5.models.DirectionsRoute in project mapbox-navigation-android by mapbox.
the class NavigationHelper method stepDistanceRemaining.
/**
* Calculates the distance remaining in the step from the current users snapped position, to the
* next maneuver position.
*/
static double stepDistanceRemaining(Point snappedPosition, int legIndex, int stepIndex, DirectionsRoute directionsRoute, List<Point> coordinates) {
List<LegStep> steps = directionsRoute.legs().get(legIndex).steps();
Point nextManeuverPosition = nextManeuverPosition(stepIndex, steps, coordinates);
LineString lineString = LineString.fromPolyline(steps.get(stepIndex).geometry(), Constants.PRECISION_6);
// position or the linestring coordinate size is less than 2,the distance remaining is zero.
if (snappedPosition.equals(nextManeuverPosition) || lineString.coordinates().size() < 2) {
return 0;
}
LineString slicedLine = TurfMisc.lineSlice(snappedPosition, nextManeuverPosition, lineString);
return TurfMeasurement.length(slicedLine, TurfConstants.UNIT_METERS);
}
use of com.mapbox.api.directions.v5.models.DirectionsRoute in project mapbox-navigation-android by mapbox.
the class NavigationRouteProcessor method checkNewRoute.
/**
* Checks if the route provided is a new route. If it is, all {@link RouteProgress}
* data and {@link NavigationIndices} needs to be reset.
*
* @param mapboxNavigation to get the current route and off-route engine
*/
private void checkNewRoute(MapboxNavigation mapboxNavigation) {
DirectionsRoute directionsRoute = mapboxNavigation.getRoute();
if (RouteUtils.isNewRoute(previousRouteProgress, directionsRoute)) {
stepPoints = decodeStepPoints(directionsRoute, FIRST_LEG_INDEX, FIRST_STEP_INDEX);
updateOffRouteDetectorStepPoints(mapboxNavigation.getOffRouteEngine(), stepPoints);
previousRouteProgress = RouteProgress.builder().stepDistanceRemaining(directionsRoute.legs().get(FIRST_LEG_INDEX).steps().get(FIRST_STEP_INDEX).distance()).legDistanceRemaining(directionsRoute.legs().get(FIRST_LEG_INDEX).distance()).distanceRemaining(directionsRoute.distance()).directionsRoute(directionsRoute).stepIndex(FIRST_STEP_INDEX).legIndex(FIRST_LEG_INDEX).build();
indices = NavigationIndices.create(FIRST_LEG_INDEX, FIRST_STEP_INDEX);
}
}
use of com.mapbox.api.directions.v5.models.DirectionsRoute in project mapbox-navigation-android by mapbox.
the class BaseTest method buildDirectionsRoute.
protected DirectionsRoute buildDirectionsRoute() throws IOException {
Gson gson = new GsonBuilder().registerTypeAdapterFactory(DirectionsAdapterFactory.create()).create();
String body = loadJsonFixture(DIRECTIONS_PRECISION_6);
DirectionsResponse response = gson.fromJson(body, DirectionsResponse.class);
DirectionsRoute aRoute = response.routes().get(0);
return aRoute;
}
Aggregations