首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Mapbox RMTileCacheBackgroundDelegate回调不起作用

Mapbox RMTileCacheBackgroundDelegate回调不起作用
EN

Stack Overflow用户
提问于 2015-03-22 21:25:47
回答 1查看 117关注 0票数 0

下面有快速密码。地图上的一切都如预期的那样工作,但我从未看到任何RMTileCashBackgroundDelegate方法正在被调用。我看到的就是“缓存开始了!”然后什么都没有。我试过很多次调整,但都没能成功。任何帮助都将不胜感激!

代码语言:javascript
复制
class MapboxViewController: UIViewController, RMMapViewDelegate, RMTileCacheBackgroundDelegate {
    var mapView: RMMapView!

    override func viewDidLoad() {
        super.viewDidLoad()

        let mapSource:RMMapboxSource = RMMapboxSource(mapID: "myMapId")

        mapView = RMMapView(frame: self.view.bounds, andTilesource: mapSource)
        mapView.delegate = self

        //background caching
        mapView.tileCache.backgroundCacheDelegate = self
        mapView.tileCache.beginBackgroundCacheForTileSource(mapView.tileSource, southWest: swBounds, northEast: neBounds, minZoom: 13, maxZoom: 17)
    }

    override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(animated)

        mainView.addSubview(mapView)
    }

    func tileCache(tileCache: RMTileCache!, didBeginBackgroundCacheWithCount tileCount: Int, forTileSource tileSource: RMTileSource) {
        println("Caching started!")
    }
    func tileCache(tileCache: RMTileCache!, didBackgroundCacheTile tile: RMTile, withIndex tileIndex: Int, ofTotalTileCount totalTileCount: Int) {
        println("Cached tile \(tileIndex) of \(totalTileCount)")
    }
    func tileCache(tileCache: RMTileCache!, didReceiveError error: NSError!, whenCachingTile tile: RMTile) {
        println("Error caching tile")
    }
    func tileCacheDidCancelBackgroundCache(tileCache: RMTileCache!) {
        println("Caching cancelled!")
    }
    func tileCacheDidFinishBackgroundCache(tileCache: RMTileCache!) {
        println("Caching complete!")
    }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-04-25 05:04:00

这里有两个问题,其中一个问题在上面的代码中并不明显:

  1. tileCache函数采用的是UInt而不是Int (升级到SWIFT1.2后强制使用)
  2. 我在beginBackgroundCacheForTileSource中的边框是四舍五入的,所以我最终得到了一条没有瓷砖的边线。这对我来说太草率了,实际上导致Mapbox iOS SDK崩溃。

感谢Mapbox支持他们的帮助。下面是Swift中一个很好的离线缓存示例,以供参考:https://github.com/mapbox/mapbox-ios-sdk-offline

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29200050

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档