gpt4 book ai didi

ios - 停止离线 MapBox map 重新下载

转载 作者:行者123 更新时间:2023-12-01 19:46:21 27 4
gpt4 key购买 nike

我正在使用 MapBox 下载离线 map 。这样我的用户就可以在旅行时访问特定区域。
使用 MapBox Offline 文档,MapBox map 似乎总是在有连接时尝试下载(重新下载)。

如何设置我的 MapBox 以便它执行检查存储以查看 map 是否已下载?

func startOfflinePackDownload() {

let region = MGLTilePyramidOfflineRegion(styleURL: mapView.styleURL, bounds: mapView.visibleCoordinateBounds, fromZoomLevel: mapView.zoomLevel, toZoomLevel: 13)

let userInfo = ["name": "My Offline Pack"]
let context = NSKeyedArchiver.archivedData(withRootObject: userInfo)

MGLOfflineStorage.shared().addPack(for: region, withContext: context) { (pack, error) in
guard error == nil else {
// The pack couldn’t be created for some reason.
print("Error: \(error?.localizedDescription ?? "unknown error")")
return
}
// Start downloading.
pack!.resume()
}
}

我找到了下面的代码来检查下载是否已经存在......所以这将在我上面的“startOfflinePackDownload()”函数的开始处进行。
但是,较新版本的 MapBox 无法识别该代码。请问有人可以帮助我吗?
MGLOfflineStorage.sharedOfflineStorage().getPacksWithCompletionHandler { (packs, error) in guard error == nil else {
return
}
for pack in packs {
let userInfo = NSKeyedUnarchiver.unarchiveObjectWithData(pack.context) as! [String: String]
if userInfo["name"] == "My Offline Pack" {
// allready downloaded
return
}
}

最佳答案

mapbox Doc , MGLOfflinePackStateUnknown = 0 表示瓦片已经下载,所以我们同样可以查看离线包状态:

Code is in Objective c , You can convert to swift


-(void)mapViewDidFinishLoadingMap:(MGLMapView *)mapView {

NSArray *arrTiles = MGLOfflineStorage.sharedOfflineStorage.packs;


if (arrTiles.count==0) {
[self startOfflinePackDownload];
}

for (MGLOfflinePack *downloadPack in arrTiles) {
NSLog(@"title: %@",downloadPack.region.description );

switch (downloadPack.state) {
case MGLOfflinePackStateUnknown:
[downloadPack requestProgress];
break;

case MGLOfflinePackStateComplete:

break;

case MGLOfflinePackStateInactive:
[downloadPack resume];
break;

case MGLOfflinePackStateActive:
[self startOfflinePackDownload];
break;

case MGLOfflinePackStateInvalid:
// NSAssert(NO, @"Invalid offline pack at index path %@", indexPath);
break;
}
}
}

关于ios - 停止离线 MapBox map 重新下载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48339095/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com