Skip to content

Commit

Permalink
vk-2926-tilestore-config: replaced TileStoreLocation with TileStoreCo…
Browse files Browse the repository at this point in the history
…nfiguration. Added code docs. Added config for PassiveLocationDataSource.
  • Loading branch information
Udumft committed May 3, 2021
1 parent f20ff7e commit b5a0dc5
Show file tree
Hide file tree
Showing 12 changed files with 115 additions and 90 deletions.
8 changes: 4 additions & 4 deletions MapboxNavigation.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
2B8098412411375700FED452 /* SpeechSynthesizing.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2B8098402411375700FED452 /* SpeechSynthesizing.swift */; };
2B8098432411447E00FED452 /* MultiplexedSpeechSynthesizer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2B8098422411447E00FED452 /* MultiplexedSpeechSynthesizer.swift */; };
2B81EC28241A237E00145086 /* SpeechSynthesizersControllerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2B81EC27241A237E00145086 /* SpeechSynthesizersControllerTests.swift */; };
2B871272263966F0001082A9 /* TileStoreLocation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2B8712682639631C001082A9 /* TileStoreLocation.swift */; };
2B871272263966F0001082A9 /* TileStoreConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2B8712682639631C001082A9 /* TileStoreConfiguration.swift */; };
2B91C9B12416357700E532A5 /* MapboxSpeechSynthesizer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2B91C9B02416357700E532A5 /* MapboxSpeechSynthesizer.swift */; };
2B955B1C25EFDDCB00BBFEC6 /* Directions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2B955B1B25EFDDCB00BBFEC6 /* Directions.swift */; };
2BBEEDA52508DB1700C8DA4A /* RouteLegProgress.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2BBEEDA42508DB1700C8DA4A /* RouteLegProgress.swift */; };
Expand Down Expand Up @@ -544,7 +544,7 @@
2B8098402411375700FED452 /* SpeechSynthesizing.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SpeechSynthesizing.swift; sourceTree = "<group>"; };
2B8098422411447E00FED452 /* MultiplexedSpeechSynthesizer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MultiplexedSpeechSynthesizer.swift; sourceTree = "<group>"; };
2B81EC27241A237E00145086 /* SpeechSynthesizersControllerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SpeechSynthesizersControllerTests.swift; sourceTree = "<group>"; };
2B8712682639631C001082A9 /* TileStoreLocation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TileStoreLocation.swift; sourceTree = "<group>"; };
2B8712682639631C001082A9 /* TileStoreConfiguration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TileStoreConfiguration.swift; sourceTree = "<group>"; };
2B91C9B02416357700E532A5 /* MapboxSpeechSynthesizer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MapboxSpeechSynthesizer.swift; sourceTree = "<group>"; };
2B955B1B25EFDDCB00BBFEC6 /* Directions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Directions.swift; sourceTree = "<group>"; };
2BBEEDA42508DB1700C8DA4A /* RouteLegProgress.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RouteLegProgress.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1806,7 +1806,7 @@
8D4CF9C521349FFB009C3FEE /* NavigationServiceDelegate.swift */,
4303A3982332CD6200B5737D /* UnimplementedLogging.swift */,
8D1A5CD1212DDFCD0059BA4A /* DispatchTimer.swift */,
2B8712682639631C001082A9 /* TileStoreLocation.swift */,
2B8712682639631C001082A9 /* TileStoreConfiguration.swift */,
8D75F990212B5C7F00F99CF3 /* TunnelAuthority.swift */,
2B7ACA9A25E3F84600B0ACFD /* PredictiveCacheOptions.swift */,
2B7ACA9925E3F84600B0ACFD /* PredictiveCacheManager.swift */,
Expand Down Expand Up @@ -2779,7 +2779,7 @@
8D75F991212B5C7F00F99CF3 /* TunnelAuthority.swift in Sources */,
C5E7A31C1F4F6828001CB015 /* NavigationRouteOptions.swift in Sources */,
352F464D20EB74C200147886 /* NavigationEventsManager.swift in Sources */,
2B871272263966F0001082A9 /* TileStoreLocation.swift in Sources */,
2B871272263966F0001082A9 /* TileStoreConfiguration.swift in Sources */,
351174F41EF1C0530065E248 /* ReplayLocationManager.swift in Sources */,
2BE701172535940D00F46E4E /* Tunnel.swift in Sources */,
8A3A219025EEC00200EDA999 /* CoreNavigationNavigator.swift in Sources */,
Expand Down
2 changes: 1 addition & 1 deletion Sources/MapboxCoreNavigation/LegacyRouteController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ open class LegacyRouteController: NSObject, Router, InternalRouter, CLLocationMa

