Skip to content

Commit d1529f6

Browse files
authored
Reroute Controller integration (#3754)
* vk-1324-reroute-controller: added RerouteController; wired up it's usage through RouteController introducing `customRoutingProvider`; piped settings usage; CHANGELOG entry added; Unit tests updated; deprecated corresponding properties and initializers
1 parent 15474b2 commit d1529f6

35 files changed

+520
-147
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@
2525

2626
* Added the `CarPlayManagerDelegate.carPlayManager(_:shouldUpdateNotificationFor:with:in:)` and `CarPlayManagerDelegate.carPlayManager(_:shouldShowNotificationFor:in:)` to provide the ability to control notifications presentation while CarPlay application is in the background. ([#3828](https://github.com/mapbox/mapbox-navigation-ios/pull/3828))
2727

28+
### Routing
29+
30+
* Integrated MaboxNavigtionNative rerouting mechanism. `Router.routingProvider` is replaced with optional `customRoutingProvider` which is used as customization for reroutng mechanism. Default `nil` value corresponds to SDK's default rerouting mechanism to be used. If you don't want custom reroute requests, update your `NavigationService` and `Router` instances instantiation to use the default `nil` value. ([#3754](https://github.com/mapbox/mapbox-navigation-ios/pull/3754))
31+
* Exposed configurations for rerouting aspects like controlling usage of online vs. offline data for route building using desired `RoutingProviderSource` in `NavigationSettings.initialize(directions:tileStoreConfiguration:routingProviderSource:)` method, and `Router.initialManeuverAvoidanceRadius` to configure radius before first dangerous maneuver. ([#3754](https://github.com/mapbox/mapbox-navigation-ios/pull/3754))
32+
2833
### Other changes
2934

3035
* Added the `NavigationViewControllerDelegate.navigationViewController(_:, didSubmitArrivalFeedback:)` method which is called to notify that the user submitted the end of route feedback. Implementation of this method receives an `EndOfRouteFeedback` object with user's rating and comment. ([#3842](https://github.com/mapbox/mapbox-navigation-ios/pull/3842))

Example/AppDelegate+CarPlay.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ extension AppDelegate: CarPlayManagerDelegate {
8484
return MapboxNavigationService(routeResponse: routeResponse,
8585
routeIndex: routeIndex,
8686
routeOptions: routeOptions,
87-
routingProvider: MapboxRoutingProvider(.hybrid),
87+
customRoutingProvider: nil,
8888
credentials: NavigationSettings.shared.directions.credentials,
8989
simulating: desiredSimulationMode)
9090
}

Example/AppDelegate.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
1111
var window: UIWindow?
1212

1313
@available(iOS 12.0, *)
14-
lazy var carPlayManager: CarPlayManager = CarPlayManager(routingProvider: MapboxRoutingProvider(.hybrid))
14+
lazy var carPlayManager: CarPlayManager = CarPlayManager(customRoutingProvider: MapboxRoutingProvider(.hybrid))
1515

1616
@available(iOS 12.0, *)
1717
lazy var carPlaySearchController: CarPlaySearchController = CarPlaySearchController()

Example/CustomViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class CustomViewController: UIViewController {
4848
navigationService = MapboxNavigationService(routeResponse: indexedUserRouteResponse!.routeResponse,
4949
routeIndex: indexedUserRouteResponse!.routeIndex,
5050
routeOptions: userRouteOptions!,
51-
routingProvider: MapboxRoutingProvider(.hybrid),
51+
customRoutingProvider: nil,
5252
credentials: NavigationSettings.shared.directions.credentials,
5353
locationSource: locationManager,
5454
simulating: simulateLocation ? .always : .inTunnels)

Example/ViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ class ViewController: UIViewController {
601601
return MapboxNavigationService(routeResponse: response,
602602
routeIndex: routeIndex,
603603
routeOptions: options,
604-
routingProvider: MapboxRoutingProvider(.hybrid),
604+
customRoutingProvider: nil,
605605
credentials: NavigationSettings.shared.directions.credentials,
606606
simulating: mode)
607607
}

MapboxNavigation.xcodeproj/project.pbxproj

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
2B01E4B7274671550002A5F7 /* RoutingProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2B01E4B4274671540002A5F7 /* RoutingProvider.swift */; };
3939
2B01E4B8274671550002A5F7 /* Directions+RoutingProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2B01E4B5274671550002A5F7 /* Directions+RoutingProvider.swift */; };
4040
2B07444124B4832400615E87 /* TokenTestViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2B07444024B4832400615E87 /* TokenTestViewController.swift */; };
41+
2B28E22127EB48C60029E4C1 /* RerouteControllerDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2B28E22027EB48C60029E4C1 /* RerouteControllerDelegate.swift */; };
4142
2B3ED38C2609FA7900861A84 /* ArrivalController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2B3ED38B2609FA7900861A84 /* ArrivalController.swift */; };
4243
2B3ED3962609FB2300861A84 /* CameraController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2B3ED3952609FB2300861A84 /* CameraController.swift */; };
4344
2B3ED3B4260A162900861A84 /* NavigationViewData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2B3ED3B3260A162900861A84 /* NavigationViewData.swift */; };
@@ -68,6 +69,7 @@
6869
2BE7013D25359C7B00F46E4E /* RouteAlert.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2BE7013C25359C7B00F46E4E /* RouteAlert.swift */; };
6970
2BE7016925371E3400F46E4E /* Incident.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2BE7016825371E3400F46E4E /* Incident.swift */; };
7071
2BE70189253734A000F46E4E /* TollCollection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2BE7012C2535946300F46E4E /* TollCollection.swift */; };
72+
2BEA240A27D205B500EE05D9 /* RerouteController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2BEA240827D205B500EE05D9 /* RerouteController.swift */; };
7173
2BEF16472775C8FD0085E3C6 /* MapMatchingResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2BEF16462775C8FD0085E3C6 /* MapMatchingResult.swift */; };
7274
2BF398C1274BDEA8000C9A72 /* Directions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2BF398C0274BDEA8000C9A72 /* Directions.swift */; };
7375
2BF398C3274FE99A000C9A72 /* HandlerFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2BF398C2274FE99A000C9A72 /* HandlerFactory.swift */; };
@@ -591,6 +593,7 @@
591593
2B01E4B4274671540002A5F7 /* RoutingProvider.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RoutingProvider.swift; sourceTree = "<group>"; };
592594
2B01E4B5274671550002A5F7 /* Directions+RoutingProvider.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Directions+RoutingProvider.swift"; sourceTree = "<group>"; };
593595
2B07444024B4832400615E87 /* TokenTestViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TokenTestViewController.swift; sourceTree = "<group>"; };
596+
2B28E22027EB48C60029E4C1 /* RerouteControllerDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RerouteControllerDelegate.swift; sourceTree = "<group>"; };
594597
2B3ED38B2609FA7900861A84 /* ArrivalController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ArrivalController.swift; sourceTree = "<group>"; };
595598
2B3ED3952609FB2300861A84 /* CameraController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CameraController.swift; sourceTree = "<group>"; };
596599
2B3ED3B3260A162900861A84 /* NavigationViewData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationViewData.swift; sourceTree = "<group>"; };
@@ -621,6 +624,7 @@
621624
2BE701342535948100F46E4E /* RestStop.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RestStop.swift; sourceTree = "<group>"; };
622625
2BE7013C25359C7B00F46E4E /* RouteAlert.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RouteAlert.swift; sourceTree = "<group>"; };
623626
2BE7016825371E3400F46E4E /* Incident.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Incident.swift; sourceTree = "<group>"; };
627+
2BEA240827D205B500EE05D9 /* RerouteController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RerouteController.swift; sourceTree = "<group>"; };
624628
2BEF16462775C8FD0085E3C6 /* MapMatchingResult.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MapMatchingResult.swift; sourceTree = "<group>"; };
625629
2BF398C0274BDEA8000C9A72 /* Directions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Directions.swift; sourceTree = "<group>"; };
626630
2BF398C2274FE99A000C9A72 /* HandlerFactory.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HandlerFactory.swift; sourceTree = "<group>"; };
@@ -1998,8 +2002,8 @@
19982002
3582A24F20EEC46B0029C5DE /* Router.swift */,
19992003
353E69031EF0C4E5007B2AE5 /* SimulatedLocationManager.swift */,
20002004
35C98730212E02B500808B82 /* RouteController.swift */,
2001-
2B5A4ABF2807124800170A2B /* RerouteController.swift */,
2002-
2B5A4AC02807124800170A2B /* RerouteControllerDelegate.swift */,
2005+
2BEA240827D205B500EE05D9 /* RerouteController.swift */,
2006+
2B28E22027EB48C60029E4C1 /* RerouteControllerDelegate.swift */,
20032007
5A39B9272498F9890026DFD1 /* PassiveLocationManager.swift */,
20042008
8A3A218F25EEC00200EDA999 /* CoreNavigationNavigator.swift */,
20052009
E2805A5726CB994500165DB9 /* NSLock+MapboxInternal.swift */,
@@ -2922,7 +2926,7 @@
29222926
3A163AE3249901D000D66A0D /* FixLocation.swift in Sources */,
29232927
2E50E0D2264E468B009D3848 /* RoadObjectMatcherError.swift in Sources */,
29242928
8D2AA745211CDD4000EB7F72 /* NavigationService.swift in Sources */,
2925-
2B5A4AC12807124900170A2B /* RerouteController.swift in Sources */,
2929+
2BEA240A27D205B500EE05D9 /* RerouteController.swift in Sources */,
29262930
2B01E4B8274671550002A5F7 /* Directions+RoutingProvider.swift in Sources */,
29272931
2B7ACA9C25E3F84700B0ACFD /* PredictiveCacheOptions.swift in Sources */,
29282932
35A5413B1EFC052700E49846 /* RouteOptions.swift in Sources */,
@@ -2944,7 +2948,7 @@
29442948
2BBED93B267A3AB900F90032 /* BillingHandler.swift in Sources */,
29452949
2BE701352535948100F46E4E /* RestStop.swift in Sources */,
29462950
2B01E4B6274671550002A5F7 /* MapboxRoutingProvider.swift in Sources */,
2947-
2B5A4AC22807124900170A2B /* RerouteControllerDelegate.swift in Sources */,
2951+
2B28E22127EB48C60029E4C1 /* RerouteControllerDelegate.swift in Sources */,
29482952
8D4CF9C621349FFB009C3FEE /* NavigationServiceDelegate.swift in Sources */,
29492953
2BF398C3274FE99A000C9A72 /* HandlerFactory.swift in Sources */,
29502954
118D883626F8CA0700B2ED7B /* ActiveNavigationFeedbackType.swift in Sources */,

