mapbox-navigation-android icon indicating copy to clipboard operation
mapbox-navigation-android copied to clipboard

Is it possible to hide silent waypoint

Open IvanMagda-energ opened this issue 2 years ago • 4 comments

Hello Team, i have a small problem with waypoints. I have an array of coordinates of 25 points on which I build a route. I need to make it so that only the start point and end point are visible on the map, and all intermediate points on the map are not visible. During route generation, I specify silent waypoints using the waypointIndicesList(listOf(0, 24) parameter. Navigation considers the specified coordinate indices as silent points, but they are still visible on the route. Although when you specify silent points in the Map Box Navigation IOS, they become invisible on the map! How can they be hidden in the Android version?

private` fun requestRoutes(listOfPoint: ArrayList<Point>) {
        MapboxNavigationApp.current()!!.requestRoutes(
            RouteOptions
                .builder()
                .applyLanguageAndVoiceUnitOptions(view!!.context)
                .applyDefaultNavigationOptions()
                .alternatives(true)
                .coordinatesList(listOfPoint)
                .waypointIndicesList(listOf(0, 24))
                .build(),
            object : NavigationRouterCallback {
                override fun onCanceled(routeOptions: RouteOptions, routerOrigin: RouterOrigin) {
                    // no Implement
                }
                override fun onFailure(reasons: List<RouterFailure>, routeOptions: RouteOptions) {
                    // no Implement
                }
                override fun onRoutesReady(
                    routes: List<NavigationRoute>,
                    routerOrigin: RouterOrigin
                ) {
                    navigationView.api.startRoutePreview(routes)
                    navigationView.api.routeReplayEnabled(true)
                }
            }
        )
    }

Mapbox Navigation SDK version: implementation 'com.mapbox.navigation:ui-app:2.8.0' implementation 'com.mapbox.navigation:ui-dropin:2.8.0'

IvanMagda-energ avatar Oct 11 '22 06:10 IvanMagda-energ

@IvanMagda-energ Thanks for reporting the issue.

@cafesilencio @LukasPaczos I don't think this is possible with Navigation SDK today. I don't see any means in RouteLineOptions to mark a waypoint as silent and hence not associate a drawable with it. Can one of you confirm?

abhishek1508 avatar Oct 12 '22 23:10 abhishek1508

I looks like the NavigationView is being used in the example above. I'm don't think the NavigationView supports this option currently. The MapboxRouteLineApi doesn't expose a feature to hide the intermediate waypoints explicitly but there is a way it could be done if interacting with MapboxRouteLineApi directly.

@abhishek1508 I can explain how to do this with the MapboxRouteLineApi if this option is added to NavigationView.

cafesilencio avatar Oct 13 '22 15:10 cafesilencio

I looks like the NavigationView is being used in the example above. I'm don't think the NavigationView supports this option currently. The MapboxRouteLineApi doesn't expose a feature to hide the intermediate waypoints explicitly but there is a way it could be done if interacting with MapboxRouteLineApi directly.

@abhishek1508 I can explain how to do this with the MapboxRouteLineApi if this option is added to NavigationView.

Thanks for taking a look at this @cafesilencio. I would like to know how could this be achieved using MapboxRouteLineApi and make necessary adjustments to NavigationView to support it.

abhishek1508 avatar Oct 13 '22 16:10 abhishek1508

Probably the easiest thing to do would be to add an extension function to MapboxRouteLineApiExtensions.

Something like:

fun Expected<RouteLineError, RouteSetValue>.replaceWaypoints(wayPoints: List<Point>):
    Expected<RouteLineError, RouteSetValue> {
    return this.fold({
        this
    }, { routeSetValue ->
        val features = wayPoints.map { Feature.fromGeometry(it) }
        val waypointFeatureCollection = FeatureCollection.fromFeatures(features)
        val mutableValue = routeSetValue.toMutableValue()
        mutableValue.waypointsSource = waypointFeatureCollection
        val updatedValue = mutableValue.toImmutableValue()
        ExpectedFactory.createValue(updatedValue)
    })
}

// basic usage
routeLineApi.setRoutes(
    routeLines
) { result ->
    // hard coding here for clarity
    val origin = Point.fromLngLat(-122.43301555469577, 37.776324454155564)
    val destination = Point.fromLngLat(-122.46904197739785, 37.77058251092445)
    val updatedResult = result.replaceWaypoints(listOf(origin, destination))

    mapboxMap.getStyle()?.apply {
        routeLineView.renderRouteDrawData(this, updatedResult)
    }
}

Either one of us can add the extension function. You're more knowledgable in how to expose and implement this in NavigationView.

cafesilencio avatar Oct 13 '22 17:10 cafesilencio