Reputation: 9123
My function successfully renders a route from origin to destination:
private fun renderRouteToDestination(){
val origin = Point.fromLngLat(initialLocation!!.longitude, initialLocation!!.latitude)
val destination = Point.fromLngLat(143.152001, -37.260811)
val navRoute = NavigationRoute.builder(context)
.accessToken(getString(R.string.mapbox_access_token))
.origin(origin)
.profile(DirectionsCriteria.PROFILE_WALKING)
.destination(destination)
.build()
navRoute.getRoute(object : Callback<DirectionsResponse> {
override fun onFailure(call: Call<DirectionsResponse>, t: Throwable) {}
override fun onResponse(call: Call<DirectionsResponse>, response: Response<DirectionsResponse>) {
val routeResponse = response ?: return
val body = routeResponse.body() ?: return
if (body.routes().count() == 0){
Log.d(TAG, "There were no routes")
return
}
if (navigationMapRoute != null) navigationMapRoute?.updateRouteVisibilityTo(false)
navigationMapRoute = NavigationMapRoute(null, mapView!!, mapbox)
val directionsRoute = body.routes().first()
navigationMapRoute?.addRoute(directionsRoute)
Log.d(TAG, "Successful got route to destination")
}
})
}
However I would like to customise the route in 2 ways:
Change the color of the route
Make the route dotted instead of solid
How can I achieve these styles?
Upvotes: 1
Views: 492
Reputation: 1774
The the Android Nav SDK documentation goes into specific detail about how to modify the style defaults of the route line here: https://docs.mapbox.com/android/navigation/overview/map-styling/#style-the-map-route
The bottom line is that you can override these defaults by providing an alternative style when you initialize your NavigationMapRoute
———
⚠️ disclaimer: I currently work at Mapbox ⚠️
Upvotes: 1