Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change route line default color #173

Open
ghadeeraqraa1992 opened this issue Dec 13, 2022 · 4 comments
Open

Change route line default color #173

ghadeeraqraa1992 opened this issue Dec 13, 2022 · 4 comments

Comments

@ghadeeraqraa1992
Copy link

I'm not able to change the route line default color as in the image below, I tried by changing routeDefaultColor without a result
val customColorResources = RouteLineColorResources.Builder() .routeCasingColor(Color.parseColor("#00DEDF")) .routeDefaultColor(Color.parseColor("#00DEDF"))//TODO :: it is not work .build() val routeLineResources = RouteLineResources.Builder() .routeLineColorResources(customColorResources) .build() val mapboxRouteLineOptions = MapboxRouteLineOptions.Builder(this) .withVanishingRouteLineEnabled(true) .withRouteLineResources(routeLineResources) .withRouteLineBelowLayerId(LocationComponentConstants.LOCATION_INDICATOR_LAYER) .build() routeLineApi = MapboxRouteLineApi(mapboxRouteLineOptions) routeLineView = MapboxRouteLineView(mapboxRouteLineOptions)
Navigation SDK : com.mapbox.navigation:android:2.9.4
any help here ?
Screen Shot 2022-12-13 at 3 12 47 PM

@cafesilencio
Copy link
Contributor

The route line is made up of multiple layers stacked on top of each other. The top most line is the traffic line. It obscures the main line unless it is scaled to be narrower than the default width. What is observed above is the traffic line. The traffic can be hidden, if that's the desired effect, by either setting the traffic colors to Color.Transparent or by calling MapboxRouteLineView::hideTraffic. Or the traffic colors can be customized to match the desired effect, specifically the color for unknown traffic which could be transparent or match the color designated for the default route line.

Changing the subject...

withRouteLineBelowLayerId(LocationComponentConstants.LOCATION_INDICATOR_LAYER)

I don't recommend doing this. The timing of this layer being added to the map isn't guaranteed or predictable. I have seen cases in the past where this layer isn't present at the time the route line layers initialize and the route line ends up on top of the layer stack, which happens if the belowLayer isn't present. I suggest identifying a layer in the map style being used since it is baked into the style. The Mapbox navigation styles have a layer called road-label-navigation that can be used. For custom styles I suggest looking at the layers in the style and finding something equivalent.

@cafesilencio
Copy link
Contributor

Another option is to use MapboxRouteLineApiExtensions::setPrimaryTrafficColor on the result of the setRoutes (and similar) MapboxRouteLineApi methods. This extension function takes the result of the setRoutes call and mutates the traffic Expression to a single color and returns a result that should then be passed to the render method of MapboxRouteLineView.

@wirthandras
Copy link

wirthandras commented Sep 10, 2024

I run into the same problem:

// initialize route line, the withRouteLineBelowLayerId is specified to place
        // the route line below road labels layer on the map
        // the value of this option will depend on the style that you are using
        // and under which layer the route line should be placed on the map layers stack
        val mapboxRouteLineOptions = MapboxRouteLineOptions.Builder(this)
            .withRouteLineBelowLayerId("road-label-navigation")
            .withVanishingRouteLineEnabled(true)
            .withRouteLineResources(
                RouteLineResources.Builder()
                    .routeLineColorResources(
                        RouteLineColorResources.Builder()
                            .routeDefaultColor(Color.BLACK) //<--- Doesn't work
                            .routeLineTraveledColor(Color.GRAY)
                            .routeLineTraveledCasingColor(Color.DKGRAY)
                            .build()
                    )
                    .build()
            )
            .build()
        routeLineApi = MapboxRouteLineApi(mapboxRouteLineOptions)
        routeLineView = MapboxRouteLineView(mapboxRouteLineOptions)

image

I am using the following version: com.mapbox.navigation:android:2.19.0

@wirthandras
Copy link

Oh, I realized when set the routeUnknownCongestionColor it become black...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants