mapbox / mapbox/mapbox-navigation-android
Add route selection by index
Nobody has claimed this yet.
- Dominant language
- Kotlin
- Stars
- 651
- Forks
- 321
- PR merge metrics
- No merged PRs in 30d
Description
**Mapbox Navigation SDK version:** 2.1.0
EDIT: grammar
Follow up work from https://github.com/mapbox/mapbox-navigation-android/pull/4892. Anticipating this issue will require refactoring and testing in order to get it all just right. It is considered out of scope of the initial integration of continuous alternatives because we may not want to do this. Re-ordering the list and assuming route index zero also works.
Here is the existing way to change the route leg in MapboxNavigation
``` kotlin
fun navigateNextRouteLeg(callback: LegIndexUpdatedCallback) {
arrivalProgressObserver.navigateNextRouteLeg(callback)
}
```
So here we're proposing adding and/or changing the functions in MapboxNavigation
``` kotlin
// Adding routeIndex may be semver, since it changes the position of the setRoute arguments
fun setRoutes(routes: List, routeIndex: Int = 0, initialLegIndex: Int = 0) {
// After routes have been set, be able to change the route index with something like this.
fun setPrimaryRoute(routeIndex: Int)
fun setPrimaryRoute(route: DirectionsRoute)
```
## Ui code to select a route
[Before](https://github.com/mapbox/mapbox-navigation-android/blob/ac985d5298f3b9dae22a8dae2eb74a5366ed7c1e/qa-test-app/src/main/java/com/mapbox/navigation/qa_test_app/view/AlternativeRouteActivity.kt#L273-L293)
``` kotlin
private val mapClickListener = OnMapClickListener { point ->
CoroutineScope(Dispatchers.Main).launch {
val result = routeLineApi.findClosestRoute(
point,
binding.mapView.getMapboxMap(),
routeClickPadding
)
val routeFound = result.value?.route
if (routeFound != null && routeFound != routeLineApi.getPrimaryRoute()) {
val reOrderedRoutes = routeLineApi.getRoutes()
.filter { it != routeFound }
.toMutableList()
.also {
it.add(0, routeFound)
}
mapboxNavigation.setRoutes(reOrderedRoutes)
}
}
false
}
```
After
``` kotlin
private val mapClickListener = OnMapClickListener { point ->
CoroutineScope(Dispatchers.Main).launch {
val result = routeLineApi.findClosestRoute(
point,
binding.mapView.getMapboxMap(),
routeClickPadding
)
result.value?.route?.let { mapboxNavigation.setPrimaryRoute(it)
}
false
}
```
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the MapboxNavigation entry point and the existing navigateNextRouteLeg and setRoutes APIs. Compare the current AlternativeRouteActivity implementation with the proposed setPrimaryRoute usage to understand route selection behavior. Done means supporting primary-route selection by index or DirectionsRoute while preserving route and leg handling, with refactoring and tests covering the new behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, kotlin
- Domain
- api, mobile
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100