Skip to content

Commit 08002c8

Browse files
dzinadgithub-actions[bot]
authored andcommitted
NAVAND-5616: fix route line progress after reroute
GitOrigin-RevId: c0a5ad6d41a3780cc24e4f54643eab7d00a6b2ac
1 parent 42bf633 commit 08002c8

File tree

5 files changed

+96
-45
lines changed

5 files changed

+96
-45
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Fixed an issue where after a reroute the vanishing point on the route line might have been ahead of the actual vehicle's position.

ui-maps/src/main/java/com/mapbox/navigation/ui/maps/route/line/api/MapboxRouteLineApi.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -744,8 +744,10 @@ class MapboxRouteLineApi @VisibleForTesting internal constructor(
744744
activeLegIndex = currentLegIndex
745745

746746
val (maskingLayerData, routeLineData) = if (legChange) {
747+
val vanishingOffset = vanishingRouteLine?.vanishPointOffset ?: 0.0
747748
val maskingLayerData = getRouteLineDynamicDataForMaskingLayers(
748749
currentPrimaryRoute,
750+
vanishingOffset,
749751
currentLegProgress,
750752
)
751753
val routeLineData =
@@ -759,7 +761,7 @@ class MapboxRouteLineApi @VisibleForTesting internal constructor(
759761
primaryRouteDistance =
760762
currentPrimaryRoute.directionsRoute.distance(),
761763
vanishingPointOffset =
762-
vanishingRouteLine?.vanishPointOffset ?: 0.0,
764+
vanishingOffset,
763765
legIndex = activeLegIndex,
764766
)
765767
} else {
@@ -807,6 +809,7 @@ class MapboxRouteLineApi @VisibleForTesting internal constructor(
807809

808810
internal fun getRouteLineDynamicDataForMaskingLayers(
809811
segments: List<RouteLineExpressionData>,
812+
vanishingOffset: Double?,
810813
distance: Double,
811814
legIndex: Int,
812815
): RouteLineDynamicData {
@@ -903,6 +906,7 @@ class MapboxRouteLineApi @VisibleForTesting internal constructor(
903906
mainExpCommandHolder,
904907
casingExpApplier,
905908
trafficExpProvider,
909+
trimOffset = vanishingOffset?.let { RouteLineTrimOffset(it) },
906910
restrictedSectionExpressionCommandHolder = restrictedExpCommandHolder,
907911
trailExpressionCommandHolder = trailExpCommandHolder,
908912
trailCasingExpressionCommandHolder = trailCasingExpCommandHolder,
@@ -924,13 +928,15 @@ class MapboxRouteLineApi @VisibleForTesting internal constructor(
924928
*/
925929
internal fun getRouteLineDynamicDataForMaskingLayers(
926930
route: NavigationRoute,
931+
vanishingOffset: Double?,
927932
currentLegProgress: RouteLegProgress,
928933
): RouteLineDynamicData? {
929934
val numLegs = route.directionsRoute.legs()?.size ?: 0
930935
val legIndex = currentLegProgress.legIndex
931936
return if (route.isMultiLeg() && legIndex < numLegs) {
932937
getRouteLineDynamicDataForMaskingLayers(
933938
routeLineExpressionData,
939+
vanishingOffset,
934940
route.directionsRoute.distance(),
935941
legIndex,
936942
)
@@ -1380,6 +1386,7 @@ class MapboxRouteLineApi @VisibleForTesting internal constructor(
13801386
val maskingLayerData = if (navigationRoute.isMultiLeg()) {
13811387
getRouteLineDynamicDataForMaskingLayers(
13821388
routeLineExpressionData,
1389+
vanishingPointOffset,
13831390
navigationRoute.directionsRoute.distance(),
13841391
legIndex,
13851392
)

ui-maps/src/main/java/com/mapbox/navigation/ui/maps/route/line/api/MapboxRouteLineView.kt

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@ import androidx.annotation.RestrictTo
44
import androidx.annotation.UiThread
55
import androidx.annotation.VisibleForTesting
66
import com.mapbox.bindgen.Expected
7+
import com.mapbox.bindgen.Value
78
import com.mapbox.common.toValue
89
import com.mapbox.geojson.FeatureCollection
910
import com.mapbox.maps.LayerPosition
1011
import com.mapbox.maps.MapboxMap
1112
import com.mapbox.maps.Style
12-
import com.mapbox.maps.extension.style.expressions.dsl.generated.literal
13-
import com.mapbox.maps.extension.style.expressions.generated.Expression
1413
import com.mapbox.maps.extension.style.layers.Layer
1514
import com.mapbox.maps.extension.style.layers.getLayer
1615
import com.mapbox.maps.extension.style.layers.properties.generated.Visibility
@@ -442,22 +441,22 @@ class MapboxRouteLineView @VisibleForTesting internal constructor(
442441
else -> {
443442
val maskingTrimCommands = if (index == 0) {
444443
listOf(
445-
createTrimOffsetCommand(
444+
createTrimEndCommand(
446445
routeSetValue.routeLineMaskingLayerDynamicData,
447446
MASKING_LAYER_CASING,
448447
style,
449448
),
450-
createTrimOffsetCommand(
449+
createTrimEndCommand(
451450
routeSetValue.routeLineMaskingLayerDynamicData,
452451
MASKING_LAYER_MAIN,
453452
style,
454453
),
455-
createTrimOffsetCommand(
454+
createTrimEndCommand(
456455
routeSetValue.routeLineMaskingLayerDynamicData,
457456
MASKING_LAYER_TRAFFIC,
458457
style,
459458
),
460-
createTrimOffsetCommand(
459+
createTrimEndCommand(
461460
routeSetValue.routeLineMaskingLayerDynamicData,
462461
MASKING_LAYER_RESTRICTED,
463462
style,
@@ -466,7 +465,7 @@ class MapboxRouteLineView @VisibleForTesting internal constructor(
466465
} else {
467466
listOf()
468467
}
469-
getTrimOffsetCommands(
468+
getTrimEndCommands(
470469
style,
471470
sourceKeyFeaturePair.first,
472471
routeLineData,
@@ -1080,14 +1079,14 @@ class MapboxRouteLineView @VisibleForTesting internal constructor(
10801079
}
10811080
}
10821081

1083-
private fun updateTrimOffset(
1082+
private fun updateTrimEnd(
10841083
layerId: String,
1085-
expression: Expression?,
1084+
value: Value?,
10861085
): (Style) -> Unit = { style: Style ->
1087-
ifNonNull(expression) { expression ->
1086+
ifNonNull(value) { expression ->
10881087
style.setStyleLayerProperty(
10891088
layerId,
1090-
"line-trim-offset",
1089+
"line-trim-end",
10911090
expression,
10921091
)
10931092
}
@@ -1128,7 +1127,7 @@ class MapboxRouteLineView @VisibleForTesting internal constructor(
11281127
}
11291128
}
11301129

1131-
private fun getTrimOffsetCommands(
1130+
private fun getTrimEndCommands(
11321131
style: Style,
11331132
routeLineSourceKey: RouteLineSourceKey?,
11341133
routeLineData: RouteLineData,
@@ -1137,20 +1136,20 @@ class MapboxRouteLineView @VisibleForTesting internal constructor(
11371136
val trailLayerIds = trailCasingLayerIds.plus(trailLayerIds)
11381137
return sourceLayerMap[routeLineSourceKey]?.filter { !trailLayerIds.contains(it) }
11391138
?.map {
1140-
createTrimOffsetCommand(routeLineData.dynamicData, it, style)
1139+
createTrimEndCommand(routeLineData.dynamicData, it, style)
11411140
} ?: listOf()
11421141
}
11431142

1144-
private fun createTrimOffsetCommand(
1143+
private fun createTrimEndCommand(
11451144
dynamicData: RouteLineDynamicData?,
11461145
layerId: String,
11471146
style: Style,
11481147
): () -> Unit {
1149-
val expression = ifNonNull(dynamicData, dynamicData?.trimOffset?.offset) { _, offset ->
1150-
literal(listOf(0.0, offset))
1148+
val value = ifNonNull(dynamicData, dynamicData?.trimOffset?.offset) { _, offset ->
1149+
Value.valueOf(offset)
11511150
}
11521151

1153-
return { updateTrimOffset(layerId, expression)(style) }
1152+
return { updateTrimEnd(layerId, value)(style) }
11541153
}
11551154

11561155
private suspend fun getGradientUpdateCommands(

ui-maps/src/test/java/com/mapbox/navigation/ui/maps/route/line/api/MapboxRouteLineApiTest.kt

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1331,6 +1331,7 @@ class MapboxRouteLineApiTest {
13311331

13321332
val result = MapboxRouteLineApi(options).getRouteLineDynamicDataForMaskingLayers(
13331333
segments,
1334+
null,
13341335
multilegRouteWithOverlap.navigationRoute.directionsRoute.distance(),
13351336
1,
13361337
)
@@ -1425,6 +1426,27 @@ class MapboxRouteLineApiTest {
14251426
)
14261427
}
14271428

1429+
@Test
1430+
fun getRouteLineDynamicDataForMaskingLayersVanishingTest() = coroutineRule.runBlockingTest {
1431+
val options = MapboxRouteLineApiOptions.Builder()
1432+
.build()
1433+
val segments = MapboxRouteLineUtils.calculateRouteLineSegments(
1434+
multilegRouteWithOverlap.navigationRoute,
1435+
listOf(),
1436+
true,
1437+
options,
1438+
)
1439+
1440+
val result = MapboxRouteLineApi(options).getRouteLineDynamicDataForMaskingLayers(
1441+
segments,
1442+
0.2,
1443+
multilegRouteWithOverlap.navigationRoute.directionsRoute.distance(),
1444+
1,
1445+
)
1446+
1447+
assertEquals(0.2, result.trimOffset?.offset)
1448+
}
1449+
14281450
@Test
14291451
fun getRouteLineDynamicDataForMaskingLayersForRouteProgressTest() =
14301452
coroutineRule.runBlockingTest {
@@ -1514,6 +1536,7 @@ class MapboxRouteLineApiTest {
15141536

15151537
val result = api.getRouteLineDynamicDataForMaskingLayers(
15161538
multilegRouteWithOverlap.navigationRoute,
1539+
null,
15171540
routeProgress.currentLegProgress!!,
15181541
)!!
15191542

@@ -1609,6 +1632,26 @@ class MapboxRouteLineApiTest {
16091632
)
16101633
}
16111634

1635+
@Test
1636+
fun getRouteLineDynamicDataForMaskingLayersForRouteProgressVanishingTest() =
1637+
coroutineRule.runBlockingTest {
1638+
val options = MapboxRouteLineApiOptions.Builder()
1639+
.build()
1640+
val routeProgress = mockRouteProgress(multilegRouteWithOverlap.navigationRoute)
1641+
every { routeProgress.currentLegProgress!!.legIndex } returns 1
1642+
every { routeProgress.currentRouteGeometryIndex } returns 43
1643+
val api = MapboxRouteLineApi(options)
1644+
api.setNavigationRoutes(listOf(multilegRouteWithOverlap.navigationRoute))
1645+
1646+
val result = api.getRouteLineDynamicDataForMaskingLayers(
1647+
multilegRouteWithOverlap.navigationRoute,
1648+
0.1,
1649+
routeProgress.currentLegProgress!!,
1650+
)!!
1651+
1652+
assertEquals(0.1, result.trimOffset?.offset)
1653+
}
1654+
16121655
@Test
16131656
fun getRouteLineDynamicDataForMaskingLayersForRouteProgressWhenSingleLegRouteTest() {
16141657
val options = MapboxRouteLineApiOptions.Builder().build()
@@ -1617,6 +1660,7 @@ class MapboxRouteLineApiTest {
16171660

16181661
val result = MapboxRouteLineApi(options).getRouteLineDynamicDataForMaskingLayers(
16191662
shortRoute.navigationRoute,
1663+
null,
16201664
routeProgress.currentLegProgress!!,
16211665
)
16221666

@@ -1631,6 +1675,7 @@ class MapboxRouteLineApiTest {
16311675

16321676
val result = MapboxRouteLineApi(options).getRouteLineDynamicDataForMaskingLayers(
16331677
shortRoute.navigationRoute,
1678+
null,
16341679
routeProgress.currentLegProgress!!,
16351680
)
16361681

0 commit comments

Comments
 (0)