Sources/MapboxCoreNavigation/CoreNavigationNavigator.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ class Navigator {
122122
tilesVersion: Self.tilesVersion,
123123
historyDirectoryURL: Self.historyDirectoryURL,
124124
datasetProfileIdentifier: Self.datasetProfileIdentifier,
125-
navigatorRouterType: NavigationSettings.shared.routingProviderSource.nativeSource)
125+
routingProviderSource: NavigationSettings.shared.routingProviderSource.nativeSource)
126126
tileStore = factory.tileStore
127127
historyRecorder = factory.historyRecorder
128128
cacheHandle = factory.cacheHandle
@@ -151,7 +151,7 @@ class Navigator {
151151
historyDirectoryURL: Self.historyDirectoryURL,
152152
targetVersion: version.map { _ in Self.tilesVersion },
153153
datasetProfileIdentifier: Self.datasetProfileIdentifier,
154-
navigatorRouterType: NavigationSettings.shared.routingProviderSource.nativeSource)
154+
routingProviderSource: NavigationSettings.shared.routingProviderSource.nativeSource)
155155
tileStore = factory.tileStore
156156
historyRecorder = factory.historyRecorder
157157
cacheHandle = factory.cacheHandle

Sources/MapboxCoreNavigation/LegacyRouteController.swift

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,23 @@ open class LegacyRouteController: NSObject, Router, InternalRouter, CLLocationMa
2020
/**
2121
A reference to a MapboxDirections service. Used for rerouting.
2222
*/
23-
@available(*, deprecated, message: "Use `routingProvider` instead. If route controller was not initialized using `Directions` object - this property is unused and ignored.")
23+
@available(*, deprecated, message: "Use `customRoutingProvider` instead. If route controller was not initialized using `Directions` object - this property is unused and ignored.")
2424
public lazy var directions: Directions = routingProvider as? Directions ?? Directions.shared
2525

