Skip to content

Commit 2606ee3

Browse files
jushgithub-actions[bot]
authored andcommitted
Some comments, better naming, and avoid 3 styleLayers JNI calls
GitOrigin-RevId: f66a214280dc4178d33ba71c57f5206b882b9c76
1 parent cefe454 commit 2606ee3

2 files changed

Lines changed: 25 additions & 13 deletions

File tree

ui-maps/src/main/java/com/mapbox/navigation/ui/maps/internal/route/line/MapboxRouteLineUtils.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2638,20 +2638,21 @@ internal object MapboxRouteLineUtils {
26382638

26392639
internal fun getTopRouteLineRelatedLayerId(style: Style): String? {
26402640
return runCatching {
2641-
val upperRange = style.styleLayers.indexOf(
2641+
val styleLayers = style.styleLayers
2642+
val upperRange = styleLayers.indexOf(
26422643
StyleObjectInfo(
26432644
RouteLayerConstants.TOP_LEVEL_ROUTE_LINE_LAYER_ID,
26442645
"background",
26452646
),
26462647
)
2647-
val lowerRange = style.styleLayers.indexOf(
2648+
val lowerRange = styleLayers.indexOf(
26482649
StyleObjectInfo(
26492650
RouteLayerConstants.BOTTOM_LEVEL_ROUTE_LINE_LAYER_ID,
26502651
"background",
26512652
),
26522653
)
26532654

2654-
style.styleLayers.subList(lowerRange, upperRange)
2655+
styleLayers.subList(lowerRange, upperRange)
26552656
.filter { it.id !in maskingLayerIds }
26562657
.mapIndexed { index, styleObjectInfo ->
26572658
Pair(index, styleObjectInfo.id)

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

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,9 @@ class MapboxRouteLineView @VisibleForTesting internal constructor(
348348
val featuresNotOnMap = routeLineDatas.map {
349349
RouteLineFeatureId(it.featureCollection.features()?.firstOrNull()?.id())
350350
}.filter { it !in sourceToFeatureMap.values }
351+
// If the incoming feature IDs are already in the map. That is, they're in the
352+
// sourceToFeatureMap we don't need to update them. `sourcesToUpdate` will contain
353+
// the sources that are available to be replaced for the new features.
351354
val sourcesToUpdate = sourceToFeatureMap.filter {
352355
it.value.id() !in incomingFeatureIds
353356
}
@@ -361,17 +364,24 @@ class MapboxRouteLineView @VisibleForTesting internal constructor(
361364
it.featureCollection.features()?.firstOrNull()?.id() ==
362365
nextFeatureId?.id()
363366
}
364-
val fc: FeatureCollection =
365-
nextRouteLineData?.featureCollection
366-
?: FeatureCollection.fromFeatures(listOf())
367+
// Either we get the next route line data or empty if there are no more.
368+
val fc: FeatureCollection = nextRouteLineData?.featureCollection
369+
?: FeatureCollection.fromFeatures(listOf())
367370
val sourceId = sourceToUpdate.key.sourceId
368371
val routeId = nextFeatureId?.id()
369372
val dataId = dataIdHolder.incrementDataId(sourceId)
373+
374+
// We don't really clear the source but rather replace its data with the new
375+
// feature collection `fc` (which can be an empty).
376+
// We add it to the cleared route list if the previous feature collection
377+
// (`sourceToFeatureMap[sourceToUpdate.key]?.id()`) is not null.
370378
expectedRoutesData.addClearedRoute(
371379
sourceId,
372380
dataId,
373381
sourceToFeatureMap[sourceToUpdate.key]?.id(),
374382
)
383+
// Finally add the new route to the rendered route list and create the command
384+
// to update the source (which can be empty geometry).
375385
expectedRoutesData.addRenderedRoute(sourceId, dataId, routeId)
376386
updateSourceCommands.add {
377387
updateSource(style, sourceToUpdate.key.sourceId, fc, dataId)
@@ -740,24 +750,25 @@ class MapboxRouteLineView @VisibleForTesting internal constructor(
740750
logE(TAG, error.message)
741751
null
742752
},
743-
)?.also {
744-
val newDataId = dataIdHolder.incrementDataId(it.sourceId)
753+
)?.also { primaryRouteLineSourceKey ->
754+
val primarySourceId = primaryRouteLineSourceKey.sourceId
755+
val newDataId = dataIdHolder.incrementDataId(primarySourceId)
745756
val routeId = value.primaryRouteSource.features()?.firstOrNull()?.id()
746757
expectedRoutesData.addClearedRoute(
747-
it.sourceId,
758+
primarySourceId,
748759
newDataId,
749-
sourceToFeatureMap[it]?.id(),
760+
sourceToFeatureMap[primaryRouteLineSourceKey]?.id(),
750761
)
751-
expectedRoutesData.addRenderedRoute(it.sourceId, newDataId, routeId)
762+
expectedRoutesData.addRenderedRoute(primarySourceId, newDataId, routeId)
752763
updateSourceCommands.add {
753764
updateSource(
754765
style,
755-
it.sourceId,
766+
primarySourceId,
756767
value.primaryRouteSource,
757768
newDataId,
758769
)
759770
}
760-
sourceToFeatureMap[it] = RouteLineFeatureId(routeId)
771+
sourceToFeatureMap[primaryRouteLineSourceKey] = RouteLineFeatureId(routeId)
761772
}
762773
sourceLayerMap.keys.filter { it != primarySourceKey }
763774
.forEachIndexed { index, routeLineSourceKey ->

0 commit comments

Comments
 (0)