@@ -89,6 +89,8 @@ class MapboxNavigationActivity : AppCompatActivity() {
8989 // location puck integration
9090 private val navigationLocationProvider = NavigationLocationProvider ()
9191
92+ private val waypoints = mutableListOf<Point >()
93+
9294 // camera
9395 private lateinit var navigationCamera: NavigationCamera
9496 private lateinit var viewportDataSource: MapboxNavigationViewportDataSource
@@ -398,7 +400,7 @@ class MapboxNavigationActivity : AppCompatActivity() {
398400 routeLineView.initializeLayers(style)
399401 // add long click listener that search for a route to the clicked destination
400402 binding.mapView.gestures.addOnMapLongClickListener { point ->
401- findRoute (point)
403+ addWaypoint (point)
402404 true
403405 }
404406 }
@@ -459,24 +461,25 @@ class MapboxNavigationActivity : AppCompatActivity() {
459461 voiceInstructionsPlayer.shutdown()
460462 }
461463
462- private fun findRoute (destination : Point ) {
464+ private fun addWaypoint (destination : Point ) {
463465 val origin = navigationLocationProvider.lastLocation?.let {
464466 Point .fromLngLat(it.longitude, it.latitude)
465467 } ? : return
466468
469+ waypoints.add(destination)
470+
467471 mapboxNavigation.requestRoutes(
468472 RouteOptions .builder()
469473 .applyDefaultNavigationOptions()
470474 .applyLanguageAndVoiceUnitOptions(this )
471- .coordinatesList(listOf (origin, destination))
472- .layersList(listOf (mapboxNavigation.getZLevel(), null ))
475+ .coordinatesList(listOf (origin) + waypoints)
473476 .build(),
474477 object : NavigationRouterCallback {
475478 override fun onRoutesReady (
476479 routes : List <NavigationRoute >,
477480 routerOrigin : RouterOrigin
478481 ) {
479- setRouteAndStartNavigation (routes)
482+ setRoutePreview (routes)
480483 }
481484
482485 override fun onFailure (
@@ -493,9 +496,25 @@ class MapboxNavigationActivity : AppCompatActivity() {
493496 )
494497 }
495498
496- private fun setRouteAndStartNavigation (route : List <NavigationRoute >) {
499+
500+
501+ private fun setRoutePreview (route : List <NavigationRoute >) {
502+ // set route
503+ mapboxNavigation.previewNavigationRoutes(route)
504+ binding.navigate.visibility = VISIBLE
505+ binding.navigate.setOnClickListener {
506+ setRoute()
507+ binding.navigate.visibility = INVISIBLE
508+ }
509+
510+ // move the camera to overview when new route is available
511+ navigationCamera.requestNavigationCameraToOverview()
512+ }
513+
514+ private fun setRoute () {
497515 // set route
498- mapboxNavigation.setNavigationRoutes(route)
516+ mapboxNavigation.setPreviewedRoute()
517+ waypoints.clear()
499518
500519 // show UI elements
501520 binding.soundButton.visibility = VISIBLE
@@ -505,7 +524,7 @@ class MapboxNavigationActivity : AppCompatActivity() {
505524 binding.soundButton.unmuteAndExtend(2000L )
506525
507526 // move the camera to overview when new route is available
508- navigationCamera.requestNavigationCameraToOverview ()
527+ navigationCamera.requestNavigationCameraToFollowing ()
509528 }
510529
511530 private fun clearRouteAndStopNavigation () {
0 commit comments