com.mapbox.api.directions.v5.models.DirectionsRoute Java Examples
The following examples show how to use
com.mapbox.api.directions.v5.models.DirectionsRoute.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RouteStepProgressTest.java From graphhopper-navigation-android with MIT License | 6 votes |
@Test public void distanceTraveled_equalsStepDistanceAtEndOfStep() throws Exception { DirectionsRoute route = buildTestDirectionsRoute(); RouteLeg firstLeg = route.legs().get(0); int stepIndex = 3; int legIndex = 0; double stepDistanceRemaining = 0; double legDistanceRemaining = firstLeg.distance(); double distanceRemaining = route.distance(); RouteProgress routeProgress = buildTestRouteProgress(route, stepDistanceRemaining, legDistanceRemaining, distanceRemaining, stepIndex, legIndex); RouteStepProgress routeStepProgress = routeProgress.currentLegProgress().currentStepProgress(); assertEquals(firstLeg.steps().get(3).distance(), routeStepProgress.distanceTraveled(), BaseTest.DELTA); }
Example #2
Source File: RouteUtilsTest.java From graphhopper-navigation-android with MIT License | 6 votes |
@Test public void isArrivalEvent_returnsFalseWhenManeuverTypeIsArrival_andIsNotLastInstruction() throws Exception { DirectionsRoute route = buildTestDirectionsRoute(); int first = 0; RouteLeg routeLeg = route.legs().get(first); List<LegStep> routeSteps = routeLeg.steps(); int currentStepIndex = routeSteps.size() - 2; int upcomingStepIndex = routeSteps.size() - 1; LegStep currentStep = routeSteps.get(currentStepIndex); LegStep upcomingStep = routeSteps.get(upcomingStepIndex); RouteProgress routeProgress = buildRouteProgress(first, route, currentStep, upcomingStep); BannerInstructionMilestone bannerInstructionMilestone = mock(BannerInstructionMilestone.class); List<BannerInstructions> currentStepBannerInstructions = currentStep.bannerInstructions(); buildBannerInstruction(first, bannerInstructionMilestone, currentStepBannerInstructions); RouteUtils routeUtils = new RouteUtils(); boolean isArrivalEvent = routeUtils.isArrivalEvent(routeProgress, bannerInstructionMilestone); assertFalse(isArrivalEvent); }
Example #3
Source File: TestRouteBuilder.java From graphhopper-navigation-android with MIT License | 6 votes |
private DirectionsRoute buildRouteWithOptions(DirectionsRoute route) throws IOException { List<Point> coordinates = new ArrayList<>(); RouteOptions routeOptionsWithoutVoiceInstructions = RouteOptions.builder() .baseUrl(Constants.BASE_API_URL) .user("user") .profile("profile") .accessToken(ACCESS_TOKEN) .requestUuid("uuid") .geometries("mocked_geometries") .voiceInstructions(true) .bannerInstructions(true) .coordinates(coordinates).build(); return route.toBuilder() .routeOptions(routeOptionsWithoutVoiceInstructions) .build(); }
Example #4
Source File: ValidationUtilsTest.java From graphhopper-navigation-android with MIT License | 6 votes |
private DirectionsRoute buildRouteWithFalseVoiceInstructions() throws IOException { DirectionsRoute route = buildTestDirectionsRoute(); List<Point> coordinates = new ArrayList<>(); RouteOptions routeOptionsWithoutVoiceInstructions = RouteOptions.builder() .baseUrl(Constants.BASE_API_URL) .user("user") .profile("profile") .accessToken(ACCESS_TOKEN) .requestUuid("uuid") .geometries("mocked_geometries") .voiceInstructions(false) .coordinates(coordinates).build(); return route.toBuilder() .routeOptions(routeOptionsWithoutVoiceInstructions) .build(); }
Example #5
Source File: RouteStepProgressTest.java From graphhopper-navigation-android with MIT License | 6 votes |
@Test public void getDurationRemaining_equalsStepDurationAtBeginning() throws Exception { DirectionsRoute route = buildTestDirectionsRoute(); RouteLeg firstLeg = route.legs().get(0); LegStep fourthStep = firstLeg.steps().get(5); double stepDuration = fourthStep.duration(); int stepIndex = 5; int legIndex = 0; double stepDistanceRemaining = firstLeg.steps().get(stepIndex).distance(); double legDistanceRemaining = firstLeg.distance(); double distanceRemaining = route.distance(); RouteProgress routeProgress = buildTestRouteProgress(route, stepDistanceRemaining, legDistanceRemaining, distanceRemaining, stepIndex, legIndex); RouteStepProgress routeStepProgress = routeProgress.currentLegProgress().currentStepProgress(); double durationRemaining = routeStepProgress.durationRemaining(); assertEquals(stepDuration, durationRemaining, BaseTest.DELTA); }
Example #6
Source File: MapboxNavigation.java From graphhopper-navigation-android with MIT License | 6 votes |
/** * Calling This begins a new navigation session using the provided directions route. this API is * also intended to be used when a reroute occurs passing in the updated directions route. * <p> * On initial start of the navigation session, the navigation services gets created and bound to * your activity. Unless disabled, a notification will be displayed to the user and will remain * until the service stops running in the background. * </p><p> * The directions route should be acquired by building a {@link NavigationRoute} object and * calling {@link NavigationRoute#getRoute(Callback)} on it. Using navigation route request a * route with the required parameters needed while at the same time, allowing for flexibility in * other parts of the request. * </p> * * @param directionsRoute a {@link DirectionsRoute} that makes up the path your user should * traverse along * @since 0.1.0 */ public void startNavigation(@NonNull DirectionsRoute directionsRoute) { ValidationUtils.validDirectionsRoute(directionsRoute, options.defaultMilestonesEnabled()); this.directionsRoute = directionsRoute; Timber.d("MapboxNavigation startNavigation called."); if (!isBound) { // Begin telemetry session navigationTelemetry.startSession(directionsRoute); // Start the NavigationService Intent intent = getServiceIntent(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { applicationContext.startForegroundService(intent); } else { applicationContext.startService(intent); } applicationContext.bindService(intent, this, Context.BIND_AUTO_CREATE); // Send navigation event running: true navigationEventDispatcher.onNavigationEvent(true); } else { // Update telemetry directions route navigationTelemetry.updateSessionRoute(directionsRoute); } }
Example #7
Source File: NavigationHelper.java From graphhopper-navigation-android with MIT License | 6 votes |
/** * 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)); }
Example #8
Source File: RouteStepProgressTest.java From graphhopper-navigation-android with MIT License | 6 votes |
@Test public void distanceRemaining_equalsStepDistanceAtBeginning() throws Exception { DirectionsRoute route = buildTestDirectionsRoute(); RouteLeg firstLeg = route.legs().get(0); LineString lineString = LineString.fromPolyline(firstLeg.steps().get(5).geometry(), Constants.PRECISION_6); double stepDistance = TurfMeasurement.length(lineString, TurfConstants.UNIT_METERS); double stepDistanceRemaining = firstLeg.steps().get(5).distance(); double legDistanceRemaining = firstLeg.distance(); double distanceRemaining = route.distance(); int stepIndex = 4; RouteProgress routeProgress = buildTestRouteProgress(route, stepDistanceRemaining, legDistanceRemaining, distanceRemaining, stepIndex, 0); RouteStepProgress routeStepProgress = routeProgress.currentLegProgress().currentStepProgress(); assertEquals(stepDistance, routeStepProgress.distanceRemaining(), BaseTest.LARGE_DELTA); }
Example #9
Source File: NavigationMapRoute.java From graphhopper-navigation-android with MIT License | 5 votes |
/** * If the {@link DirectionsRoute} request contains congestion information via annotations, breakup * the source into pieces so data-driven styling can be used to change the route colors * accordingly. */ private FeatureCollection addTrafficToSource(DirectionsRoute route, int index) { final List<Feature> features = new ArrayList<>(); LineString originalGeometry = LineString.fromPolyline(route.geometry(), Constants.PRECISION_6); buildRouteFeatureFromGeometry(index, features, originalGeometry); routeLineStrings.put(originalGeometry, route); LineString lineString = LineString.fromPolyline(route.geometry(), Constants.PRECISION_6); buildTrafficFeaturesFromRoute(route, index, features, lineString); return FeatureCollection.fromFeatures(features); }
Example #10
Source File: BaseTest.java From graphhopper-navigation-android with MIT License | 5 votes |
protected RouteProgress buildRouteProgress(DirectionsRoute route, double stepDistanceRemaining, double legDistanceRemaining, double distanceRemaining, int stepIndex, int legIndex) throws Exception { return routeProgressBuilder.buildTestRouteProgress( route, stepDistanceRemaining, legDistanceRemaining, distanceRemaining, stepIndex, legIndex ); }
Example #11
Source File: NavigationFasterRouteListenerTest.java From graphhopper-navigation-android with MIT License | 5 votes |
@NonNull private DirectionsResponse buildDirectionsResponse() { DirectionsResponse response = mock(DirectionsResponse.class); List<DirectionsRoute> routes = new ArrayList<>(); routes.add(mock(DirectionsRoute.class)); when(response.routes()).thenReturn(routes); return response; }
Example #12
Source File: RouteLegProgressTest.java From graphhopper-navigation-android with MIT License | 5 votes |
@Test public void currentStep_returnsCurrentStep() throws Exception { RouteProgress routeProgress = buildDefaultTestRouteProgress(); DirectionsRoute route = buildTestDirectionsRoute(); RouteLeg firstLeg = route.legs().get(0); routeProgress = routeProgress.toBuilder().stepIndex(5).build(); assertEquals( firstLeg.steps().get(5).geometry(), routeProgress.currentLegProgress().currentStep().geometry() ); assertNotSame( firstLeg.steps().get(6).geometry(), routeProgress.currentLegProgress().currentStep().geometry() ); }
Example #13
Source File: ToleranceUtilsTest.java From graphhopper-navigation-android with MIT License | 5 votes |
@Test public void dynamicRerouteDistanceTolerance_userJustPastTheIntersection() throws Exception { DirectionsRoute route = buildTestDirectionsRoute(); RouteProgress routeProgress = buildDefaultTestRouteProgress(); double distanceToIntersection = route.distance(); LineString lineString = LineString.fromPolyline(route.geometry(), Constants.PRECISION_6); Point closePoint = TurfMeasurement.along(lineString, distanceToIntersection, TurfConstants.UNIT_METERS); double tolerance = ToleranceUtils.dynamicRerouteDistanceTolerance(closePoint, routeProgress); assertEquals(50.0, tolerance, DELTA); }
Example #14
Source File: NavigationMapRoute.java From graphhopper-navigation-android with MIT License | 5 votes |
/** * The routes also display an icon for each waypoint in the route, we use symbol layers for this. */ private FeatureCollection waypointFeatureCollection(DirectionsRoute route) { final List<Feature> waypointFeatures = new ArrayList<>(); for (RouteLeg leg : route.legs()) { waypointFeatures.add(getPointFromLineString(leg, 0)); waypointFeatures.add(getPointFromLineString(leg, leg.steps().size() - 1)); } return FeatureCollection.fromFeatures(waypointFeatures); }
Example #15
Source File: NavigationMapRoute.java From graphhopper-navigation-android with MIT License | 5 votes |
private void generateFeatureCollectionList(List<DirectionsRoute> directionsRoutes) { // Each route contains traffic information and should be recreated considering this traffic // information. for (int i = 0; i < directionsRoutes.size(); i++) { featureCollections.add(addTrafficToSource(directionsRoutes.get(i), i)); } // Add the waypoint geometries to represent them as an icon featureCollections.add( waypointFeatureCollection(directionsRoutes.get(primaryRouteIndex)) ); }
Example #16
Source File: ViewRouteFetcher.java From graphhopper-navigation-android with MIT License | 5 votes |
private String obtainRouteLegDescriptionFrom(DirectionsRoute route) { List<RouteLeg> routeLegs = route.legs(); StringBuilder routeLegDescription = new StringBuilder(); for (RouteLeg leg : routeLegs) { routeLegDescription.append(leg.summary()); } return routeLegDescription.toString(); }
Example #17
Source File: NavigationPresenter.java From graphhopper-navigation-android with MIT License | 5 votes |
void onRouteUpdate(DirectionsRoute directionsRoute) { view.drawRoute(directionsRoute); if (!resumeState) { view.updateWaynameVisibility(true); view.startCamera(directionsRoute); } }
Example #18
Source File: RouteProgressTest.java From graphhopper-navigation-android with MIT License | 5 votes |
@Test public void multiLeg_getLegIndex_returnsCurrentLegIndex() throws Exception { DirectionsRoute multiLegRoute = buildMultipleLegRoute(); RouteProgress routeProgress = buildBeginningOfLegRouteProgress(multiLegRoute); routeProgress = routeProgress.toBuilder().legIndex(1).build(); assertEquals(1, routeProgress.legIndex()); }
Example #19
Source File: RouteProgressTest.java From graphhopper-navigation-android with MIT License | 5 votes |
@Test public void multiLeg_distanceRemaining_equalsRouteDistanceAtBeginning() throws Exception { DirectionsRoute multiLegRoute = buildMultipleLegRoute(); RouteProgress routeProgress = buildBeginningOfLegRouteProgress(multiLegRoute); assertEquals(multiLegRoute.distance(), routeProgress.distanceRemaining(), LARGE_DELTA); }
Example #20
Source File: MetricsRouteProgress.java From graphhopper-navigation-android with MIT License | 5 votes |
private Point retrieveRouteDestination(DirectionsRoute route) { RouteLeg lastLeg = route.legs().get(route.legs().size() - 1); LegStep lastStep = lastLeg.steps().get(lastLeg.steps().size() - 1); StepManeuver finalManuever = lastStep.maneuver(); if (finalManuever.location() != null) { return finalManuever.location(); } return Point.fromLngLat(0d, 0d); }
Example #21
Source File: RouteProgressTest.java From graphhopper-navigation-android with MIT License | 5 votes |
@Test public void fractionTraveled_equalsZeroAtBeginning() throws Exception { DirectionsRoute route = buildTestDirectionsRoute(); RouteProgress beginningRouteProgress = buildBeginningOfLegRouteProgress(route); assertEquals(0, beginningRouteProgress.fractionTraveled(), BaseTest.LARGE_DELTA); }
Example #22
Source File: DynamicCameraTest.java From graphhopper-navigation-android with MIT License | 5 votes |
@Test public void onInformationFromRoute_engineCreatesOverviewPointList() throws Exception { DynamicCamera cameraEngine = buildDynamicCamera(); DirectionsRoute route = buildDirectionsRoute(); List<Point> routePoints = generateRouteCoordinates(route); RouteInformation routeInformation = RouteInformation.create(route, null, null); List<Point> overviewPoints = cameraEngine.overview(routeInformation); assertEquals(routePoints, overviewPoints); }
Example #23
Source File: DirectionsResponseFactory.java From mapbox-java with MIT License | 5 votes |
private List<DirectionsRoute> generateRouteOptions(Response<DirectionsResponse> response) { List<DirectionsRoute> routes = response.body().routes(); List<DirectionsRoute> modifiedRoutes = new ArrayList<>(); for (DirectionsRoute route : routes) { modifiedRoutes.add(route.toBuilder().routeOptions( RouteOptions.builder() .profile(mapboxDirections.profile()) .coordinates(mapboxDirections.coordinates()) .waypointIndicesList(ParseUtils.parseToIntegers(mapboxDirections.waypointIndices())) .waypointNamesList(ParseUtils.parseToStrings(mapboxDirections.waypointNames())) .waypointTargetsList(ParseUtils.parseToPoints(mapboxDirections.waypointTargets())) .continueStraight(mapboxDirections.continueStraight()) .annotationsList(ParseUtils.parseToStrings(mapboxDirections.annotation())) .approachesList(ParseUtils.parseToStrings(mapboxDirections.approaches())) .bearingsList(ParseUtils.parseToListOfListOfDoubles(mapboxDirections.bearing())) .alternatives(mapboxDirections.alternatives()) .language(mapboxDirections.language()) .radiusesList(ParseUtils.parseToDoubles(mapboxDirections.radius())) .user(mapboxDirections.user()) .voiceInstructions(mapboxDirections.voiceInstructions()) .bannerInstructions(mapboxDirections.bannerInstructions()) .roundaboutExits(mapboxDirections.roundaboutExits()) .geometries(mapboxDirections.geometries()) .overview(mapboxDirections.overview()) .steps(mapboxDirections.steps()) .exclude(mapboxDirections.exclude()) .voiceUnits(mapboxDirections.voiceUnits()) .accessToken(mapboxDirections.accessToken()) .requestUuid(response.body().uuid()) .baseUrl(mapboxDirections.baseUrl()) .walkingOptions(mapboxDirections.walkingOptions()) .build() ).build()); } return modifiedRoutes; }
Example #24
Source File: NavigationRouteProcessor.java From graphhopper-navigation-android with MIT License | 5 votes |
private RouteProgress assembleRouteProgress(DirectionsRoute route) { int legIndex = indices.legIndex(); int stepIndex = indices.stepIndex(); double legDistanceRemaining = legDistanceRemaining(stepDistanceRemaining, legIndex, stepIndex, route); double routeDistanceRemaining = routeDistanceRemaining(legDistanceRemaining, legIndex, route); currentLegAnnotation = createCurrentAnnotation(currentLegAnnotation, currentLeg, legDistanceRemaining); double stepDistanceTraveled = currentStep.distance() - stepDistanceRemaining; StepIntersection currentIntersection = findCurrentIntersection( currentIntersections, currentIntersectionDistances, stepDistanceTraveled ); StepIntersection upcomingIntersection = findUpcomingIntersection( currentIntersections, upcomingStep, currentIntersection ); RouteProgress.Builder progressBuilder = RouteProgress.builder() .stepDistanceRemaining(stepDistanceRemaining) .legDistanceRemaining(legDistanceRemaining) .distanceRemaining(routeDistanceRemaining) .directionsRoute(route) .currentStepPoints(currentStepPoints) .upcomingStepPoints(upcomingStepPoints) .stepIndex(stepIndex) .legIndex(legIndex) .intersections(currentIntersections) .currentIntersection(currentIntersection) .upcomingIntersection(upcomingIntersection) .intersectionDistancesAlongStep(currentIntersectionDistances) .currentLegAnnotation(currentLegAnnotation); addUpcomingStepPoints(progressBuilder); return progressBuilder.build(); }
Example #25
Source File: RouteLegProgressTest.java From graphhopper-navigation-android with MIT License | 5 votes |
@Test public void distanceRemaining_equalsLegDistanceAtBeginning() throws Exception { RouteProgress routeProgress = buildBeginningOfLegRouteProgress(); DirectionsRoute route = buildTestDirectionsRoute(); RouteLeg firstLeg = route.legs().get(0); assertEquals(firstLeg.distance(), routeProgress.currentLegProgress().distanceRemaining(), BaseTest.LARGE_DELTA); }
Example #26
Source File: DynamicCameraTest.java From graphhopper-navigation-android with MIT License | 5 votes |
private List<Point> generateRouteCoordinates(DirectionsRoute route) { if (route == null) { return Collections.emptyList(); } LineString lineString = LineString.fromPolyline(route.geometry(), Constants.PRECISION_6); return lineString.coordinates(); }
Example #27
Source File: NavigationHelperTest.java From graphhopper-navigation-android with MIT License | 5 votes |
private DirectionsRoute buildMultiLegRoute() throws IOException { Gson gson = new GsonBuilder() .registerTypeAdapterFactory(DirectionsAdapterFactory.create()).create(); String body = loadJsonFixture(MULTI_LEG_ROUTE_FIXTURE); DirectionsResponse response = gson.fromJson(body, DirectionsResponse.class); return response.routes().get(0); }
Example #28
Source File: NavigationViewEventDispatcherTest.java From graphhopper-navigation-android with MIT License | 5 votes |
@Test public void onRouteListenerNotSet_rerouteAlongListenerIsNotCalled() throws Exception { NavigationViewEventDispatcher eventDispatcher = new NavigationViewEventDispatcher(); RouteListener routeListener = mock(RouteListener.class); DirectionsRoute directionsRoute = mock(DirectionsRoute.class); eventDispatcher.onRerouteAlong(directionsRoute); verify(routeListener, times(0)).onRerouteAlong(directionsRoute); }
Example #29
Source File: ViewRouteFetcherTest.java From graphhopper-navigation-android with MIT License | 5 votes |
private 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); RouteOptions options = buildRouteOptionsWithCoordinates(response); return response.routes().get(0).toBuilder().routeOptions(options).build(); }
Example #30
Source File: ViewRouteFetcherTest.java From graphhopper-navigation-android with MIT License | 5 votes |
@Test public void onRouteResponseReceived_routeUpdateCallbackIsCalled() throws Exception { ViewRouteListener routeEngineListener = mock(ViewRouteListener.class); ViewRouteFetcher routeEngine = buildRouteEngine(routeEngineListener); DirectionsResponse response = buildDirectionsResponse(); DirectionsRoute route = response.routes().get(0); RouteProgress routeProgress = mock(RouteProgress.class); routeEngine.onResponseReceived(response, routeProgress); verify(routeEngineListener).onRouteUpdate(route); }