我正在使用MapBox和RMTileCache的beginBackgroundCacheForTileSource:在我的客户端应用程序中渲染地图之前预先加载tiles。我想为地图上当前可见的区域预加载从缩放级别3到缩放级别7的瓦片。因此,我使用从mapView latitudeLongitudeBoundingBox返回的mapView传递当前的边界。我的ViewController实现了RMTileCacheBackgroundDelegate,以便在缓存发生后完成时获得回调。我确实收到了didBeginBackgroundCacheWithCount:forTileSource:和didBackgroundCacheTile:withIndex:ofTotalTileCount:上的回调,但是,从来没有调用过tileCacheDidFinishBackgroundCache:。
我浏览了RMTileCache的源代码,注意到"progTile“中缓存的磁贴的实际数量从未达到"totalTiles”中计算出的总数量。因此,没有到达最终的回调tileCacheDidFinishBackgroundCache:。
我不确定如何更改(或者是否应该更改) totalTiles计算。也许我在最初的调用中传递了错误的视图rect?我不完全清楚这是否正确。我可以创建一个简单的修复程序,调用tileCacheDidFinishBackgroundCache:在缓存简单完成的情况下,但这似乎只是隐藏了问题。这里的任何指导都将不胜感激。
作为参考,我的测试代码很简单:
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
RMMapboxSource *onlineSource = [[RMMapboxSource alloc] initWithMapID:@"appleweed.control-room"];
mapView = [[RMMapView alloc] initWithFrame:self.view.bounds andTilesource:onlineSource];
//mapView.delegate = self;
mapView.bouncingEnabled = YES;
mapView.clusteringEnabled = YES;
mapView.clusterMarkerSize = CGSizeMake(40, 40);
mapView.clusterAreaSize = CGSizeMake(40, 40);
mapView.zoom = 1;
RMSphericalTrapezium rect = [mapView latitudeLongitudeBoundingBox];
mapView.tileCache.backgroundCacheDelegate = self;
[mapView.tileCache beginBackgroundCacheForTileSource:mapView.tileSource
southWest:rect.southWest
northEast:rect.northEast
minZoom:3.0
maxZoom:7.0];
}
- (void)tileCache:(RMTileCache *)tileCache didBeginBackgroundCacheWithCount:(int)tileCount forTileSource:(id <RMTileSource>)tileSource {
NSLog(@"start");
}
- (void)tileCache:(RMTileCache *)tileCache didBackgroundCacheTile:(RMTile)tile withIndex:(int)tileIndex ofTotalTileCount:(int)totalTileCount {
// float percentComplete = ((float)tileIndex / (float)totalTileCount) * 100;
//NSString *update = [NSString stringWithFormat:@"%.0f%%", percentComplete];
//NSLog(@"%@",update);
}
- (void)tileCacheDidFinishBackgroundCache:(RMTileCache *)tileCache {
NSLog(@"DONE!");
}
- (void)tileCacheDidCancelBackgroundCache:(RMTileCache *)tileCache {
NSLog(@"Canceled!");
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end发布于 2014-03-11 04:25:58
它是否每次都在相同的瓦片计数处停止?是否有地图视图同时可见?如果你在调试器中暂停你的应用程序,一旦它在后台似乎停止了下载磁贴,它会做什么?
https://stackoverflow.com/questions/22303592
复制相似问题