Skip to content

Commit 536a017

Browse files
author
Bobby Sudekum
authored
Merge pull request #1411 from mapbox/better-end
Improve arrival location and end of route screen animation
2 parents 5322a46 + 7d54122 commit 536a017

File tree

4 files changed

+18
-15
lines changed

4 files changed

+18
-15
lines changed

MapboxCoreNavigation/Constants.swift

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,6 @@ public var RouteControllerProactiveReroutingInterval: TimeInterval = 120
8282

8383
let FasterRouteFoundEvent = "navigation.fasterRoute"
8484

85-
/**
86-
The number of seconds remaining on the final step of a leg before the user is considered "arrived".
87-
*/
88-
public var RouteControllerDurationRemainingWaypointArrival: TimeInterval = 3
89-
9085
//MARK: - Route Snapping (CLLocation)
9186
/**
9287
Accepted deviation excluding horizontal accuracy before the user is considered to be off route.

MapboxCoreNavigation/RouteController.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -661,9 +661,9 @@ extension RouteController: CLLocationManagerDelegate {
661661

662662
func updateRouteLegProgress(for location: CLLocation) {
663663
let currentDestination = routeProgress.currentLeg.destination
664-
let legDurationRemaining = routeProgress.currentLegProgress.durationRemaining
664+
guard let remainingVoiceInstructions = routeProgress.currentLegProgress.currentStepProgress.remainingSpokenInstructions else { return }
665665

666-
if legDurationRemaining < RouteControllerDurationRemainingWaypointArrival, currentDestination != previousArrivalWaypoint {
666+
if routeProgress.currentLegProgress.remainingSteps.count <= 1 && remainingVoiceInstructions.count == 0 && currentDestination != previousArrivalWaypoint {
667667
previousArrivalWaypoint = currentDestination
668668

669669
routeProgress.currentLegProgress.userHasArrivedAtWaypoint = true

MapboxNavigation/NavigationMapView.swift

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -344,11 +344,7 @@ open class NavigationMapView: MGLMapView, UIGestureRecognizerDelegate {
344344
let padding = UIEdgeInsets(top: point.y, left: point.x, bottom: bounds.height - point.y, right: bounds.width - point.x)
345345
let newCamera = MGLMapCamera(lookingAtCenter: location.coordinate, fromDistance: altitude, pitch: 45, heading: location.course)
346346
let function: CAMediaTimingFunction? = animated ? CAMediaTimingFunction(name: kCAMediaTimingFunctionLinear) : nil
347-
setCamera(newCamera, withDuration: duration, animationTimingFunction: function, edgePadding: padding, completionHandler: {
348-
UIView.animate(withDuration: duration, delay: 0, options: [.curveLinear, .beginFromCurrentState], animations: {
349-
self.userCourseView?.center = self.convert(location.coordinate, toPointTo: self)
350-
}, completion: nil)
351-
})
347+
setCamera(newCamera, withDuration: duration, animationTimingFunction: function, edgePadding: padding, completionHandler: nil)
352348
} else {
353349
UIView.animate(withDuration: duration, delay: 0, options: [.curveLinear, .beginFromCurrentState], animations: {
354350
self.userCourseView?.center = self.convert(location.coordinate, toPointTo: self)

MapboxNavigation/RouteMapViewController.swift

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ func defaultFeedbackHandlers(source: FeedbackSource = .user) -> (send: FeedbackV
490490
endOfRoute.removeFromParentViewController()
491491
}
492492

493-
func showEndOfRoute(duration: TimeInterval = 0.3, completion: ((Bool) -> Void)? = nil) {
493+
func showEndOfRoute(duration: TimeInterval = 1.0, completion: ((Bool) -> Void)? = nil) {
494494
embedEndOfRoute()
495495
endOfRouteViewController.destination = destination
496496
navigationView.endOfRouteView?.isHidden = false
@@ -512,10 +512,22 @@ func defaultFeedbackHandlers(source: FeedbackSource = .user) -> (send: FeedbackV
512512
let noAnimation = { animate(); completion?(true) }
513513

514514
guard duration > 0.0 else { return noAnimation() }
515+
516+
navigationView.mapView.tracksUserCourse = false
515517
UIView.animate(withDuration: duration, delay: 0.0, options: [.curveLinear], animations: animate, completion: completion)
516518

517-
// Prevent the user puck from floating around.
518-
mapView.updateCourseTracking(location: routeController.location, animated: false)
519+
guard let height = navigationView.endOfRouteHeightConstraint?.constant else { return }
520+
let insets = UIEdgeInsets(top: navigationView.instructionsBannerView.bounds.height, left: 20, bottom: height + 20, right: 20)
521+
522+
if let coordinates = routeController.routeProgress.route.coordinates, let userLocation = routeController.locationManager.location?.coordinate {
523+
let slicedLine = Polyline(coordinates).sliced(from: userLocation).coordinates
524+
let line = MGLPolyline(coordinates: slicedLine, count: UInt(slicedLine.count))
525+
526+
let camera = navigationView.mapView.cameraThatFitsShape(line, direction: navigationView.mapView.camera.heading, edgePadding: insets)
527+
camera.pitch = 0
528+
camera.altitude = navigationView.mapView.camera.altitude
529+
navigationView.mapView.setCamera(camera, animated: true)
530+
}
519531
}
520532

521533
func hideEndOfRoute(duration: TimeInterval = 0.3, completion: ((Bool) -> Void)? = nil) {

0 commit comments

Comments
 (0)