MapBox 缓存不工作
MapBox cache not working
我正在尝试在 MapBox 中缓存地图。当应用在线时,一切正常。正在正确调用 tileCacheDidFinishBackgroundCache。
然后,我离线重新启动应用程序。 RMMapView 只显示白色,而不是地图。
我的代码:
- (void)viewDidLoad
{
[super viewDidLoad];
[[RMConfiguration sharedInstance] setAccessToken:@"pk......"];
RMTileCache * tileCache = [[RMTileCache alloc] initWithExpiryPeriod:0];
[tileCache setBackgroundCacheDelegate:self];
tileSource = [[RMMapboxSource alloc] initWithMapID:@"mirap.ld8dbe2c"];
mapView = [[RMMapView alloc] initWithFrame:viewMapView.bounds
andTilesource:tileSource];
[mapView.tileSource setCacheable:YES];
[viewMapView addSubview:mapView];
}
-(void)viewDidAppear:(BOOL)animated {
RMSphericalTrapezium rect = [mapView latitudeLongitudeBoundingBox];
mapView.tileCache.backgroundCacheDelegate = self;
[mapView.tileCache beginBackgroundCacheForTileSource:mapView.tileSource
southWest:rect.southWest
northEast:rect.northEast
minZoom:10.0
maxZoom:20.0];
}
- (void)tileCacheDidFinishBackgroundCache:(RMTileCache *)tileCache {
NSLog(@"DONE!");
}
这是您需要的:
mapbox-ios-sdk-offline/ViewController.swift#L38-L44
简而言之,用地图ID初始化瓦片源就是shorthand请求远程元数据URL。
-[RMMapboxSource initWithMapID:]
This method requires a network connection in order to download the TileJSON used to define the tile source.
相反,您还想缓存 tileSource.tileJSON
并在离线时使用它来初始化图块源。
Useful for saving locally to use in instantiating a tile source while offline.
我正在尝试在 MapBox 中缓存地图。当应用在线时,一切正常。正在正确调用 tileCacheDidFinishBackgroundCache。
然后,我离线重新启动应用程序。 RMMapView 只显示白色,而不是地图。
我的代码:
- (void)viewDidLoad
{
[super viewDidLoad];
[[RMConfiguration sharedInstance] setAccessToken:@"pk......"];
RMTileCache * tileCache = [[RMTileCache alloc] initWithExpiryPeriod:0];
[tileCache setBackgroundCacheDelegate:self];
tileSource = [[RMMapboxSource alloc] initWithMapID:@"mirap.ld8dbe2c"];
mapView = [[RMMapView alloc] initWithFrame:viewMapView.bounds
andTilesource:tileSource];
[mapView.tileSource setCacheable:YES];
[viewMapView addSubview:mapView];
}
-(void)viewDidAppear:(BOOL)animated {
RMSphericalTrapezium rect = [mapView latitudeLongitudeBoundingBox];
mapView.tileCache.backgroundCacheDelegate = self;
[mapView.tileCache beginBackgroundCacheForTileSource:mapView.tileSource
southWest:rect.southWest
northEast:rect.northEast
minZoom:10.0
maxZoom:20.0];
}
- (void)tileCacheDidFinishBackgroundCache:(RMTileCache *)tileCache {
NSLog(@"DONE!");
}
这是您需要的:
mapbox-ios-sdk-offline/ViewController.swift#L38-L44
简而言之,用地图ID初始化瓦片源就是shorthand请求远程元数据URL。
-[RMMapboxSource initWithMapID:]
This method requires a network connection in order to download the TileJSON used to define the tile source.
相反,您还想缓存 tileSource.tileJSON
并在离线时使用它来初始化图块源。
Useful for saving locally to use in instantiating a tile source while offline.