Search in sources :

Example 56 with RouteProgress

use of com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress in project mapbox-navigation-android by mapbox.

the class RouteStepProgressTest method distanceRemaining_equalsCorrectValueAtIntervals.

@Test
public void distanceRemaining_equalsCorrectValueAtIntervals() {
    LineString lineString = LineString.fromPolyline(firstStep.geometry(), Constants.PRECISION_6);
    double stepDistance = TurfMeasurement.length(lineString, TurfConstants.UNIT_METERS);
    // meters
    double stepSegments = 5;
    // Chop the line in small pieces
    for (double i = 0; i < stepDistance; i += stepSegments) {
        Point point = TurfMeasurement.along(lineString, i, TurfConstants.UNIT_METERS);
        if (point.equals(route.legs().get(0).steps().get(1).maneuver().location())) {
            return;
        }
        LineString slicedLine = TurfMisc.lineSlice(point, route.legs().get(0).steps().get(1).maneuver().location(), lineString);
        double distance = TurfMeasurement.length(slicedLine, TurfConstants.UNIT_METERS);
        RouteProgress routeProgress = RouteProgress.builder().stepDistanceRemaining(distance).legDistanceRemaining(firstLeg.distance()).distanceRemaining(route.distance()).directionsRoute(route).stepIndex(0).legIndex(0).build();
        RouteStepProgress routeStepProgress = routeProgress.currentLegProgress().currentStepProgress();
        assertEquals(distance, routeStepProgress.distanceRemaining(), BaseTest.DELTA);
    }
}
Also used : LineString(com.mapbox.geojson.LineString) Point(com.mapbox.geojson.Point) Test(org.junit.Test) BaseTest(com.mapbox.services.android.navigation.v5.BaseTest)

Example 57 with RouteProgress

use of com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress in project mapbox-navigation-android by mapbox.

the class RouteStepProgressTest method stepIntersections_includesAllStepIntersectionsAndNextManeuver.

@Test
public void stepIntersections_includesAllStepIntersectionsAndNextManeuver() throws Exception {
    RouteProgress routeProgress = RouteProgress.builder().stepDistanceRemaining(0).legDistanceRemaining(firstLeg.distance()).distanceRemaining(route.distance()).directionsRoute(route).stepIndex(3).legIndex(0).build();
    RouteStepProgress routeStepProgress = routeProgress.currentLegProgress().currentStepProgress();
    int currentStepTotal = route.legs().get(0).steps().get(3).intersections().size();
    Point maneuverLocation = route.legs().get(0).steps().get(4).maneuver().location();
    assertEquals(currentStepTotal + 1, routeStepProgress.intersections().size());
    assertEquals(routeStepProgress.intersections().get(16).location().latitude(), maneuverLocation.latitude());
    assertEquals(routeStepProgress.intersections().get(16).location().longitude(), maneuverLocation.longitude());
}
Also used : Point(com.mapbox.geojson.Point) Point(com.mapbox.geojson.Point) Test(org.junit.Test) BaseTest(com.mapbox.services.android.navigation.v5.BaseTest)

Example 58 with RouteProgress

use of com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress in project mapbox-navigation-android by mapbox.

the class RouteStepProgressTest method getDurationRemaining_equalsCorrectValueAtIntervals.

@Test
public void getDurationRemaining_equalsCorrectValueAtIntervals() {
    LineString lineString = LineString.fromPolyline(firstStep.geometry(), Constants.PRECISION_6);
    // meters
    double stepSegments = 5;
    // Chop the line in small pieces
    for (double i = 0; i < firstStep.distance(); i += stepSegments) {
        Point point = TurfMeasurement.along(lineString, i, TurfConstants.UNIT_METERS);
        LineString slicedLine = TurfMisc.lineSlice(point, route.legs().get(0).steps().get(1).maneuver().location(), lineString);
        double distance = TurfMeasurement.length(slicedLine, TurfConstants.UNIT_METERS);
        RouteProgress routeProgress = RouteProgress.builder().stepDistanceRemaining(distance).legDistanceRemaining(firstLeg.distance()).distanceRemaining(route.distance()).directionsRoute(route).stepIndex(0).legIndex(0).build();
        RouteStepProgress routeStepProgress = routeProgress.currentLegProgress().currentStepProgress();
        double fractionRemaining = (firstStep.distance() - distance) / firstStep.distance();
        assertEquals((1.0 - fractionRemaining) * firstStep.duration(), routeStepProgress.durationRemaining(), BaseTest.LARGE_DELTA);
    }
}
Also used : LineString(com.mapbox.geojson.LineString) Point(com.mapbox.geojson.Point) Test(org.junit.Test) BaseTest(com.mapbox.services.android.navigation.v5.BaseTest)

