Skip to content

Commit c28e1e7

Browse files
authored
Navigation camera viewport API. (#2826)
1 parent 6cc9728 commit c28e1e7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+2227
-1057
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@
3939
* Improved performance and decreased memory usage when downloading routing tiles. ([#2808](https://github.com/mapbox/mapbox-navigation-ios/pull/2808))
4040
* Renamed `PassiveLocationManager.startUpdatingLocation(completionHandler:)` to `PassiveLocationManager.startUpdatingLocation()`. This method now runs synchronously like `CLLocationManager.startUpdatingLocation()`. ([#2823](https://github.com/mapbox/mapbox-navigation-ios/pull/2823))
4141

42+
### Camera
43+
44+
* Added Navigation Viewport Camera APIs, which allow to control camera viewport system frames based on various properties, such as: current location, some or all of the remaining route line coordinates, upcoming maneuvers etc. This allows to provide a camera viewport system, which is optimal for visualization and animation in navigation applications. ([#2826](https://github.com/mapbox/mapbox-navigation-ios/pull/2826))
45+
* Removed `CarPlayNavigationViewController.tracksUserCourse`, `NavigationMapView.defaultAltitude`, `NavigationMapView.zoomedOutMotorwayAltitude`, `NavigationMapView.longManeuverDistance`, `NavigationMapView.showsUserLocation`, `NavigationMapView.tracksUserCourse`, `NavigationMapView.enableFrameByFrameCourseViewTracking(for:)`, `NavigationMapView.updateCourseTracking(location:camera:animated:)` `NavigationMapView.defaultPadding`, `NavigationMapView.setOverheadCameraView(from:along:for:)`, `NavigationMapView.recenterMap()`, `NavigationMapViewDelegate.navigationMapViewUserAnchorPoint(_:)`, `NavigationMapViewCourseTrackingDelegate`, `NavigationViewController.pendingCamera` in favor of new Navigation Viewport Camera APIs. ([#2826](https://github.com/mapbox/mapbox-navigation-ios/pull/2826))
46+
* Replaced `CourseUpdatable.update(location:pitch:direction:animated:tracksUserCourse:)` with `CourseUpdatable.update(location:pitch:direction:animated:navigationCameraState:)` to provide more agile way of handling `NavigationCameraState`. ([#2826](https://github.com/mapbox/mapbox-navigation-ios/pull/2826))
47+
* Added `NavigationMapView.init(frame:navigationCameraType:)` to be able to provide type of `NavigationCamera`, which should be used for that specific instance of `NavigationMapView` (either iOS or CarPlay). ([#2826](https://github.com/mapbox/mapbox-navigation-ios/pull/2826))
48+
* Added `NavigationCamera`, `ViewportDataSourceType`, `ViewportDataSourceDelegate`, `NavigationCameraState` Navigation Viewport Camera APIs. By default Navigation SDK for iOS provides default camera behavior via `NavigationViewportDataSource` and `NavigationCameraStateTransition` classes. If you'd like to override current behavior use `ViewportDataSource` and `CameraStateTransition` protocols for custom behavior. ([#2826](https://github.com/mapbox/mapbox-navigation-ios/pull/2826))
49+
4250
### CarPlay
4351

4452
* Removed deprecated `CarPlayNavigationDelegate.carPlayNavigationViewControllerDidArrive(_:)`. ([#2808](https://github.com/mapbox/mapbox-navigation-ios/pull/2808))

Example/AppDelegate+CarPlay.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ extension AppDelegate: CarPlayManagerDelegate {
5757

5858
// MARK: CarPlayManagerDelegate
5959
func carPlayManager(_ carPlayManager: CarPlayManager, didBeginNavigationWith service: NavigationService) {
60-
currentAppRootViewController?.beginNavigationWithCarplay(navigationService: service)
60+
currentAppRootViewController?.beginNavigationWithCarPlay(navigationService: service)
6161
carPlayManager.currentNavigator?.compassView.isHidden = false
6262

6363
// Render part of the route that has been traversed with full transparency, to give the illusion of a disappearing route.

Example/CustomViewController.swift

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,16 @@ import MapboxNavigation
44
import MapboxDirections
55
import MapboxMaps
66

7-
// FIXME: Currently if `MapView` is created using storyboard crash occurs.
87
class CustomViewController: UIViewController {
98

9+
var destinationAnnotation: PointAnnotation! {
10+
didSet {
11+
navigationMapView.mapView.annotationManager.addAnnotation(destinationAnnotation)
12+
}
13+
}
14+
1015
var navigationService: NavigationService!
16+
1117
var simulateLocation = false
1218

1319
var userIndexedRoute: IndexedRoute?
@@ -34,6 +40,7 @@ class CustomViewController: UIViewController {
3440
super.viewDidLoad()
3541

3642
navigationMapView.mapView.style.styleURL = .custom(url: URL(string: "mapbox://styles/mapbox-map-design/ckd6dqf981hi71iqlyn3e896y")!)
43+
navigationMapView.userCourseView.isHidden = false
3744

3845
let locationManager = simulateLocation ? SimulatedLocationManager(route: userIndexedRoute!.0) : NavigationLocationManager()
3946
navigationService = MapboxNavigationService(route: userIndexedRoute!.0, routeIndex: userIndexedRoute!.1, routeOptions: userRouteOptions!, locationSource: locationManager, simulating: simulateLocation ? .always : .onPoorGPS)
@@ -51,13 +58,15 @@ class CustomViewController: UIViewController {
5158
// Start navigation
5259
navigationService.start()
5360

54-
// Center map on user
55-
navigationMapView.recenterMap()
56-
5761
navigationMapView.mapView.on(.styleLoaded, handler: { [weak self] _ in
5862
guard let route = self?.navigationService.route else { return }
5963
self?.navigationMapView.show([route])
6064
})
65+
66+
// By default `NavigationViewportDataSource` tracks location changes from `PassiveLocationDataSource`, to consume
67+
// locations in active guidance navigation `ViewportDataSourceType` should be set to `.active`.
68+
let navigationViewportDataSource = NavigationViewportDataSource(navigationMapView.mapView, viewportDataSourceType: .active)
69+
navigationMapView.navigationCamera.viewportDataSource = navigationViewportDataSource
6170
}
6271

6372
override func viewWillAppear(_ animated: Bool) {
@@ -101,8 +110,8 @@ class CustomViewController: UIViewController {
101110
instructionsBannerView.updateDistance(for: routeProgress.currentLegProgress.currentStepProgress)
102111
instructionsBannerView.isHidden = false
103112

104-
// Update the user puck
105-
navigationMapView.updateCourseTracking(location: location, animated: true)
113+
// Update `UserCourseView` to be placed on the most recent location.
114+
navigationMapView.updateUserCourseView(location, animated: true)
106115
}
107116

108117
@objc func updateInstructionsBanner(notification: NSNotification) {
@@ -122,7 +131,7 @@ class CustomViewController: UIViewController {
122131
}
123132

124133
@IBAction func recenterMap(_ sender: Any) {
125-
navigationMapView.recenterMap()
134+
navigationMapView.navigationCamera.follow()
126135
}
127136

128137
@IBAction func showFeedback(_ sender: Any) {
@@ -172,8 +181,7 @@ class CustomViewController: UIViewController {
172181
updatePreviewBannerWith(step: step, maneuverStep: maneuverStep)
173182

174183
// stop tracking user, and move camera to step location
175-
navigationMapView.tracksUserCourse = false
176-
navigationMapView.enableFrameByFrameCourseViewTracking(for: 1)
184+
navigationMapView.navigationCamera.stop()
177185
navigationMapView.mapView.cameraManager.setCamera(centerCoordinate: maneuverStep.maneuverLocation,
178186
bearing: maneuverStep.initialHeading!,
179187
animated: true)

Example/ViewController+FreeDrive.swift

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import MapboxMaps
1010

1111
extension ViewController {
1212

13-
func setupPassiveLocationManager(_ navigationMapView: NavigationMapView) {
13+
func setupPassiveLocationManager() {
1414
setupFreeDriveStyledFeatures()
15-
15+
1616
let passiveLocationDataSource = PassiveLocationDataSource()
1717
let passiveLocationManager = PassiveLocationManager(dataSource: passiveLocationDataSource)
1818
navigationMapView.mapView.locationManager.overrideLocationProvider(with: passiveLocationManager)
@@ -67,6 +67,12 @@ extension ViewController {
6767
color: .lightGray,
6868
lineWidth: 3.0,
6969
lineString: LineString([]))
70+
71+
navigationMapView.mapView.on(.styleLoaded, handler: { [weak self] _ in
72+
guard let self = self else { return }
73+
self.addStyledFeature(self.trackStyledFeature)
74+
self.addStyledFeature(self.rawTrackStyledFeature)
75+
})
7076
}
7177

7278
func updateFreeDriveStyledFeatures() {
@@ -116,7 +122,6 @@ extension ViewController {
116122
let branchNames = branchEdgeIdentifiers.flatMap { edgeNames(identifier: $0) }
117123
statusString += " at \(branchNames.joined(separator: ", "))"
118124
}
119-
print(statusString)
120125
}
121126

122127
func edgeNames(identifier: ElectronicHorizon.Edge.Identifier) -> [String] {

Example/ViewController+GuidanceCards.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ extension ViewController: InstructionsCardCollectionDelegate {
1919
let maneuverStep = leg.steps[stepIndex + 1]
2020

2121
// stop tracking user, and move camera to step location
22-
navigationMapView.tracksUserCourse = false
23-
navigationMapView.enableFrameByFrameCourseViewTracking(for: 1)
22+
navigationMapView.navigationCamera.stop()
2423

2524
let camera = CameraOptions(center: maneuverStep.maneuverLocation,
2625
zoom: navigationMapView.mapView.zoom,

0 commit comments

Comments
 (0)