Skip to content

Commit

Permalink
Added flag to ignore route line updates in the view under certain con…
Browse files Browse the repository at this point in the history
…ditions.
  • Loading branch information
Seth Bourget committed Feb 27, 2023
1 parent 89a2e42 commit ed47799
Show file tree
Hide file tree
Showing 5 changed files with 168 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -799,20 +799,29 @@ 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<Expected<RouteLineError, RouteLineUpdateValue>>
) {
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<RouteLineError, RouteLineUpdateValue>(
RouteLineUpdateValue(
this.primaryRouteLineData.dynamicData,
this.alternativeRouteLinesData.map { it.dynamicData },
maskingLayerData
)
updateValue
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class RouteLineUpdateValue internal constructor(
val routeLineMaskingLayerDynamicData: RouteLineDynamicData? = null
) {

internal var ignorePrimaryRouteLineData = false

/**
* @return a class with mutable values for replacing.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1064,6 +1064,7 @@ class MapboxRouteLineApiTest {
assertEquals(expectedCasingExpression, casingExpression.toString())
assertEquals(expectedTrailExpression, trailExpression.toString())
assertEquals(expectedTrailCasingExpression, trailCasingExpression.toString())
assertTrue(result.ignorePrimaryRouteLineData)

callbackCalled = true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Expression>()
val routeLineExp = mockk<Expression>()
val casingLineEx = mockk<Expression>()
val restrictedRoadExp = mockk<Expression>()
val trailExpression = mockk<Expression>()
val trailCasingExpression = mockk<Expression>()
val state: Expected<RouteLineError, RouteLineUpdateValue> =
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<Style> {
every {
setStyleLayerProperty(any(), any(), any())
} returns ExpectedFactory.createNone()
}.also {
mockCheckForLayerInitialization(it)
}

pauseDispatcher {
val view = MapboxRouteLineView(options)
view.initPrimaryRouteLineLayerGroup(MapboxRouteLineUtils.layerGroup1SourceLayerIds)
view.renderRouteLineUpdate(style, state)
}

verify(exactly = 0) {
style.setStyleLayerProperty(
LAYER_GROUP_1_TRAFFIC,
"line-gradient",
trafficLineExp
)
}
verify(exactly = 0) {
style.setStyleLayerProperty(
LAYER_GROUP_1_MAIN,
"line-gradient",
routeLineExp
)
}
verify(exactly = 0) {
style.setStyleLayerProperty(
LAYER_GROUP_1_CASING,
"line-gradient",
casingLineEx
)
}
verify(exactly = 0) {
style.setStyleLayerProperty(
LAYER_GROUP_1_RESTRICTED,
"line-gradient",
restrictedRoadExp
)
}
verify(exactly = 0) {
style.setStyleLayerProperty(
LAYER_GROUP_1_TRAIL,
"line-gradient",
trailExpression
)
}
verify(exactly = 0) {
style.setStyleLayerProperty(
LAYER_GROUP_1_TRAIL_CASING,
"line-gradient",
trailCasingExpression
)
}
verify {
style.setStyleLayerProperty(
MASKING_LAYER_TRAFFIC,
"line-gradient",
trafficLineExp
)
}
verify {
style.setStyleLayerProperty(
MASKING_LAYER_MAIN,
"line-gradient",
routeLineExp
)
}
verify {
style.setStyleLayerProperty(
MASKING_LAYER_CASING,
"line-gradient",
casingLineEx
)
}
verify {
style.setStyleLayerProperty(
MASKING_LAYER_TRAIL,
"line-gradient",
trailExpression
)
}
verify {
style.setStyleLayerProperty(
MASKING_LAYER_TRAIL_CASING,
"line-gradient",
trailCasingExpression
)
}

unmockkObject(MapboxRouteLineUtils)
unmockkStatic("com.mapbox.maps.extension.style.layers.LayerUtils")
}

@Test
fun renderTraveledRouteLineTrimUpdate() = coroutineRule.runBlockingTest {
mockkStatic("com.mapbox.maps.extension.style.layers.LayerUtils")
Expand Down

0 comments on commit ed47799

Please sign in to comment.