From 4e0f445d97dd90bdd8b30646bec927c7c474a939 Mon Sep 17 00:00:00 2001 From: Bobby Sudekum Date: Thu, 24 May 2018 15:52:42 -0700 Subject: [PATCH 1/2] Fix setOverheadCameraView for short routes --- MapboxNavigation/NavigationMapView.swift | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/MapboxNavigation/NavigationMapView.swift b/MapboxNavigation/NavigationMapView.swift index 98321974dc0..ace2e36a2f9 100644 --- a/MapboxNavigation/NavigationMapView.swift +++ b/MapboxNavigation/NavigationMapView.swift @@ -1030,14 +1030,25 @@ open class NavigationMapView: MGLMapView, UIGestureRecognizerDelegate { let line = MGLPolyline(coordinates: slicedLine, count: UInt(slicedLine.count)) tracksUserCourse = false + + // If the user has a short distance left on the route, prevent the camera from zooming all the way. + // `MGLMapView.setVisibleCoordinateBounds(:edgePadding:animated:)` will go beyond what is convient for the driver. + guard line.overlayBounds.ne.distance(to: line.overlayBounds.sw) > NavigationMapViewMinimumDistanceForOverheadZooming else { + let camera = self.camera + camera.pitch = 0 + camera.heading = 0 + camera.centerCoordinate = userLocation + camera.altitude = NavigationMapView.defaultAltitude + setCamera(camera, animated: true) + return + } + + // Sadly, `MGLMapView.setVisibleCoordinateBounds(:edgePadding:animated:)` uses the current pitch and direction of the mapview. Ideally, we'd be able to pass in zero. let camera = self.camera camera.pitch = 0 camera.heading = 0 self.camera = camera - // Don't keep zooming in - guard line.overlayBounds.ne.distance(to: line.overlayBounds.sw) > NavigationMapViewMinimumDistanceForOverheadZooming else { return } - setVisibleCoordinateBounds(line.overlayBounds, edgePadding: bounds, animated: true) } } From f812683bc942f0ffaaaa26c86c5ea50809cfb804 Mon Sep 17 00:00:00 2001 From: Bobby Sudekum Date: Tue, 29 May 2018 10:49:26 -0700 Subject: [PATCH 2/2] update --- CHANGELOG.md | 1 + MapboxNavigation/NavigationMapView.swift | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ba1a784e348..7129071fae7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ * `NavigationMapViewDelegate.navigationMapView(_:shapeFor:)` Now expects an array of `Route`. The first route will be rendered as the main route, all subsequent routes will be rendered as alternate routes. * Added support for generic route shields. Image-backed route shields also now display as generic (instead of plain text) while the SDK loads the image. [#1190](https://github.com/mapbox/mapbox-navigation-ios/issues/1190), [#1417](https://github.com/mapbox/mapbox-navigation-ios/pull/1417) * Animating the user through tunnels and automatically switching the map style when entering a tunnel is now on by default. [#1449](https://github.com/mapbox/mapbox-navigation-ios/pull/1449) +* Fixed an issue when going into overhead mode with a short route. [#1456](https://github.com/mapbox/mapbox-navigation-ios/pull/1456/) ## v0.17.0 (May 14, 2018) diff --git a/MapboxNavigation/NavigationMapView.swift b/MapboxNavigation/NavigationMapView.swift index ace2e36a2f9..fccb24d886f 100644 --- a/MapboxNavigation/NavigationMapView.swift +++ b/MapboxNavigation/NavigationMapView.swift @@ -1032,7 +1032,7 @@ open class NavigationMapView: MGLMapView, UIGestureRecognizerDelegate { tracksUserCourse = false // If the user has a short distance left on the route, prevent the camera from zooming all the way. - // `MGLMapView.setVisibleCoordinateBounds(:edgePadding:animated:)` will go beyond what is convient for the driver. + // `MGLMapView.setVisibleCoordinateBounds(:edgePadding:animated:)` will go beyond what is convenient for the driver. guard line.overlayBounds.ne.distance(to: line.overlayBounds.sw) > NavigationMapViewMinimumDistanceForOverheadZooming else { let camera = self.camera camera.pitch = 0