Search in sources :

Example 1 with SnapToRoute

use of com.mapbox.services.android.navigation.v5.snap.SnapToRoute in project mapbox-navigation-android by mapbox.

the class NavigationEngine method handleRequest.

/**
 * Takes a new location model and runs all related engine checks against it
 * (off-route, milestones, snapped location, and faster-route).
 * <p>
 * After running through the engines, all data is submitted to {@link NavigationService} via
 * {@link NavigationEngine.Callback}.
 *
 * @param newLocationModel hold location, navigation (with options), and distances away from maneuver
 */
private void handleRequest(final NewLocationModel newLocationModel) {
    final MapboxNavigation mapboxNavigation = newLocationModel.mapboxNavigation();
    boolean snapToRouteEnabled = mapboxNavigation.options().snapToRoute();
    final Location rawLocation = newLocationModel.location();
    RouteProgress routeProgress = routeProcessor.buildNewRouteProgress(mapboxNavigation, rawLocation);
    final boolean userOffRoute = isUserOffRoute(newLocationModel, routeProgress, routeProcessor);
    routeProcessor.checkIncreaseIndex(mapboxNavigation);
    RouteProgress previousRouteProgress = routeProcessor.getPreviousRouteProgress();
    final List<Milestone> milestones = checkMilestones(previousRouteProgress, routeProgress, mapboxNavigation);
    final Location location = routeProcessor.buildSnappedLocation(mapboxNavigation, snapToRouteEnabled, rawLocation, routeProgress, userOffRoute);
    boolean fasterRouteEnabled = mapboxNavigation.options().enableFasterRouteDetection();
    final boolean checkFasterRoute = fasterRouteEnabled && !userOffRoute && shouldCheckFasterRoute(newLocationModel, routeProgress);
    final RouteProgress finalRouteProgress = routeProgress;
    routeProcessor.setPreviousRouteProgress(finalRouteProgress);
    responseHandler.post(new Runnable() {

        @Override
        public void run() {
            callback.onNewRouteProgress(location, finalRouteProgress);
            callback.onMilestoneTrigger(milestones, finalRouteProgress);
            callback.onUserOffRoute(location, userOffRoute);
            callback.onCheckFasterRoute(location, finalRouteProgress, checkFasterRoute);
        }
    });
}
Also used : Milestone(com.mapbox.services.android.navigation.v5.milestone.Milestone) RouteProgress(com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress) Location(android.location.Location)

Example 2 with SnapToRoute

use of com.mapbox.services.android.navigation.v5.snap.SnapToRoute in project mapbox-navigation-android by mapbox.

the class MapboxNavigation method initialize.

/**
 * In-charge of initializing all variables needed to begin a navigation session. Many values can
 * be changed later on using their corresponding setter. An internal progressChangeListeners used
 * to prevent users from removing it.
 */
private void initialize() {
    // Initialize event dispatcher and add internal listeners
    navigationEventDispatcher = new NavigationEventDispatcher();
    initializeDefaultLocationEngine();
    initializeDefaultCameraEngine();
    initializeTelemetry();
    // Create and add default milestones if enabled.
    milestones = new ArrayList<>();
    if (options.defaultMilestonesEnabled()) {
        addMilestone(new VoiceInstructionMilestone.Builder().setIdentifier(VOICE_INSTRUCTION_MILESTONE_ID).build());
        addMilestone(new BannerInstructionMilestone.Builder().setIdentifier(BANNER_INSTRUCTION_MILESTONE_ID).build());
    }
    if (options.snapToRoute()) {
        snapEngine = new SnapToRoute();
    }
    if (options.enableOffRouteDetection()) {
        offRouteEngine = new OffRouteDetector();
    }
    if (options().enableFasterRouteDetection()) {
        fasterRouteEngine = new FasterRouteDetector();
    }
}
Also used : VoiceInstructionMilestone(com.mapbox.services.android.navigation.v5.milestone.VoiceInstructionMilestone) BannerInstructionMilestone(com.mapbox.services.android.navigation.v5.milestone.BannerInstructionMilestone) SnapToRoute(com.mapbox.services.android.navigation.v5.snap.SnapToRoute) FasterRouteDetector(com.mapbox.services.android.navigation.v5.route.FasterRouteDetector) OffRouteDetector(com.mapbox.services.android.navigation.v5.offroute.OffRouteDetector)

Example 3 with SnapToRoute

use of com.mapbox.services.android.navigation.v5.snap.SnapToRoute in project mapbox-navigation-android by mapbox.

the class MapboxNavigationTest method setSnapEngine_doesReplaceDefaultEngine.

@Test
public void setSnapEngine_doesReplaceDefaultEngine() throws Exception {
    Snap snap = navigation.getSnapEngine();
    assertTrue(snap instanceof SnapToRoute);
    snap = mock(Snap.class);
    navigation.setSnapEngine(snap);
    assertTrue(!(navigation.getSnapEngine() instanceof SnapToRoute));
    assertTrue(navigation.getSnapEngine() instanceof Snap);
}
Also used : SnapToRoute(com.mapbox.services.android.navigation.v5.snap.SnapToRoute) Snap(com.mapbox.services.android.navigation.v5.snap.Snap) Test(org.junit.Test) BaseTest(com.mapbox.services.android.navigation.v5.BaseTest)

Example 4 with SnapToRoute

use of com.mapbox.services.android.navigation.v5.snap.SnapToRoute 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)

Aggregations

Location (android.location.Location)2 BaseTest (com.mapbox.services.android.navigation.v5.BaseTest)2 SnapToRoute (com.mapbox.services.android.navigation.v5.snap.SnapToRoute)2 Test (org.junit.Test)2 Point (com.mapbox.geojson.Point)1 BannerInstructionMilestone (com.mapbox.services.android.navigation.v5.milestone.BannerInstructionMilestone)1 Milestone (com.mapbox.services.android.navigation.v5.milestone.Milestone)1 VoiceInstructionMilestone (com.mapbox.services.android.navigation.v5.milestone.VoiceInstructionMilestone)1 OffRouteDetector (com.mapbox.services.android.navigation.v5.offroute.OffRouteDetector)1 FasterRouteDetector (com.mapbox.services.android.navigation.v5.route.FasterRouteDetector)1 RouteProgress (com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress)1 Snap (com.mapbox.services.android.navigation.v5.snap.Snap)1 Ignore (org.junit.Ignore)1