Skip to content

Commit

Permalink
Merge pull request #2366 from mapbox/2284-route-refresh
Browse files Browse the repository at this point in the history
Route Refresh
  • Loading branch information
1ec5 authored Sep 4, 2020
2 parents f32f511 + e979932 commit c945bcf
Show file tree
Hide file tree
Showing 42 changed files with 419 additions and 191 deletions.
14 changes: 13 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@
* Xcode 11.4.1 or above is now required for building this SDK from source. ([#2417](https://github.com/mapbox/mapbox-navigation-ios/pull/2417))
* Enabled MAU billing by default, so that SDKs usage of Mapbox APIs is [billed](https://www.mapbox.com/pricing/) together based on [monthly active users](https://docs.mapbox.com/help/glossary/monthly-active-users/) rather than individually by HTTP request. If you prefer to still use request-based billing, set the `MBXNavigationBillingMethod` key in Info.plist to `request` ([#2405](https://github.com/mapbox/mapbox-navigation-ios/pull/2405).
* Added Greek and Turkish localizations. ([#2385](https://github.com/mapbox/mapbox-navigation-ios/pull/2385), [#2475](https://github.com/mapbox/mapbox-navigation-ios/pull/2475), [valhalla/valhalla#2438](https://github.com/valhalla/valhalla/pull/2438))
* Upgraded to [MapboxDirections v0.33.2](https://github.com/mapbox/mapbox-directions-swift/releases/tag/v0.33.2). ([#2585](https://github.com/mapbox/mapbox-navigation-ios/pull/2585))
* Upgraded to [MapboxDirections v1.0.0-rc.1](https://github.com/mapbox/mapbox-directions-swift/releases/tag/v1.0.0-rc.1). ([#2585](https://github.com/mapbox/mapbox-navigation-ios/pull/2585))
* Upgraded to [MapboxSpeech v0.3.1](https://github.com/mapbox/mapbox-speech-swift/releases/tag/v0.3.1). ([#2543](https://github.com/mapbox/mapbox-navigation-ios/pull/2543))

### Map

* The `MGLStyle.navigationDayStyleURL` and `MGLStyle.navigationNightStyleURL` properties contain URLs to the Mapbox Navigation Day and Night v5 styles, both of which show traffic congestion lines on all roads by default. The traffic congestion layer is appropriate for a preview map; to tailor the style to turn-by-turn navigation, set `MGLMapView.showsTraffic` to `false`. ([#2523](https://github.com/mapbox/mapbox-navigation-ios/pull/2523))
* A portion of the route line now disappears behind the user puck as the user travels along the route during turn-by-turn navigation if `NavigationViewController.routeLineTracksTraversal` is set to `true`. ([#2377](https://github.com/mapbox/mapbox-navigation-ios/pull/2377))
* Traffic congestion segments along the route line and the estimated arrival time periodically update to reflect current conditions when using the `DirectionsProfileIdentifier.automobileAvoidingTraffic` profile. These updates correspond to the new `Notification.Name.routeControllerDidRefreshRoute` notification, `NavigationServiceDelegate.navigationService(_:didRefresh:)` method, and `NavigationViewControllerDelegate.navigationViewController(_:didRefresh:)` method. To disable these updates, set `RouteOptions.refreshingEnabled` to `false`. ([#2366](https://github.com/mapbox/mapbox-navigation-ios/pull/2366))
* A building at the destination waypoint can be extruded in 3D and highlighted for emphasis and recognizability. To enable building extrusion or highlighting, set the `NavigationViewController.waypointStyle` property. For a standalone map view that is not part of `NavigationViewController`, call the `NavigationMapView.highlightBuildings(at:in3D:)` method to highlight the destination building at a specific coordinate and `NavigationMapView.unhighlightBuildings()` to reverse this effect. ([#2535](https://github.com/mapbox/mapbox-navigation-ios/pull/2535))
* Replaced the `MGLStyle.navigationPreviewDayStyleURL` and `MGLStyle.navigationGuidanceDayStyleURL` properties with `MGLStyle.navigationDayStyleURL`, and replaced `MGLStyle.navigationPreviewNightStyleURL` and `MGLStyle.navigationGuidanceNightStyleURL` with `MGLStyle.navigationNightStyleURL`. ([#2523](https://github.com/mapbox/mapbox-navigation-ios/pull/2523))
* Replaced the `MGLStyle.navigationGuidanceDayStyleURL(version:)` and `MGLStyle.navigationGuidanceNightStyleURL(version:)` methods with `MGLStyle.navigationDayStyleURL(version:)` and `MGLStyle.navigationNightStyleURL(version:)` respectively, removed the `MGLStyle.navigationPreviewDayStyleURL(version:)` and `MGLStyle.navigationPreviewNightStyleURL(version:)` methods. ([#2567](https://github.com/mapbox/mapbox-navigation-ios/pull/2567))
Expand Down Expand Up @@ -53,6 +54,17 @@

* Improved the accuracy of location tracking and off-route detection. ([#2319](https://github.com/mapbox/mapbox-navigation-ios/pull/2319))
* Added the `PassiveLocationManager` class for use with the `MGLMapView.locationManager` property. Unlike `CLLocationManager`, this class causes the map view to display user locations snapped to the road network, just like during turn-by-turn navigation. To receive these locations without an `MGLMapView`, use the `PassiveLocationDataSource` class and implement the `PassiveLocationDataSourceDelegate.passiveLocationDataSource(_:didUpdateLocation:rawLocation:)` method or observe `Notification.Name.passiveLocationDataSourceDidUpdate` notifications. ([#2410](https://github.com/mapbox/mapbox-navigation-ios/pull/2410))
* The `NavigationViewController.route` and `NavigationService.route` properties are now read-only. To change the route that the user is traveling along, set the `NavigationViewController.indexedRoute` or `NavigationService.indexedRoute` property instead, pairing the route with the index of the route in the original `RouteResponse` object. ([#2366](https://github.com/mapbox/mapbox-navigation-ios/pull/2366))
* The following methods now require a route index to be passed in as an argument ([#2366](https://github.com/mapbox/mapbox-navigation-ios/pull/2366)):
* `NavigationViewController(for:routeIndex:routeOptions:navigationOptions:)`
* `NavigationViewController(route:routeIndex:routeOptions:navigationService:)`
* `CarPlayManagerDelegate.carPlayManager(_:navigationServiceAlong:routeIndex:routeOptions:desiredSimulationMode:)`
* `MapboxNavigationService(route:routeIndex:routeOptions:)`
* `MapboxNavigationService(route:routeIndex:routeOptions:directions:locationSource:eventsManagerType:simulating:routerType:)`
* `RouteProgress(route:routeIndex:options:legIndex:spokenInstructionIndex:)`
* `RouteProgress(route:routeIndex:options:legIndex:spokenInstructionIndex:)`
* `Router(along:routeIndex:options:directions:dataSource:)`
* `RouteController(along:routeIndex:options:directions:dataSource:)`
* Fixed an issue where location tracking would pause at the beginning of a route after setting `RouteOptions.shapeFormat` to `RouteShapeFormat.polyline` or `RouteShapeFormat.geoJSON`. Note that you most likely do not need to override the default value of `RouteShapeFormat.polyline6`: this is the least bandwidth-intensive format, and `Route.shape` and `RouteStep.shape` are set to `LineString`s regardless. ([#2319](https://github.com/mapbox/mapbox-navigation-ios/pull/2319))
* Fixed an issue where various delegate methods omitted `CLLocation.courseAccuracy` and `CLLocation.speedAccuracy` properties from passed-in `CLLocation` objects when using `RouteController`, even when these properties are provided by Core Location on iOS 13.4 and above. ([#2417](https://github.com/mapbox/mapbox-navigation-ios/pull/2417))
* Fixed issues where the user puck would sometimes drift away from the route line even though the user was following the route. ([#2412](https://github.com/mapbox/mapbox-navigation-ios/pull/2412), [#2417](https://github.com/mapbox/mapbox-navigation-ios/pull/2417))
Expand Down
2 changes: 1 addition & 1 deletion Cartfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ binary "https://www.mapbox.com/ios-sdk/MapboxAccounts.json" ~> 2.3.0
binary "https://api.mapbox.com/downloads/v2/carthage/mobile-navigation-native/MapboxNavigationNative.json" ~> 18.0.2
binary "https://api.mapbox.com/downloads/v2/carthage/mobile-maps/mapbox-ios-sdk-dynamic.json" == 6.1.0-beta.2
binary "https://api.mapbox.com/downloads/v2/carthage/mapbox-common/MapboxCommon-ios.json" == 4.0.0
github "mapbox/mapbox-directions-swift" ~> 0.33
github "mapbox/mapbox-directions-swift" == 1.0.0-rc.1
github "mapbox/turf-swift" ~> 0.5
github "mapbox/mapbox-events-ios" ~> 0.10
github "ceeK/Solar" ~> 2.1.0
Expand Down
4 changes: 2 additions & 2 deletions Cartfile.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ github "Udumft/SnappyShrimp" "66f3e3ba70370ad5e889ac8ed72a8730ca79958e"
github "ceeK/Solar" "2.1.0"
github "linksmt/OHHTTPStubs" "563f48d3fab84ef04639649c770b00f4fa502cca"
github "mapbox/MapboxGeocoder.swift" "v0.10.2"
github "mapbox/mapbox-directions-swift" "v0.33.2"
github "mapbox/mapbox-events-ios" "v0.10.2"
github "mapbox/mapbox-directions-swift" "v1.0.0-rc.1"
github "mapbox/mapbox-events-ios" "v0.10.3"
github "mapbox/mapbox-speech-swift" "v0.3.1"
github "mapbox/turf-swift" "v0.5.0"
github "raphaelmor/Polyline" "v4.2.1"
Expand Down
4 changes: 2 additions & 2 deletions Example/AppDelegate+CarPlay.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ extension AppDelegate: CPApplicationDelegate {

@available(iOS 12.0, *)
extension AppDelegate: CarPlayManagerDelegate {
func carPlayManager(_ carPlayManager: CarPlayManager, navigationServiceAlong route: Route, routeOptions: RouteOptions, desiredSimulationMode: SimulationMode) -> NavigationService {
func carPlayManager(_ carPlayManager: CarPlayManager, navigationServiceAlong route: Route, routeIndex: Int, routeOptions: RouteOptions, desiredSimulationMode: SimulationMode) -> NavigationService {

if let nvc = self.window?.rootViewController?.presentedViewController as? NavigationViewController, let service = nvc.navigationService {
//Do not set simulation mode if we already have an active navigation session.
return service
}
return MapboxNavigationService(route: route, routeOptions: routeOptions, simulating: desiredSimulationMode)
return MapboxNavigationService(route: route, routeIndex: routeIndex, routeOptions: routeOptions, simulating: desiredSimulationMode)
}

// MARK: CarPlayManagerDelegate
Expand Down
6 changes: 3 additions & 3 deletions Example/CustomViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class CustomViewController: UIViewController, MGLMapViewDelegate {
var navigationService: NavigationService!
var simulateLocation = false

var userRoute: Route?
var userIndexedRoute: IndexedRoute?

var userRouteOptions: RouteOptions?

Expand All @@ -36,8 +36,8 @@ class CustomViewController: UIViewController, MGLMapViewDelegate {
override func viewDidLoad() {
super.viewDidLoad()

let locationManager = simulateLocation ? SimulatedLocationManager(route: userRoute!) : NavigationLocationManager()
navigationService = MapboxNavigationService(route: userRoute!, routeOptions: userRouteOptions!, locationSource: locationManager, simulating: simulateLocation ? .always : .onPoorGPS)
let locationManager = simulateLocation ? SimulatedLocationManager(route: userIndexedRoute!.0) : NavigationLocationManager()
navigationService = MapboxNavigationService(route: userIndexedRoute!.0, routeIndex: userIndexedRoute!.1, routeOptions: userRouteOptions!, locationSource: locationManager, simulating: simulateLocation ? .always : .onPoorGPS)

mapView.delegate = self
mapView.compassView.isHidden = true
Expand Down
25 changes: 14 additions & 11 deletions Example/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,9 @@ class ViewController: UIViewController {
waypoints.insert(userWaypoint, at: 0)

let options = NavigationRouteOptions(waypoints: waypoints)

// Get periodic updates regarding changes in estimated arrival time and traffic congestion segments along the route line.
RouteControllerProactiveReroutingInterval = 30

requestRoute(with: options, success: defaultSuccess, failure: defaultFailure)
}
Expand All @@ -260,7 +263,7 @@ class ViewController: UIViewController {
func startBasicNavigation() {
guard let response = response, let route = response.routes?.first, case let .route(routeOptions) = response.options else { return }

let service = navigationService(route: route, options: routeOptions)
let service = navigationService(route: route, routeIndex: 0, options: routeOptions)
let navigationViewController = self.navigationViewController(navigationService: service)

// Render part of the route that has been traversed with full transparency, to give the illusion of a disappearing route.
Expand All @@ -279,8 +282,8 @@ class ViewController: UIViewController {
func startNavigation(styles: [Style]) {
guard let response = response, let route = response.routes?.first, case let .route(routeOptions) = response.options else { return }

let options = NavigationOptions(styles: styles, navigationService: navigationService(route: route, options: routeOptions))
let navigationViewController = NavigationViewController(for: route, routeOptions: routeOptions, navigationOptions: options)
let options = NavigationOptions(styles: styles, navigationService: navigationService(route: route, routeIndex: 0, options: routeOptions))
let navigationViewController = NavigationViewController(for: route, routeIndex: 0, routeOptions: routeOptions, navigationOptions: options)
navigationViewController.delegate = self

// Example of building highlighting in 2D.
Expand All @@ -292,7 +295,7 @@ class ViewController: UIViewController {
func navigationViewController(navigationService: NavigationService) -> NavigationViewController {
let options = NavigationOptions(navigationService: navigationService)

let navigationViewController = NavigationViewController(for: navigationService.route, routeOptions: navigationService.routeProgress.routeOptions, navigationOptions: options)
let navigationViewController = NavigationViewController(for: navigationService.route, routeIndex: navigationService.indexedRoute.1, routeOptions: navigationService.routeProgress.routeOptions, navigationOptions: options)
navigationViewController.delegate = self
navigationViewController.mapView?.delegate = self
return navigationViewController
Expand All @@ -313,7 +316,7 @@ class ViewController: UIViewController {

guard let customViewController = storyboard?.instantiateViewController(withIdentifier: "custom") as? CustomViewController else { return }

customViewController.userRoute = route
customViewController.userIndexedRoute = (route, 0)
customViewController.userRouteOptions = routeOptions

let destination = MGLPointAnnotation()
Expand All @@ -330,8 +333,8 @@ class ViewController: UIViewController {
guard let response = response, let route = response.routes?.first, case let .route(routeOptions) = response.options else { return }

let styles = [CustomDayStyle(), CustomNightStyle()]
let options = NavigationOptions(styles:styles, navigationService: navigationService(route: route, options: routeOptions))
let navigationViewController = NavigationViewController(for: route, routeOptions: routeOptions, navigationOptions: options)
let options = NavigationOptions(styles: styles, navigationService: navigationService(route: route, routeIndex: 0, options: routeOptions))
let navigationViewController = NavigationViewController(for: route, routeIndex: 0, routeOptions: routeOptions, navigationOptions: options)
navigationViewController.delegate = self

presentAndRemoveMapview(navigationViewController, completion: beginCarPlayNavigation)
Expand All @@ -344,17 +347,17 @@ class ViewController: UIViewController {
let instructionsCardCollection = InstructionsCardViewController()
instructionsCardCollection.cardCollectionDelegate = self

let options = NavigationOptions(navigationService: navigationService(route: route, options: routeOptions), topBanner: instructionsCardCollection)
let navigationViewController = NavigationViewController(for: route, routeOptions: routeOptions, navigationOptions: options)
let options = NavigationOptions(navigationService: navigationService(route: route, routeIndex: 0, options: routeOptions), topBanner: instructionsCardCollection)
let navigationViewController = NavigationViewController(for: route, routeIndex: 0, routeOptions: routeOptions, navigationOptions: options)
navigationViewController.delegate = self

presentAndRemoveMapview(navigationViewController, completion: beginCarPlayNavigation)
}

func navigationService(route: Route, options: RouteOptions) -> NavigationService {
func navigationService(route: Route, routeIndex: Int, options: RouteOptions) -> NavigationService {
let simulate = simulationButton.isSelected
let mode: SimulationMode = simulate ? .always : .onPoorGPS
return MapboxNavigationService(route: route, routeOptions: options, simulating: mode)
return MapboxNavigationService(route: route, routeIndex: routeIndex, routeOptions: options, simulating: mode)
}

func presentAndRemoveMapview(_ navigationViewController: NavigationViewController, completion: CompletionHandler?) {
Expand Down
2 changes: 1 addition & 1 deletion MapboxCoreNavigation.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Pod::Spec.new do |s|

s.dependency "MapboxNavigationNative", "~> 18.0.2"
s.dependency "MapboxAccounts", "~> 2.3.0"
s.dependency "MapboxDirections", "~> 0.33.2"
s.dependency "MapboxDirections", "~> 1.0.0-rc.1"
s.dependency "MapboxMobileEvents", "~> 0.10.2" # Always pin to a patch release if pre-1.0
s.dependency "Turf", "~> 0.5.0" # Always pin to a patch release if pre-1.0

Expand Down
9 changes: 9 additions & 0 deletions MapboxCoreNavigation/CoreConstants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ public var RouteControllerMinimumDurationRemainingForProactiveRerouting: TimeInt

/**
The number of seconds between attempts to automatically calculate a more optimal route while traveling.

In addition to calculating a more optimal route, `RouteController` also refreshes time-dependent statistics about the route, such as traffic congestion and the remaining duration, as long as `DirectionsOptions.profileIdentifier` is set to `DirectionsProfileIdentifier.automobileAvoidingTraffic` and `RouteOptions.refreshingEnabled` is set to `true`.
*/
public var RouteControllerProactiveReroutingInterval: TimeInterval = 120

Expand Down Expand Up @@ -130,6 +132,13 @@ public extension Notification.Name {
*/
static let routeControllerProgressDidChange: Notification.Name = .init(rawValue: "RouteControllerProgressDidChange")

/**
Posted when `RouteController` receives updated information about the current route.

The user info dictionary contains the key `RouteController.NotificationUserInfoKey.routeProgressKey`.
*/
static let routeControllerDidRefreshRoute: Notification.Name = .init(rawValue: "RouteControllerDidRefreshRoute")

/**
Posted after the user diverges from the expected route, just before `RouteController` attempts to calculate a new route.

Expand Down
Loading

0 comments on commit c945bcf

Please sign in to comment.