2626
/**
27-
Routing provider used to create the route.
27+
`RoutingProvider`, used to create a route during refreshing or rerouting.
2828
*/
29-
public var routingProvider: RoutingProvider
29+
@available(*, deprecated, message: "Use `customRoutingProvider` instead. This property will be equal to `customRoutingProvider` if that is provided or a `MapboxRoutingProvider` instance otherwise.")
30+
public lazy var routingProvider: RoutingProvider = customRoutingProvider ?? MapboxRoutingProvider(NavigationSettings.shared.routingProviderSource)
31+
/**
32+
Custom `RoutingProvider`, used to create a route during refreshing or rerouting.
33+
*/
34+
public var customRoutingProvider: RoutingProvider? = nil
3035

36+
var resolvedRoutingProvider: RoutingProvider {
37+
customRoutingProvider ?? routingProvider
38+
}
39+
3140
public var route: Route {
3241
routeProgress.route
3342
}
@@ -100,6 +109,8 @@ open class LegacyRouteController: NSObject, Router, InternalRouter, CLLocationMa
100109

101110
var lastRerouteLocation: CLLocation?
102111

112+
public var initialManeuverAvoidanceRadius: TimeInterval = RerouteController.DefaultManeuverAvoidanceRadius
113+
103114
public var refreshesRoute: Bool = true
104115