var userSnapToStepDistanceFromManeuver: CLLocationDistance?

required public init(along route: Route, routeIndex: Int, options: RouteOptions, directions: Directions = Directions.shared, dataSource source: RouterDataSource, tileStoreLocation: TileStoreLocation.Strict = .default) {
required public init(along route: Route, routeIndex: Int, options: RouteOptions, directions: Directions = Directions.shared, dataSource source: RouterDataSource, tileStoreLocation: TileStoreConfiguration.Location = .default) {
self.directions = directions
self._routeProgress = RouteProgress(route: route, routeIndex: routeIndex, options: options)
self.dataSource = source
Expand Down
3 changes: 2 additions & 1 deletion Sources/MapboxCoreNavigation/NavigationService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ public class MapboxNavigationService: NSObject, NavigationService {
- parameter eventsManagerType: An optional events manager type to use while tracking the route.
- parameter simulationMode: The simulation mode desired.
- parameter routerType: An optional router type to use for traversing the route.
- parameter tileStoreLocation: Configuration of `TileStore` location, where Navigation tiles are stored.
*/
required public init(route: Route,
routeIndex: Int,
Expand All @@ -235,7 +236,7 @@ public class MapboxNavigationService: NSObject, NavigationService {
eventsManagerType: NavigationEventsManager.Type? = nil,
simulating simulationMode: SimulationMode = .onPoorGPS,
routerType: Router.Type? = nil,
tileStoreLocation: TileStoreLocation.Strict = .default) {
tileStoreLocation: TileStoreConfiguration.Location = .default) {
nativeLocationSource = locationSource ?? NavigationLocationManager()
self.directions = directions ?? Directions.shared
self.simulationMode = simulationMode
Expand Down
5 changes: 3 additions & 2 deletions Sources/MapboxCoreNavigation/PassiveLocationDataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ open class PassiveLocationDataSource: NSObject {
- parameter directions: The directions service that allows the location data source to access road network data. If this argument is omitted, the shared `Directions` object is used.
- parameter systemLocationManager: The location manager that provides raw locations for the receiver to match against the road network.
- parameter tileStoreLocation: Configuration of `TileStore` location, where Navigation tiles are stored.
- postcondition: Call `startUpdatingLocation()` afterwards to begin receiving location updates.
*/
public required init(directions: Directions = Directions.shared, systemLocationManager: NavigationLocationManager? = nil, tileStoreURL: URL? = nil) {
public required init(directions: Directions = Directions.shared, systemLocationManager: NavigationLocationManager? = nil, tileStoreLocation: TileStoreConfiguration.Location = .default) {
self.directions = directions
Navigator.credentials = directions.credentials
Navigator.tilesURL = tileStoreURL
Navigator.tilesURL = tileStoreLocation.rawValue

self.systemLocationManager = systemLocationManager ?? NavigationLocationManager()

Expand Down
4 changes: 2 additions & 2 deletions Sources/MapboxCoreNavigation/RouteController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,10 @@ open class RouteController: NSObject {
return snappedLocation ?? rawLocation
}

required public init(along route: Route, routeIndex: Int, options: RouteOptions, directions: Directions = Directions.shared, dataSource source: RouterDataSource, tileStoreLocation: TileStoreLocation.Strict = .default) {
required public init(along route: Route, routeIndex: Int, options: RouteOptions, directions: Directions = Directions.shared, dataSource source: RouterDataSource, tileStoreLocation: TileStoreConfiguration.Location = .default) {
self.directions = directions
Navigator.credentials = directions.credentials
Navigator.tilesURL = tileStoreLocation.tilStoreURL
Navigator.tilesURL = tileStoreLocation.rawValue
self._routeProgress = RouteProgress(route: route, routeIndex: routeIndex, options: options)
self.dataSource = source
self.refreshesRoute = options.profileIdentifier == .automobileAvoidingTraffic && options.refreshingEnabled
Expand Down
4 changes: 2 additions & 2 deletions Sources/MapboxCoreNavigation/Router.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ public protocol Router: class, CLLocationManagerDelegate {
- parameter routeIndex: The index of the route within the original `RouteResponse` object.
- parameter directions: The Directions object that created `route`.
- parameter source: The data source for the RouteController.
- parameter tileStoreURL: A local path to tile storage location. `nil` value results in default location.
- parameter tileStoreLocation: Configuration of `TileStore` location, where Navigation tiles are stored.
*/
init(along route: Route, routeIndex: Int, options: RouteOptions, directions: Directions, dataSource source: RouterDataSource, tileStoreLocation: TileStoreLocation.Strict)
init(along route: Route, routeIndex: Int, options: RouteOptions, directions: Directions, dataSource source: RouterDataSource, tileStoreLocation: TileStoreConfiguration.Location)

/**
Details about the user’s progress along the current route, leg, and step.
Expand Down
86 changes: 86 additions & 0 deletions Sources/MapboxCoreNavigation/TileStoreConfiguration.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@

import Foundation
import MapboxCommon

/**
Describes `TileStore` setup.
This struct encapsulates logic for handling `default` and `custom` paths as well as providing corresponding `TileStore`s.
It also covers differences between tile storages for Map and Navigation data. Tupically, you won't need to configure these and rely on defaults, unless you provide pre-downloaded data withing your app in which case you'll need `custom()` path to point to your data.
*/
public struct TileStoreConfiguration {
/**
Describes filesystem location for tile storage folder
*/
public enum Location: RawRepresentable {
/**
Encapsulated default location.
`rawValue` for this case will return `nil`
*/
case `default`
/**
User-provided path to tile storage folder
*/
case custom(URL)

public init?(rawValue: URL?) {
self = rawValue.map { .custom($0) } ?? .default
}

/**
Corresponding URL path
`default` location is interpreted as `nil`.
*/
public var rawValue: URL? {
switch self {
case .default:
return nil
case .custom(let url):
return url
}
}
/**
A `TileStore` instance, configured for current location.
*/
public var tileStore: TileStore {
switch self {
case .default:
return TileStore.getInstance()
case .custom(let url):
return TileStore.getInstanceForPath(url.path)
}
}
}

/**
Location of Navigator tiles data
*/
public let navigatorLocation: Location
/**
Location of Map tiles data
*/
public let mapLocation: Location?

/**
Tile data will be stored at default SDK location
*/
public static var `default`: Self {
.init(navigatorLocation: .default, mapLocation: .default)
}
/**
Custom path to a folder, where tiles data will be stored
*/
public static func custom(_ url: URL) -> Self {
.init(navigatorLocation: .custom(url), mapLocation: .custom(url))
}
/**
:nodoc:
Option to configure Map and Navigation tiles to be stored separately. You should not use this option unless you know what you are doing.
*/
public static func isolated(navigationLocation: Location, mapLocation: Location?) -> Self {
.init(navigatorLocation: navigationLocation, mapLocation: mapLocation)
}
}
64 changes: 0 additions & 64 deletions Sources/MapboxCoreNavigation/TileStoreLocation.swift

This file was deleted.

7 changes: 4 additions & 3 deletions Sources/MapboxNavigation/NavigationMapView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,9 @@ open class NavigationMapView: UIView {
- parameter frame: The frame rectangle for the `NavigationMapView`.
- parameter navigationCameraType: Type of `NavigationCamera`, which is used for the current instance of `NavigationMapView`.
- parameter tileStoreLocation: Configuration of `TileStore` location, where Map tiles are stored. Use `nil` to disable onboard tile storage.
*/
public init(frame: CGRect, navigationCameraType: NavigationCameraType = .mobile, tileStoreLocation: TileStoreLocation.Optional = .default) {
public init(frame: CGRect, navigationCameraType: NavigationCameraType = .mobile, tileStoreLocation: TileStoreConfiguration.Location? = .default) {
super.init(frame: frame)

setupMapView(frame, navigationCameraType: navigationCameraType, tileStoreLocation: tileStoreLocation)
Expand Down Expand Up @@ -221,12 +222,12 @@ open class NavigationMapView: UIView {
}
}

func setupMapView(_ frame: CGRect, navigationCameraType: NavigationCameraType = .mobile, tileStoreLocation: TileStoreLocation.Optional = .default) {
func setupMapView(_ frame: CGRect, navigationCameraType: NavigationCameraType = .mobile, tileStoreLocation: TileStoreConfiguration.Location? = .default) {
guard let accessToken = CredentialsManager.default.accessToken else {
fatalError("Access token was not set.")
}

let tileStore = tileStoreLocation.tileStore
let tileStore = tileStoreLocation?.tileStore
// TODO: allow customising tile store location.
let resourceOptions = ResourceOptions(accessToken: accessToken,
tileStore: tileStore,
Expand Down
10 changes: 5 additions & 5 deletions Sources/MapboxNavigation/NavigationOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ open class NavigationOptions: NavigationCustomizable {
open var predictiveCacheOptions: PredictiveCacheOptions?

/**
TODO: document it
Configuration of `TileStore` location, where Map and Navigation tiles are stored.
*/
open var tileStoreLocation: TileStoreLocation = .default
open var tileStoreConfiguration: TileStoreConfiguration = .default


// This makes the compiler happy.
Expand All @@ -67,17 +67,17 @@ open class NavigationOptions: NavigationCustomizable {
- parameter topBanner: The container view controller that presents the top banner.
- parameter bottomBanner: The container view controller that presents the bottom banner.
- parameter predictiveCacheOptions: Configuration for predictive caching. These options control how the `PredictiveCacheManager` will try to proactively fetch data related to the route. A `nil` value disables the feature.
- parameter tileStoreLocation: TODO
- parameter tileStoreConfiguration: Configuration of `TileStore` location, where Map and Navigation tiles are stored.
*/
public convenience init(styles: [Style]? = nil, navigationService: NavigationService? = nil, voiceController: RouteVoiceController? = nil, topBanner: ContainerViewController? = nil, bottomBanner: ContainerViewController? = nil, predictiveCacheOptions: PredictiveCacheOptions? = nil, tileStoreLocation: TileStoreLocation = .default) {
public convenience init(styles: [Style]? = nil, navigationService: NavigationService? = nil, voiceController: RouteVoiceController? = nil, topBanner: ContainerViewController? = nil, bottomBanner: ContainerViewController? = nil, predictiveCacheOptions: PredictiveCacheOptions? = nil, tileStoreConfiguration: TileStoreConfiguration = .default) {
self.init()
self.styles = styles
self.navigationService = navigationService
self.voiceController = voiceController
self.topBanner = topBanner
self.bottomBanner = bottomBanner
self.predictiveCacheOptions = predictiveCacheOptions
self.tileStoreLocation = tileStoreLocation
self.tileStoreConfiguration = tileStoreConfiguration
}

/**
Expand Down
6 changes: 3 additions & 3 deletions Sources/MapboxNavigation/NavigationView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ open class NavigationView: UIView {

lazy var endOfRouteHeightConstraint: NSLayoutConstraint? = self.endOfRouteView?.heightAnchor.constraint(equalToConstant: Constants.endOfRouteHeight)

var tileStoreLocation: TileStoreLocation.Optional = .default
var tileStoreLocation: TileStoreConfiguration.Location? = .default
lazy var navigationMapView: NavigationMapView = {
let navigationMapView = NavigationMapView(frame: self.bounds, tileStoreLocation: tileStoreLocation)
navigationMapView.isHidden = false
Expand Down Expand Up @@ -130,7 +130,7 @@ open class NavigationView: UIView {

// MARK: - Initialization methods

convenience init(delegate: NavigationViewDelegate, frame: CGRect = .zero, tileStoreLocation: TileStoreLocation.Optional = .default) {
convenience init(delegate: NavigationViewDelegate, frame: CGRect = .zero, tileStoreLocation: TileStoreConfiguration.Location? = .default) {
self.init(frame: frame, tileStoreLocation: tileStoreLocation)
self.delegate = delegate
updateDelegates() // this needs to be called because didSet's do not fire in init contexts.
Expand All @@ -143,7 +143,7 @@ open class NavigationView: UIView {
}

// TODO: Refine public APIs, which are exposed by `NavigationView`.
public init(frame: CGRect, tileStoreLocation: TileStoreLocation.Optional = .default) {
public init(frame: CGRect, tileStoreLocation: TileStoreConfiguration.Location? = .default) {
self.tileStoreLocation = tileStoreLocation
super.init(frame: frame)
commonInit()
Expand Down

0 comments on commit b5a0dc5

Please sign in to comment.