Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions MapboxSceneKit/MapboxImageAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,28 +55,32 @@ public final class MapboxImageAPI: NSObject {
private let httpAPI: MapboxHTTPAPI
private var eventsManager: MMEEventsManager = MMEEventsManager.shared()

@objc
public override init() {
var mapboxAccessToken: String? = nil
@objc convenience public override init() {
var mapboxAccessToken = ""
if let path = Bundle.main.path(forResource: "Info", ofType: "plist"),
let dict = NSDictionary(contentsOfFile: path) as? [String: AnyObject],
let token = dict["MGLMapboxAccessToken"] as? String {
mapboxAccessToken = token
} else {
assert(false, "`accessToken` must be set in the Info.plist as `MGLMapboxAccessToken` or the `Route` passed into the `RouteController` must have the `accessToken` property set.")
}

if let mapboxAccessToken = mapboxAccessToken {
self.init(mapboxAccessToken: mapboxAccessToken)
}

@objc public init(mapboxAccessToken: String) {
if mapboxAccessToken.isEmpty {
assert(false, "MapBox AccessToken is missing or is empty, the models will not be working properly.")
} else {
eventsManager.isMetricsEnabledInSimulator = true
eventsManager.isMetricsEnabledForInUsePermissions = false
eventsManager.initialize(withAccessToken: mapboxAccessToken, userAgentBase: "mapbox-scenekit-ios", hostSDKVersion: String(describing: Bundle(for: MapboxImageAPI.self).object(forInfoDictionaryKey: "CFBundleShortVersionString")!))
eventsManager.disableLocationMetrics()
eventsManager.sendTurnstileEvent()

httpAPI = MapboxHTTPAPI(accessToken: mapboxAccessToken)
} else {
assert(false, "`accessToken` must be set in the Info.plist as `MGLMapboxAccessToken` or the `Route` passed into the `RouteController` must have the `accessToken` property set.")
httpAPI = MapboxHTTPAPI(accessToken: "")
}


httpAPI = MapboxHTTPAPI(accessToken: mapboxAccessToken)

super.init()
}

Expand Down
28 changes: 20 additions & 8 deletions MapboxSceneKit/TerrainNode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,38 @@ open class TerrainNode: SCNNode {
private(set) var altitudeBounds: (CLLocationDistance, CLLocationDistance) = (0.0, 1.0)

/// APIs and Tile fetching
private let api = MapboxImageAPI()
private let api: MapboxImageAPI

fileprivate var pendingFetches = [UUID]()
private static let queue = DispatchQueue(label: "com.mapbox.scenekit.processing", attributes: [.concurrent])

required public init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

@objc public init(southWestCorner: CLLocation, northEastCorner: CLLocation) {

@objc convenience public init(southWestCorner: CLLocation, northEastCorner: CLLocation) {
self.init(api: MapboxImageAPI(), southWestCorner: southWestCorner, northEastCorner: northEastCorner)
}

@objc convenience public init(mapboxAccessToken: String, southWestCorner: CLLocation, northEastCorner: CLLocation) {
self.init(api: MapboxImageAPI(mapboxAccessToken: mapboxAccessToken), southWestCorner: southWestCorner, northEastCorner: northEastCorner)
}

@objc convenience public init(mapboxAccessToken: String, minLat: CLLocationDegrees, maxLat: CLLocationDegrees, minLon: CLLocationDegrees, maxLon: CLLocationDegrees) {
self.init(api: MapboxImageAPI(mapboxAccessToken: mapboxAccessToken), southWestCorner: CLLocation(latitude: minLat, longitude: minLon), northEastCorner: CLLocation(latitude: maxLat, longitude: maxLon))
}

@objc public convenience init(minLat: CLLocationDegrees, maxLat: CLLocationDegrees, minLon: CLLocationDegrees, maxLon: CLLocationDegrees) {
self.init(api: MapboxImageAPI(), southWestCorner: CLLocation(latitude: minLat, longitude: minLon), northEastCorner: CLLocation(latitude: maxLat, longitude: maxLon))
}

private init(api: MapboxImageAPI, southWestCorner: CLLocation, northEastCorner: CLLocation) {
assert(CLLocationCoordinate2DIsValid(southWestCorner.coordinate), "TerrainNode southWestCorner coordinates are invalid.")
assert(CLLocationCoordinate2DIsValid(northEastCorner.coordinate), "TerrainNode northEastCorner coordinates are invalid.")
assert(southWestCorner.coordinate.latitude < northEastCorner.coordinate.latitude, "southWestCorner must be South of northEastCorner")
assert(southWestCorner.coordinate.longitude < northEastCorner.coordinate.longitude, "southWestCorner must be West of northEastCorner")

self.api = api
self.southWestCorner = southWestCorner
self.northEastCorner = northEastCorner
self.styleZoomLevel = Math.zoomLevelForBounds(southWestCorner: southWestCorner,
Expand All @@ -75,11 +92,6 @@ open class TerrainNode: SCNNode {
chamferRadius: 0.0)
}

@objc public convenience init(minLat: CLLocationDegrees, maxLat: CLLocationDegrees, minLon: CLLocationDegrees, maxLon: CLLocationDegrees) {
self.init(southWestCorner: CLLocation(latitude: minLat, longitude: minLon),
northEastCorner: CLLocation(latitude: maxLat, longitude: maxLon))
}

deinit {
for task in pendingFetches {
api.cancelRequestWithID(task)
Expand Down