diff --git a/libnavui-maps/src/main/java/com/mapbox/navigation/ui/maps/route/line/api/MapboxRouteLineApi.kt b/libnavui-maps/src/main/java/com/mapbox/navigation/ui/maps/route/line/api/MapboxRouteLineApi.kt index 1092cc3efcf..2cff2a654e7 100644 --- a/libnavui-maps/src/main/java/com/mapbox/navigation/ui/maps/route/line/api/MapboxRouteLineApi.kt +++ b/libnavui-maps/src/main/java/com/mapbox/navigation/ui/maps/route/line/api/MapboxRouteLineApi.kt @@ -799,6 +799,12 @@ class MapboxRouteLineApi( } } + // The purpose of this is to provide the correct masking layer data to be rendered in the view. + // Although the primary route line layer data is returned here it shouldn't be rendered by the + // view. It is included because the parameter isn't nullable. If it were the data wouldn't + // be included since it's only the masking layers that should be updated. For this reason + // the variable to ignore the primary route line data is set to true so the view class will + // ignore it. private fun provideRouteLegUpdate( routeLineOverlayDynamicData: RouteLineDynamicData?, consumer: MapboxNavigationConsumer> @@ -806,13 +812,16 @@ class MapboxRouteLineApi( ifNonNull(routeLineOverlayDynamicData) { maskingLayerData -> getRouteDrawData { expected -> expected.value?.apply { + val updateValue = RouteLineUpdateValue( + this.primaryRouteLineData.dynamicData, + this.alternativeRouteLinesData.map { it.dynamicData }, + maskingLayerData + ).also { + it.ignorePrimaryRouteLineData = true + } consumer.accept( ExpectedFactory.createValue( - RouteLineUpdateValue( - this.primaryRouteLineData.dynamicData, - this.alternativeRouteLinesData.map { it.dynamicData }, - maskingLayerData - ) + updateValue ) ) } diff --git a/libnavui-maps/src/main/java/com/mapbox/navigation/ui/maps/route/line/api/MapboxRouteLineView.kt b/libnavui-maps/src/main/java/com/mapbox/navigation/ui/maps/route/line/api/MapboxRouteLineView.kt index 98a5a8f5136..263f61390f0 100644 --- a/libnavui-maps/src/main/java/com/mapbox/navigation/ui/maps/route/line/api/MapboxRouteLineView.kt +++ b/libnavui-maps/src/main/java/com/mapbox/navigation/ui/maps/route/line/api/MapboxRouteLineView.kt @@ -370,10 +370,12 @@ class MapboxRouteLineView(options: MapboxRouteLineOptions) { jobControl.scope.launch(Dispatchers.Main) { mutex.withLock { update.onValue { - primaryRouteLineLayerGroup.map { layerId -> - toExpressionUpdateFun(layerId, it.primaryRouteLineDynamicData) - }.forEach { updateFun -> - updateFun(style) + if (!it.ignorePrimaryRouteLineData) { + primaryRouteLineLayerGroup.map { layerId -> + toExpressionUpdateFun(layerId, it.primaryRouteLineDynamicData) + }.forEach { updateFun -> + updateFun(style) + } } ifNonNull(it.routeLineMaskingLayerDynamicData) { overlayData -> diff --git a/libnavui-maps/src/main/java/com/mapbox/navigation/ui/maps/route/line/model/RouteLineUpdateValue.kt b/libnavui-maps/src/main/java/com/mapbox/navigation/ui/maps/route/line/model/RouteLineUpdateValue.kt index 301e6c3344a..eea73bcb9cd 100644 --- a/libnavui-maps/src/main/java/com/mapbox/navigation/ui/maps/route/line/model/RouteLineUpdateValue.kt +++ b/libnavui-maps/src/main/java/com/mapbox/navigation/ui/maps/route/line/model/RouteLineUpdateValue.kt @@ -13,6 +13,8 @@ class RouteLineUpdateValue internal constructor( val routeLineMaskingLayerDynamicData: RouteLineDynamicData? = null ) { + internal var ignorePrimaryRouteLineData = false + /** * @return a class with mutable values for replacing. */ diff --git a/libnavui-maps/src/test/java/com/mapbox/navigation/ui/maps/route/line/api/MapboxRouteLineApiTest.kt b/libnavui-maps/src/test/java/com/mapbox/navigation/ui/maps/route/line/api/MapboxRouteLineApiTest.kt index 2316a98c64d..b723ab11c8c 100644 --- a/libnavui-maps/src/test/java/com/mapbox/navigation/ui/maps/route/line/api/MapboxRouteLineApiTest.kt +++ b/libnavui-maps/src/test/java/com/mapbox/navigation/ui/maps/route/line/api/MapboxRouteLineApiTest.kt @@ -1064,6 +1064,7 @@ class MapboxRouteLineApiTest { assertEquals(expectedCasingExpression, casingExpression.toString()) assertEquals(expectedTrailExpression, trailExpression.toString()) assertEquals(expectedTrailCasingExpression, trailCasingExpression.toString()) + assertTrue(result.ignorePrimaryRouteLineData) callbackCalled = true } diff --git a/libnavui-maps/src/test/java/com/mapbox/navigation/ui/maps/route/line/api/MapboxRouteLineViewTest.kt b/libnavui-maps/src/test/java/com/mapbox/navigation/ui/maps/route/line/api/MapboxRouteLineViewTest.kt index e1a73fa191a..b820bb0bde7 100644 --- a/libnavui-maps/src/test/java/com/mapbox/navigation/ui/maps/route/line/api/MapboxRouteLineViewTest.kt +++ b/libnavui-maps/src/test/java/com/mapbox/navigation/ui/maps/route/line/api/MapboxRouteLineViewTest.kt @@ -541,6 +541,151 @@ class MapboxRouteLineViewTest { unmockkStatic("com.mapbox.maps.extension.style.layers.LayerUtils") } + @Test + fun renderTraveledRouteLineUpdate_whenIgnorePrimaryRouteLineData() = + coroutineRule.runBlockingTest { + mockkStatic("com.mapbox.maps.extension.style.layers.LayerUtils") + mockkObject(MapboxRouteLineUtils) + val options = MapboxRouteLineOptions.Builder(ctx).build() + val trafficLineExp = mockk() + val routeLineExp = mockk() + val casingLineEx = mockk() + val restrictedRoadExp = mockk() + val trailExpression = mockk() + val trailCasingExpression = mockk() + val state: Expected = + ExpectedFactory.createValue( + RouteLineUpdateValue( + primaryRouteLineDynamicData = RouteLineDynamicData( + { routeLineExp }, + { casingLineEx }, + { trafficLineExp }, + { restrictedRoadExp }, + trailExpressionProvider = { trailExpression }, + trailCasingExpressionProvider = { trailCasingExpression } + ), + alternativeRouteLinesDynamicData = listOf( + RouteLineDynamicData( + { throw UnsupportedOperationException() }, + { throw UnsupportedOperationException() }, + { throw UnsupportedOperationException() }, + { throw UnsupportedOperationException() } + ), + RouteLineDynamicData( + { throw UnsupportedOperationException() }, + { throw UnsupportedOperationException() }, + { throw UnsupportedOperationException() }, + { throw UnsupportedOperationException() } + ) + ), + routeLineMaskingLayerDynamicData = RouteLineDynamicData( + { routeLineExp }, + { casingLineEx }, + { trafficLineExp }, + { restrictedRoadExp }, + trailExpressionProvider = { trailExpression }, + trailCasingExpressionProvider = { trailCasingExpression } + ) + ).also { + it.ignorePrimaryRouteLineData = true + } + ) + val style = mockk