I'm working on an offline map. I updated Mapbox SDK 6.2 to 10.7 Style pack and tile region are downloading successfully.
Step 1 - Download the style and a tile source on the home screen
Step 2 - Turn off the internet
Step 3 - Navigate to the home screen
Actual Result:
Mapbox map is displayed but road, street etc. details are missing while the internet is off.
Expected result:
Mapbox map should display roads, streets and other details while the internet is off.
I appreciated your help resolve this issue. thanks
Here, is the code for downloading the tile region and style pack
let dispatchGroup = DispatchGroup()
// 1. Create style package with loadStylePack() call.
let stylePackLoadOptions = StylePackLoadOptions(glyphsRasterizationMode: .ideographsRasterizedLocally,
metadata: ["tag": "my-outdoors-style-pack"],
acceptExpired: true)!
let tileStore = TileStore.default
let accessToken = ResourceOptionsManager.default.resourceOptions.accessToken
tileStore.setOptionForKey(TileStoreOptions.mapboxAccessToken, value: accessToken)
self.tileStore = tileStore
let accessToken = ResourceOptionsManager.default.resourceOptions.accessToken
offlineManager = OfflineManager(resourceOptions: ResourceOptions(accessToken: accessToken, tileStore: tileStore))
dispatchGroup.enter()
_ = offlineManager?.loadStylePack(for: .outdoors, loadOptions: stylePackLoadOptions) { [weak self] progress in
// These closures do not get called from the main thread. In this case
DispatchQueue.main.async {
print(" progress completedResourceCount/ - requiredResourceCount \(progress.completedResourceCount) / \(progress.requiredResourceCount)")
print("StylePack = \(progress)")
}
} completion: { [weak self] result in
// getting result success
DispatchQueue.main.async {
defer {
dispatchGroup.leave()
}
switch result {
case let .success(stylePack):
print("StylePack = \(stylePack)")
case let .failure(error):
print("stylePack download Error = \(error)")
}
}
}
// 2. Create an offline region with tiles for the outdoors style
let outdoorsOptions = TilesetDescriptorOptions(styleURI: .outdoors, zoomRange: UInt8(minZoom)...UInt8(maxZoom))
guard let outdoorsDescriptor = offlineManager?.createTilesetDescriptor(for: outdoorsOptions) else {
print("outdoorsDescriptor -> missing")
return
}
// Load the tile region
let tileRegionLoadOptions = TileRegionLoadOptions(
geometry: .point(Point(coord)),
descriptors: [outdoorsDescriptor],
metadata: userInfo,
acceptExpired: true)!
// Use the the default TileStore to load this region. You can create
// custom TileStores are are unique for a particular file path, i.e.
// there is only ever one TileStore per unique path.
dispatchGroup.enter()
_ = tileStore.loadTileRegion(forId: tileRegionId, loadOptions: tileRegionLoadOptions) { progress in
// These closures do not get called from the main thread. In this case
// we're updating the UI, so it's important to dispatch to the main
// queue.
DispatchQueue.main.async {
// Update the progress bar
print("Download progress : ")
print(Float(progress.completedResourceCount) / Float(progress.requiredResourceCount))
}
} completion: { result in
//getting result success
DispatchQueue.main.async {
defer {
dispatchGroup.leave()
}
switch result {
case let .success(tileRegion):
print("tileRegion = \(tileRegion)")
print(" tileRegion progress completedResourceCount/ - requiredResourceCount \(tileRegion.completedResourceCount) / \(tileRegion.requiredResourceCount)")
case let .failure(error):
print("tileRegion download Error = \(error)")
}
}
}
// Wait for both downloads before moving to the next state
dispatchGroup.notify(queue: .main) {
print("notify download complete")
}
Added map here:
let mapView = MapView(frame: view.bounds)
mapView.mapboxMap.loadStyleURI(.outdoors)
self.view.addSubview(mapView)