Search in sources :

Example 6 with DirectionsRoute

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();
}
Also used : GsonBuilder(com.google.gson.GsonBuilder) Gson(com.google.gson.Gson) DirectionsResponse(com.mapbox.api.directions.v5.models.DirectionsResponse) Before(org.junit.Before)

Example 7 with DirectionsRoute

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));
}
Also used : DirectionsRoute(com.mapbox.api.directions.v5.models.DirectionsRoute) Point(com.mapbox.geojson.Point)

Example 8 with DirectionsRoute

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);
}
Also used : LineString(com.mapbox.geojson.LineString) Point(com.mapbox.geojson.Point) LegStep(com.mapbox.api.directions.v5.models.LegStep)

Example 9 with DirectionsRoute

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);
    }
}
Also used : DirectionsRoute(com.mapbox.api.directions.v5.models.DirectionsRoute)

Example 10 with DirectionsRoute

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;
}
Also used : GsonBuilder(com.google.gson.GsonBuilder) DirectionsRoute(com.mapbox.api.directions.v5.models.DirectionsRoute) Gson(com.google.gson.Gson) LineString(com.mapbox.geojson.LineString) DirectionsResponse(com.mapbox.api.directions.v5.models.DirectionsResponse)

Aggregations

DirectionsRoute (com.mapbox.api.directions.v5.models.DirectionsRoute)25 DirectionsResponse (com.mapbox.api.directions.v5.models.DirectionsResponse)14 Gson (com.google.gson.Gson)11 GsonBuilder (com.google.gson.GsonBuilder)11 BaseTest (com.mapbox.services.android.navigation.v5.BaseTest)10 RouteProgress (com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress)10 Test (org.junit.Test)10 RouteLeg (com.mapbox.api.directions.v5.models.RouteLeg)9 Before (org.junit.Before)7 Point (com.mapbox.geojson.Point)6 Location (android.location.Location)3 LegStep (com.mapbox.api.directions.v5.models.LegStep)3 LineString (com.mapbox.geojson.LineString)3 FasterRoute (com.mapbox.services.android.navigation.v5.route.FasterRoute)2 Feature (com.mapbox.services.commons.geojson.Feature)2 ArrayList (java.util.ArrayList)2 StepManeuver (com.mapbox.api.directions.v5.models.StepManeuver)1 NavigationRoute (com.mapbox.services.android.navigation.v5.navigation.NavigationRoute)1 LineString (com.mapbox.services.commons.geojson.LineString)1 Point (com.mapbox.services.commons.geojson.Point)1