我正在使用MapBox下载离线地图。因此,用户可以在没有互联网连接的情况下访问特定区域。
当我尝试下载一个区域并且样式具有“卫星”层时,我的问题出现了,这个有很多我不想要的资源。此问题仅出现在其中包含“卫星”图层的地图中,而不出现在没有此图层的地图中。是否可以下载没有“卫星”层的区域?
目前,我正在使用此功能下载一个区域周围的区域。
func downloadMapRegionInBackground(
mapView: MGLMapView,
radius: Double,
coordinate: CLLocationCoordinate2D
) {
let region = MGLTilePyramidOfflineRegion(
styleURL: mapView.styleURL,
bounds: mapView.visibleCoordinateBounds,
fromZoomLevel: mapView.zoomLevel,
toZoomLevel: mapView.maximumZoomLevel
)
let userInfo = ["name": "\(region.bounds)"]
let context = NSKeyedArchiver.archivedData(withRootObject: userInfo)
MGLOfflineStorage.shared.addPack(for: region, withContext: context) { [weak self] pack, _ in
guard pack != nil else {
self?.notificationsService.failure(
withTitle: nil,
message: L10n.Map.OfflineRegion.failed
)
return
}
pack?.resume()
self?.notificationsService.information(
withTitle: nil,
message: L10n.Map.OfflineRegion.started
)
}
}