@@ -17,6 +17,7 @@ import com.mapbox.maps.ScreenBox
1717import com.mapbox.maps.toCameraOptions
1818import com.mapbox.maps.util.isEmpty
1919import com.mapbox.navigation.base.ExperimentalPreviewMapboxNavigationAPI
20+ import com.mapbox.navigation.base.internal.performance.PerformanceTracker
2021import com.mapbox.navigation.base.internal.utils.areSameRoutes
2122import com.mapbox.navigation.base.internal.utils.isSameRoute
2223import com.mapbox.navigation.base.route.NavigationRoute
@@ -373,7 +374,9 @@ class MapboxNavigationViewportDataSource private constructor(
373374 fun evaluate () {
374375 mapsSizeReadyCancellable?.cancel()
375376 mapsSizeReadyCancellable = mapSizeReadyCallbackHelper.onMapSizeInitialized {
376- evaluateImpl()
377+ PerformanceTracker .trackPerformance(" MapboxNavigationViewportDataSource#evaluateImpl" ) {
378+ evaluateImpl()
379+ }
377380 }
378381 }
379382
@@ -417,7 +420,9 @@ class MapboxNavigationViewportDataSource private constructor(
417420 * @see [evaluate]
418421 */
419422 fun onRouteChanged (route : NavigationRoute ) {
420- onRoutesChanged(listOf (route))
423+ PerformanceTracker .trackPerformance(" MapboxNavigationViewportDataSource#onRouteChanged" ) {
424+ onRoutesChanged(listOf (route))
425+ }
421426 }
422427
423428 internal fun onRoutesChanged (routes : List <NavigationRoute >) {
@@ -444,61 +449,10 @@ class MapboxNavigationViewportDataSource private constructor(
444449 * @see [evaluate]
445450 */
446451 fun onRouteProgressChanged (routeProgress : RouteProgress ) {
447- this .routeProgress = routeProgress
448- val currentRoute = this .navigationRoute
449- if (currentRoute == null ) {
450- logW(
451- " You're calling #onRouteProgressChanged but you didn't call #onRouteChanged." ,
452- LOG_CATEGORY ,
453- )
454- clearProgressData()
455- return
456- } else if (! currentRoute.directionsRoute.isSameRoute(routeProgress.route)) {
457- logE(
458- " Provided route (#onRouteChanged) and navigated route " +
459- " (#onRouteProgressChanged) are not the same. " +
460- " Aborting framed geometry updates based on route progress." ,
461- LOG_CATEGORY ,
462- )
463- clearProgressData()
464- return
465- }
466-
467- ifNonNull(
468- routeProgress.currentLegProgress,
469- routeProgress.currentLegProgress?.currentStepProgress,
470- ) { currentLegProgress, currentStepProgress ->
471- isFramingManeuverProperty.fallback = isFramingManeuver(
472- routeProgress,
473- options.followingFrameOptions,
474- )
475- followingPitchProperty.fallback = if (isFramingManeuverProperty.get()) {
476- ZERO_PITCH
477- } else {
478- options.followingFrameOptions.defaultPitch
479- }
480-
481- pointsToFrameOnCurrentStep = options.followingFrameOptions.framingStrategy
482- .getPointsToFrameOnCurrentStep(
483- routeProgress,
484- options.followingFrameOptions,
485- averageIntersectionDistancesOnRoute,
486- )
487-
488- pointsToFrameAfterCurrentStep = options.followingFrameOptions.framingStrategy
489- .getPointsToFrameAfterCurrentManeuver(
490- routeProgress,
491- options.followingFrameOptions,
492- postManeuverFramingPoints,
493- )
494-
495- overviewViewportDataSource.onRouteProgressChanged(routeProgress)
496- } ? : run {
497- logE(
498- " You're calling #onRouteProgressChanged with empty leg or step progress." ,
499- LOG_CATEGORY ,
500- )
501- clearProgressData()
452+ PerformanceTracker .trackPerformance(
453+ " MapboxNavigationViewportDataSource#onRouteProgressChanged" ,
454+ ) {
455+ onRouteProgressChangedInternal(routeProgress)
502456 }
503457 }
504458
@@ -568,6 +522,65 @@ class MapboxNavigationViewportDataSource private constructor(
568522 evaluate()
569523 }
570524
525+ private fun onRouteProgressChangedInternal (routeProgress : RouteProgress ) {
526+ this .routeProgress = routeProgress
527+ val currentRoute = this .navigationRoute
528+ if (currentRoute == null ) {
529+ logW(
530+ " You're calling #onRouteProgressChanged but you didn't call #onRouteChanged." ,
531+ LOG_CATEGORY ,
532+ )
533+ clearProgressData()
534+ return
535+ } else if (! currentRoute.directionsRoute.isSameRoute(routeProgress.route)) {
536+ logE(
537+ " Provided route (#onRouteChanged) and navigated route " +
538+ " (#onRouteProgressChanged) are not the same. " +
539+ " Aborting framed geometry updates based on route progress." ,
540+ LOG_CATEGORY ,
541+ )
542+ clearProgressData()
543+ return
544+ }
545+
546+ ifNonNull(
547+ routeProgress.currentLegProgress,
548+ routeProgress.currentLegProgress?.currentStepProgress,
549+ ) { currentLegProgress, currentStepProgress ->
550+ isFramingManeuverProperty.fallback = isFramingManeuver(
551+ routeProgress,
552+ options.followingFrameOptions,
553+ )
554+ followingPitchProperty.fallback = if (isFramingManeuverProperty.get()) {
555+ ZERO_PITCH
556+ } else {
557+ options.followingFrameOptions.defaultPitch
558+ }
559+
560+ pointsToFrameOnCurrentStep = options.followingFrameOptions.framingStrategy
561+ .getPointsToFrameOnCurrentStep(
562+ routeProgress,
563+ options.followingFrameOptions,
564+ averageIntersectionDistancesOnRoute,
565+ )
566+
567+ pointsToFrameAfterCurrentStep = options.followingFrameOptions.framingStrategy
568+ .getPointsToFrameAfterCurrentManeuver(
569+ routeProgress,
570+ options.followingFrameOptions,
571+ postManeuverFramingPoints,
572+ )
573+
574+ overviewViewportDataSource.onRouteProgressChanged(routeProgress)
575+ } ? : run {
576+ logE(
577+ " You're calling #onRouteProgressChanged with empty leg or step progress." ,
578+ LOG_CATEGORY ,
579+ )
580+ clearProgressData()
581+ }
582+ }
583+
571584 private fun clearProgressData () {
572585 followingPitchProperty.fallback = options.followingFrameOptions.defaultPitch
573586 pointsToFrameOnCurrentStep = emptyList()
0 commit comments