如何自定义Mapbox路线的样式?

时间:2019-07-10 12:50:16

标签: android kotlin mapbox

我的函数成功呈现了从起点到终点的路线:

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")
            }
        })
}

enter image description here

但是我想通过两种方式自定义路线:

  1. 更改路线的颜色

  2. 用虚线代替实线

如何实现这些样式?

1 个答案:

答案 0 :(得分:0)

Android Nav SDK文档在此处详细介绍了有关如何修改路线的样式默认设置的详细信息:https://docs.mapbox.com/android/navigation/overview/map-styling/#style-the-map-route

最重要的是,您可以在初始化NavigationMapRoute

时通过提供其他样式来覆盖这些默认设置

———

⚠️免责声明:我目前在Mapbox⚠️

工作