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);
}
}
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());
}
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);
}
}
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"));
}
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);
}
}
}
Aggregations