105116
var lastRouteRefresh: Date?
@@ -201,7 +212,7 @@ open class LegacyRouteController: NSObject, Router, InternalRouter, CLLocationMa
201212
return false
202213
}
203214

204-
@available(*, deprecated, renamed: "init(alongRouteAtIndex:routeIndex:in:options:routingProvider:dataSource:)")
215+
@available(*, deprecated, renamed: "init(alongRouteAtIndex:routeIndex:in:options:customRoutingProvider:dataSource:)")
205216
public convenience init(alongRouteAtIndex routeIndex: Int,
206217
in routeResponse: RouteResponse,
207218
options: RouteOptions,
@@ -214,12 +225,25 @@ open class LegacyRouteController: NSObject, Router, InternalRouter, CLLocationMa
214225
dataSource: source)
215226
}
216227

228+
@available(*, deprecated, renamed: "init(alongRouteAtIndex:routeIndex:in:options:customRoutingProvider:dataSource:)")
229+
required public convenience init(alongRouteAtIndex routeIndex: Int,
230+
in routeResponse: RouteResponse,
231+
options: RouteOptions,
232+
routingProvider: RoutingProvider = Directions.shared,
233+
dataSource source: RouterDataSource) {
234+
self.init(alongRouteAtIndex:routeIndex,
235+
in: routeResponse,
236+
options: options,
237+
routingProvider: routingProvider,
238+
dataSource: source)
239+
}
240+
217241
required public init(alongRouteAtIndex routeIndex: Int,
218242
in routeResponse: RouteResponse,
219243
options: RouteOptions,
220-
routingProvider: RoutingProvider = Directions.shared,
244+
customRoutingProvider: RoutingProvider? = nil,
221245
dataSource source: RouterDataSource) {
222-
self.routingProvider = routingProvider
246+
self.customRoutingProvider = customRoutingProvider
223247
self.indexedRouteResponse = .init(routeResponse: routeResponse, routeIndex: routeIndex)
224248
self.routeProgress = RouteProgress(route: routeResponse.routes![routeIndex], options: options)
225249
self.dataSource = source

Sources/MapboxCoreNavigation/MapboxRoutingProvider.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public class MapboxRoutingProvider: RoutingProvider {
124124
tilesVersion: Navigator.tilesVersion,
125125
historyDirectoryURL: Navigator.historyDirectoryURL,
126126
datasetProfileIdentifier: datasetProfileIdentifier ?? Navigator.datasetProfileIdentifier,
127-
navigatorRouterType: source.nativeSource)
127+
routingProviderSource: source.nativeSource)
128128
return RouterFactory.build(for: source.nativeSource,
129129
cache: factory.cacheHandle,
130130
config: factory.configHandle,

Sources/MapboxCoreNavigation/NativeHandlersFactory.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class NativeHandlersFactory {
2121
let targetVersion: String?
2222
let configFactoryType: ConfigFactory.Type
2323
let datasetProfileIdentifier: ProfileIdentifier
24-
let navigatorRouterType: MapboxNavigationNative.RouterType?
24+
let routingProviderSource: MapboxNavigationNative.RouterType?
2525

2626
init(tileStorePath: String,
2727
credentials: Credentials,
@@ -30,15 +30,15 @@ class NativeHandlersFactory {
3030
targetVersion: String? = nil,
3131
configFactoryType: ConfigFactory.Type = ConfigFactory.self,
3232
datasetProfileIdentifier: ProfileIdentifier = ProfileIdentifier.automobile,
33-
navigatorRouterType: MapboxNavigationNative.RouterType? = nil) {
33+
routingProviderSource: MapboxNavigationNative.RouterType? = nil) {
3434
self.tileStorePath = tileStorePath
3535
self.credentials = credentials
3636
self.tilesVersion = tilesVersion
3737
self.historyDirectoryURL = historyDirectoryURL
3838
self.targetVersion = targetVersion
3939
self.configFactoryType = configFactoryType
4040
self.datasetProfileIdentifier = datasetProfileIdentifier
41-
self.navigatorRouterType = navigatorRouterType
41+
self.routingProviderSource = routingProviderSource
4242
}
4343

4444
// MARK: - Native Handlers
@@ -55,7 +55,7 @@ class NativeHandlersFactory {
5555
onMainQueueSync { // Make sure that Navigator pick ups Main Thread RunLoop.
5656
LogConfiguration.getInstance().setFilterLevelFor(LoggingLevel.info)
5757

58-
let router = navigatorRouterType.map {
58+
let router = routingProviderSource.map {
5959
MapboxNavigationNative.RouterFactory.build(for: $0,
6060
cache: cacheHandle,
6161
config: configHandle,

0 commit comments

Comments
 (0)