Example 59 with RouteProgress

use of com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress in project mapbox-navigation-android by mapbox.

the class SnapToRouteTest method getSnappedLocation_returnsProviderNameCorrectly.

@Test
@Ignore
public void getSnappedLocation_returnsProviderNameCorrectly() throws Exception {
    Snap snap = new SnapToRoute();
    Location location = new Location("test");
    List<Point> coordinates = PolylineUtils.decode(route.legs().get(0).steps().get(1).geometry(), Constants.PRECISION_6);
    Location snappedLocation = snap.getSnappedLocation(location, routeProgress, coordinates);
    assertTrue(snappedLocation.getProvider().equals("test-snapped"));
    assertTrue(location.getProvider().equals("test"));
}
Also used : Point(com.mapbox.geojson.Point) Location(android.location.Location) Ignore(org.junit.Ignore) Test(org.junit.Test) BaseTest(com.mapbox.services.android.navigation.v5.BaseTest)

Example 60 with RouteProgress

use of com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress in project mapbox-navigation-android by mapbox.

the class RouteViewModel method fetchRouteFromOffRouteEvent.

/**
 * Requests a new {@link DirectionsRoute}.
 * <p>
 * Will use {@link Location} bearing if we have a rawLocation with bearing.
 * <p>
 * Called when an off-route event is fired and a new {@link DirectionsRoute}
 * is needed to continue navigating.
 *
 * @param event found from off-route event
 */
public void fetchRouteFromOffRouteEvent(OffRouteEvent event) {
    if (OffRouteEvent.isValid(event)) {
        Double bearing = null;
        if (rawLocation != null) {
            bearing = rawLocation.hasBearing() ? Float.valueOf(rawLocation.getBearing()).doubleValue() : null;
        }
        Point origin = event.getNewOrigin();
        RouteProgress progress = event.getRouteProgress();
        NavigationRoute.Builder builder = buildRouteRequestFromCurrentLocation(origin, bearing, progress);
        if (builder != null) {
            addNavigationViewOptions(builder);
            builder.alternatives(true);
            builder.build().getRoute(this);
        }
    }
}
Also used : Point(com.mapbox.geojson.Point) RouteProgress(com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress) NavigationRoute(com.mapbox.services.android.navigation.v5.navigation.NavigationRoute)

Aggregations

BaseTest (com.mapbox.services.android.navigation.v5.BaseTest)44 Test (org.junit.Test)44 RouteProgress (com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress)39 Point (com.mapbox.geojson.Point)30 Location (android.location.Location)19 LineString (com.mapbox.geojson.LineString)12 DirectionsRoute (com.mapbox.api.directions.v5.models.DirectionsRoute)10 DirectionsResponse (com.mapbox.api.directions.v5.models.DirectionsResponse)3 LegStep (com.mapbox.api.directions.v5.models.LegStep)3 Milestone (com.mapbox.services.android.navigation.v5.milestone.Milestone)3 NavigationRoute (com.mapbox.services.android.navigation.v5.navigation.NavigationRoute)3 Context (android.content.Context)2 GsonBuilder (com.google.gson.GsonBuilder)2 RouteLeg (com.mapbox.api.directions.v5.models.RouteLeg)2 FasterRoute (com.mapbox.services.android.navigation.v5.route.FasterRoute)2 MetricsRouteProgress (com.mapbox.services.android.navigation.v5.routeprogress.MetricsRouteProgress)2 RouteStepProgress (com.mapbox.services.android.navigation.v5.routeprogress.RouteStepProgress)2 DistanceUtils (com.mapbox.services.android.navigation.v5.utils.DistanceUtils)2 Date (java.util.Date)2 Ignore (org.junit.Ignore)2