Skip to content

Commit 55e54cb

Browse files
authored
Tileset profile configuration (#3717)
* vk-1248-tiles-dataset: added setting profile identifier to tileset endpoint configuration; exposed properties for it's configuration; added Navigator property; unit test updated; CHANGELOG updated.
1 parent 8faa57e commit 55e54cb

9 files changed

+67
-38
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949
* Fixed an issue where changes made to `NavigationViewController.showsReportFeedback`, `NavigationViewController.showsSpeedLimits`, `NavigationViewController.detailedFeedbackEnabled`, `NavigationViewController.floatingButtonsPosition` and `NavigationViewController.floatingButtons` before `NavigationViewController` presentation were not saved. ([#3718](https://github.com/mapbox/mapbox-navigation-ios/pull/3718))
5050
* Fixed an issue where `SpeechSynthesizing.managesAudioSession` was ignored by `RouteVoiceController`. ([#3572](https://github.com/mapbox/mapbox-navigation-ios/pull/3572))
5151
* Location tracking and routing resources are now freed if no `RouteController` or `PassiveLocationManager` instance is actively being used. ([#3724](https://github.com/mapbox/mapbox-navigation-ios/pull/3724))
52+
* Added tileset profile configuration for Free Drive, Active Guidance, `MapboRoutingProvider` and Tileset Descriptors API. Now, `RouteOptions.profileIdentifier` is used to determine which type of tiles should be used for navigation. Please make sure to pay attention to `MapboxRoutingProfider` and `TilesetDescriptorFactory` arguments when configuring `ProfileIdentifier`. ([#3717](https://github.com/mapbox/mapbox-navigation-ios/pull/3717))
53+
* Added an optional `datasetProfileIdentifier` argument to the `MapboxRoutingProvider(_:settings:datasetProfileIdentifier:)`, `PassiveLocationManager(directions:systemLocationManager:eventsManagerType:userInfo:datasetProfileIdentifier:),` `TilesetDescriptorFactory.getSpecificVersion(version:completionQueue:datasetProfileIdentifier:completion:)`, and `TilesetDescriptorFactory.getLatest(completionQueue:datasetProfileIdentifier:completion:)` methods for obtaining routing tiles optimized for a particular mode of transportation. Make sure to configure `MapboxRoutingProvider` and `TilesetDescriptorFactory` with the correct dataset profile if you customize `Directions.profileIdentifier`. ([#3717](https://github.com/mapbox/mapbox-navigation-ios/pull/3717))
5254
* Fixed an issue where release builds would crash on invalid navigator initialization. ([#3738](https://github.com/mapbox/mapbox-navigation-ios/pull/3738))
5355

5456
## v2.2.0

Sources/MapboxCoreNavigation/CoreNavigationNavigator.swift

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,14 @@ class Navigator {
8080
// Used in tests to recreate the navigator
8181
static func _recreateNavigator() { _navigator = nil }
8282

83+
/**
84+
Profile setting, used for selecting tiles type for navigation.
85+
86+
This property can only be modified before creating `Navigator` shared instance, all
87+
further changes to this property will have no effect. Defaults to `automobile`.
88+
*/
89+
static var datasetProfileIdentifier: ProfileIdentifier = .automobile
90+
8391
/**
8492
Restrict direct initializer access.
8593
*/
@@ -88,7 +96,8 @@ class Navigator {
8896
let factory = NativeHandlersFactory(tileStorePath: tileStorePath ?? "",
8997
credentials: NavigationSettings.shared.directions.credentials,
9098
tilesVersion: Self.tilesVersion,
91-
historyDirectoryURL: Self.historyDirectoryURL)
99+
historyDirectoryURL: Self.historyDirectoryURL,
100+
datasetProfileIdentifier: Self.datasetProfileIdentifier)
92101
tileStore = factory.tileStore
93102
historyRecorder = factory.historyRecorder
94103
cacheHandle = factory.cacheHandle
@@ -114,7 +123,8 @@ class Navigator {
114123
credentials: NavigationSettings.shared.directions.credentials,
115124
tilesVersion: version ?? Self.tilesVersion,
116125
historyDirectoryURL: Self.historyDirectoryURL,
117-
targetVersion: version.map { _ in Self.tilesVersion })
126+
targetVersion: version.map { _ in Self.tilesVersion },
127+
datasetProfileIdentifier: Self.datasetProfileIdentifier)
118128
tileStore = factory.tileStore
119129
historyRecorder = factory.historyRecorder
120130
cacheHandle = factory.cacheHandle

Sources/MapboxCoreNavigation/HandlerFactory.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ protocol HandlerData {
88
var historyDirectoryURL: URL? { get }
99
var targetVersion: String? { get }
1010
var configFactoryType: ConfigFactory.Type { get }
11+
var datasetProfileIdentifier: ProfileIdentifier { get }
1112
}
1213

1314
extension NativeHandlersFactory: HandlerData { }
@@ -27,6 +28,7 @@ class HandlerFactory<HandlerType, Arguments> {
2728
let historyDirectoryURL: URL?
2829
let targetVersion: String?
2930
let configFactoryType: ConfigFactory.Type
31+
let datasetProfileIdentifier: ProfileIdentifier
3032

3133
init(data: HandlerData) {
3234
self.tileStorePath = data.tileStorePath
@@ -35,6 +37,7 @@ class HandlerFactory<HandlerType, Arguments> {
3537
self.historyDirectoryURL = data.historyDirectoryURL
3638
self.targetVersion = data.targetVersion
3739
self.configFactoryType = data.configFactoryType
40+
self.datasetProfileIdentifier = data.datasetProfileIdentifier
3841
}
3942

4043
static func != (lhs: CacheKey, rhs: HandlerData) -> Bool {
@@ -43,7 +46,8 @@ class HandlerFactory<HandlerType, Arguments> {
4346
lhs.tilesVersion != rhs.tilesVersion ||
4447
lhs.historyDirectoryURL?.absoluteString != rhs.historyDirectoryURL?.absoluteString ||
4548
lhs.targetVersion != rhs.targetVersion ||
46-
lhs.configFactoryType != rhs.configFactoryType
49+
lhs.configFactoryType != rhs.configFactoryType ||
50+
lhs.datasetProfileIdentifier != rhs.datasetProfileIdentifier
4751
}
4852
}
4953

Sources/MapboxCoreNavigation/MapboxRoutingProvider.swift

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,12 @@ public class MapboxRoutingProvider: RoutingProvider {
1818

1919
- parameter source: routing engine source to use.
2020
- parameter settings: settings object, used to get credentials and cache configuration.
21+
- parameter datasetProfileIdentifier: profile setting, used for selecting tiles type for navigation. If set to `nil` (default) - will detect the same profile as used for current navigation.
2122
*/
22-
public init(_ source: Source = .hybrid, settings: NavigationSettings = .shared) {
23+
public init(_ source: Source = .hybrid, settings: NavigationSettings = .shared, datasetProfileIdentifier: ProfileIdentifier? = nil) {
2324
self.source = source
2425
self.settings = settings
25-
26-
let factory = NativeHandlersFactory(tileStorePath: settings.tileStoreConfiguration.navigatorLocation.tileStoreURL?.path ?? "",
27-
credentials: settings.directions.credentials,
28-
tilesVersion: Navigator.tilesVersion,
29-
historyDirectoryURL: Navigator.historyDirectoryURL)
30-
self.router = RouterFactory.build(for: source.nativeSource,
31-
cache: factory.cacheHandle,
32-
config: factory.configHandle,
33-
historyRecorder: factory.historyRecorder)
26+
self.datasetProfileIdentifier = datasetProfileIdentifier
3427
}
3528

3629
// MARK: Configuration
@@ -77,6 +70,11 @@ public class MapboxRoutingProvider: RoutingProvider {
7770

7871
private let settings: NavigationSettings
7972

73+
/**
74+
Profile setting, used for selecting tiles type for navigation.
75+
*/
76+
public let datasetProfileIdentifier: ProfileIdentifier?
77+
8078
static var __testRoutesStub: ((_: RouteOptions, _: @escaping Directions.RouteCompletionHandler) -> Request?)? = nil
8179

8280
// MARK: Performing and Parsing Requests
@@ -119,7 +117,18 @@ public class MapboxRoutingProvider: RoutingProvider {
119117
public private(set) var activeRequests: [RequestId : Request] = [:]
120118

121119
private let requestsLock = NSLock()
122-
private let router: RouterInterfaceNative
120+
121+
private lazy var router: RouterInterfaceNative = {
122+
let factory = NativeHandlersFactory(tileStorePath: settings.tileStoreConfiguration.navigatorLocation.tileStoreURL?.path ?? "",
123+
credentials: settings.directions.credentials,
124+
tilesVersion: Navigator.tilesVersion,
125+
historyDirectoryURL: Navigator.historyDirectoryURL,
126+
datasetProfileIdentifier: datasetProfileIdentifier ?? Navigator.datasetProfileIdentifier)
127+
return RouterFactory.build(for: source.nativeSource,
128+
cache: factory.cacheHandle,
129+
config: factory.configHandle,
130+
historyRecorder: factory.historyRecorder)
131+
} ()
123132

124133
private func complete(requestId: RequestId, with result: @escaping () -> Void) {
125134
DispatchQueue.main.async { [self] in

Sources/MapboxCoreNavigation/NativeHandlersFactory.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,22 @@ class NativeHandlersFactory {
1919
let historyDirectoryURL: URL?
2020
let targetVersion: String?
2121
let configFactoryType: ConfigFactory.Type
22+
let datasetProfileIdentifier: ProfileIdentifier
2223

2324
init(tileStorePath: String,
2425
credentials: Credentials,
2526
tilesVersion: String = "",
2627
historyDirectoryURL: URL? = nil,
2728
targetVersion: String? = nil,
28-
configFactoryType: ConfigFactory.Type = ConfigFactory.self) {
29+
configFactoryType: ConfigFactory.Type = ConfigFactory.self,
30+
datasetProfileIdentifier: ProfileIdentifier = ProfileIdentifier.automobile) {
2931
self.tileStorePath = tileStorePath
3032
self.credentials = credentials
3133
self.tilesVersion = tilesVersion
3234
self.historyDirectoryURL = historyDirectoryURL
3335
self.targetVersion = targetVersion
3436
self.configFactoryType = configFactoryType
37+
self.datasetProfileIdentifier = datasetProfileIdentifier
3538
}
3639

3740
// MARK: - Native Handlers
@@ -79,7 +82,8 @@ class NativeHandlersFactory {
7982
TileEndpointConfiguration(credentials: credentials,
8083
tilesVersion: tilesVersion,
8184
minimumDaysToPersistVersion: nil,
82-
targetVersion: targetVersion)
85+
targetVersion: targetVersion,
86+
datasetProfileIdentifier: datasetProfileIdentifier)
8387
}()
8488

8589
lazy var tilesConfig: TilesConfig = {

Sources/MapboxCoreNavigation/PassiveLocationManager.swift

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,13 +255,19 @@ open class PassiveLocationManager: NSObject {
255255
- parameter systemLocationManager: The system location manager that provides raw locations for the receiver to match against the road network.
256256
- parameter eventsManagerType: An optional events manager type to use.
257257
- parameter userInfo: An optional metadata to be provided as initial value of `NavigationEventsManager.userInfo` property.
258+
- parameter datasetProfileIdentifier: custom profile setting, used for selecting tiles type for navigation. If set to `nil` - will not modify current profile setting.
258259

259260
- postcondition: Call `startUpdatingLocation()` afterwards to begin receiving location updates.
260261
*/
261262
public required init(directions: Directions = NavigationSettings.shared.directions,
262263
systemLocationManager: NavigationLocationManager? = nil,
263264
eventsManagerType: NavigationEventsManager.Type? = nil,
264-
userInfo: [String: String?]? = nil) {
265+
userInfo: [String: String?]? = nil,
266+
datasetProfileIdentifier: ProfileIdentifier? = nil) {
267+
if let datasetProfileIdentifier = datasetProfileIdentifier {
268+
Navigator.datasetProfileIdentifier = datasetProfileIdentifier
269+
}
270+
265271
self.directions = directions
266272

267273
self.systemLocationManager = systemLocationManager ?? NavigationLocationManager()
@@ -371,15 +377,16 @@ extension TileEndpointConfiguration {
371377
- parameter tilesVersion: Routing tile version.
372378
- parameter minimumDaysToPersistVersion: The minimum age in days that a tile version much reach before a new version can be requested from the tile endpoint.
373379
- parameter targetVersion: Routing tile version, which navigator would like to eventually switch to if it becomes available
380+
- parameter datasetProfileIdentifier: profile setting, used for selecting tiles type for navigation.
374381
*/
375-
convenience init(credentials: Credentials, tilesVersion: String, minimumDaysToPersistVersion: Int?, targetVersion: String?) {
382+
convenience init(credentials: Credentials, tilesVersion: String, minimumDaysToPersistVersion: Int?, targetVersion: String?, datasetProfileIdentifier: ProfileIdentifier) {
376383
let host = credentials.host.absoluteString
377384
guard let accessToken = credentials.accessToken, !accessToken.isEmpty else {
378385
preconditionFailure("No access token specified in Info.plist")
379386
}
380-
387+
381388
self.init(host: host,
382-
dataset: "mapbox/driving",
389+
dataset: datasetProfileIdentifier.rawValue,
383390
version: tilesVersion,
384391
token: accessToken,
385392
userAgent: URLSession.userAgent,

Sources/MapboxCoreNavigation/RouteController.swift

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -526,21 +526,6 @@ open class RouteController: NSObject {
526526
}
527527
}
528528

529-
func mode(_ profileIdentifier: ProfileIdentifier) -> ActiveGuidanceMode {
530-
switch profileIdentifier {
531-
case .automobile:
532-
return .driving
533-
case .automobileAvoidingTraffic:
534-
return .driving
535-
case .cycling:
536-
return .cycling
537-
case .walking:
538-
return .walking
539-
default:
540-
return .driving
541-
}
542-
}
543-
544529
// MARK: Handling Lifecycle
545530

546531
@available(*, deprecated, renamed: "init(alongRouteAtIndex:in:options:routingProvider:dataSource:)")
@@ -564,6 +549,8 @@ open class RouteController: NSObject {
564549
os_log("[BUG] Two simultaneous active navigation sessions. This might happen if there are two NavigationViewController or RouteController instances exists at the same time. Profile the app and make sure that NavigationViewController and RouteController is deallocated once not in use.", log: Self.log, type: .fault)
565550
}
566551

552+
Navigator.datasetProfileIdentifier = options.profileIdentifier
553+
567554
self.routingProvider = routingProvider
568555
self.indexedRouteResponse = .init(routeResponse: routeResponse, routeIndex: routeIndex)
569556
self.routeProgress = RouteProgress(route: routeResponse.routes![routeIndex], options: options)

Sources/MapboxCoreNavigation/TilesetDescriptorFactory.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,16 @@ extension TilesetDescriptorFactory {
99
- Parameters:
1010
- version: TilesetDescriptor version.
1111
- completionQueue: A DispatchQueue on which the completion will be called.
12+
- datasetProfileIdentifier: Profile setting, used for selecting tiles type for navigation.
1213
- completion: A completion that will be used to pass the tileset descriptor.
1314
*/
1415
public class func getSpecificVersion(version: String,
1516
completionQueue: DispatchQueue = .main,
17+
datasetProfileIdentifier: ProfileIdentifier = .automobile,
1618
completion: @escaping (TilesetDescriptor) -> Void) {
1719
let factory = NativeHandlersFactory(tileStorePath: NavigationSettings.shared.tileStoreConfiguration.navigatorLocation.tileStoreURL?.path ?? "",
18-
credentials: NavigationSettings.shared.directions.credentials)
20+
credentials: NavigationSettings.shared.directions.credentials,
21+
datasetProfileIdentifier: datasetProfileIdentifier)
1922
completionQueue.async {
2023
completion(getSpecificVersion(forCache: factory.cacheHandle, version: version))
2124
}
@@ -28,12 +31,15 @@ extension TilesetDescriptorFactory {
2831

2932
- Parameters:
3033
- completionQueue: A DispatchQueue on which the completion will be called.
34+
- datasetProfileIdentifier: Profile setting, used for selecting tiles type for navigation.
3135
- completion: A completion that will be used to pass the latest tileset descriptor.
3236
*/
3337
public class func getLatest(completionQueue: DispatchQueue = .main,
38+
datasetProfileIdentifier: ProfileIdentifier = .automobile,
3439
completion: @escaping (_ latestTilesetDescriptor: TilesetDescriptor) -> Void) {
3540
let factory = NativeHandlersFactory(tileStorePath: NavigationSettings.shared.tileStoreConfiguration.navigatorLocation.tileStoreURL?.path ?? "",
36-
credentials: NavigationSettings.shared.directions.credentials)
41+
credentials: NavigationSettings.shared.directions.credentials,
42+
datasetProfileIdentifier: datasetProfileIdentifier)
3743
completionQueue.async {
3844
completion(getLatestForCache(factory.cacheHandle))
3945
}

Tests/MapboxCoreNavigationTests/TilesetDescriptorFactoryTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ final class TilesetDescriptorFactoryTests: TestCase {
1818
let navigator = Navigator.shared
1919

2020
let tilesetReceived = expectation(description: "Tileset received")
21-
TilesetDescriptorFactory.getLatest(completionQueue: .global()) { latestTilesetDescriptor in
21+
TilesetDescriptorFactory.getLatest(completionQueue: .global(), datasetProfileIdentifier: MapboxCoreNavigation.Navigator.datasetProfileIdentifier) { latestTilesetDescriptor in
2222
tilesetReceived.fulfill()
2323
XCTAssertEqual(latestTilesetDescriptor,
2424
TilesetDescriptorFactory.getLatestForCache(Navigator.shared.cacheHandle))

0 commit comments

Comments
 (0)