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