无法在 Mapbox SDK 的 RMMapView 中一层一层地显示两层 iOS
Can't show two layers one above another in RMMapView from Mapbox SDK iOS
我有两个 URL 模板(一个是地形,另一个是标签)。所以我需要在地图图块上方显示标签图层(图层透明)。
我继承自 RMAbstractWebMapSource
并制作了一个 class AxMapKitTileSource
,其中覆盖了提供 URL 模板的方法。
所以,这就是我初始化的方式 RMMapView
。我有一个 class,在 我首先像这样进行初始化:
- (void) commonInitializer
{
self.mapView = [[RMMapView alloc] initWithFrame:self.bounds];
self.mapView.autoresizingMask = UIViewAutoresizingFlexibleHeight |
UIViewAutoresizingFlexibleWidth;
[self addSubview:self.mapView];
[self updateTiledLayer: self.tiledLayerMode];
}
在这个方法中,我将图块添加到 mapView:
- (void) updateTiledLayer:(AxMapTiledLayerMode)layerMode
{
[self.mapView removeTileSource:self.mapView.tileSource];
[self.mapView removeTileSource:self.mainTileSourse];
[self.mapView removeTileSource:self.auxTileSourse];
[self.mapView removeAllCachedImages];
self.mainTileSourse = nil;
self.auxTileSourse = nil;
NSString *mainTemplateURL = [[AxMapKitConfiguration sharedInstance] URLTemplateForMainTiledLayerForMode:layerMode];
NSInteger mainLayerZoomCorrection = [[AxMapKitConfiguration sharedInstance] zoomOffsetForMainTiledLayerForMode:layerMode];
if (mainTemplateURL && mainTemplateURL.length > 0) {
self.mainTileSourse = [[AxMapKitTileSource alloc] initWithURLTemplate:mainTemplateURL withZoomCorrection:mainLayerZoomCorrection];
[self.mapView setTileSource:self.mainTileSourse];
}
NSString *auxTemplateURL = [[AxMapKitConfiguration sharedInstance] URLTemplateForAuxTiledLayerForMode:layerMode];
NSInteger auxLayerZoomCorrection = [[AxMapKitConfiguration sharedInstance] zoomOffsetForAuxTiledLayerForMode:layerMode];
if (auxTemplateURL && auxTemplateURL.length > 0) {
self.auxTileSourse = [[AxMapKitTileSource alloc] initWithURLTemplate:auxTemplateURL withZoomCorrection:auxLayerZoomCorrection];
[self.mapView addTileSource:self.auxTileSourse];
}
}
正如我从文档中看到的那样 addTileSource:
应该在当前层之上添加该层,但是第二层没有出现在 mapView 上。我想,我这里有一些初始化问题 - 你能帮我解决吗?
用法看起来正确。如果您不希望切换任何一层的可见性,您可能想要查看的一件事是 RMCompositeSource
,它将并行获取并在客户端合成层,缓存结果,这是一种更有效的方法显示始终可见的图层。
我有两个 URL 模板(一个是地形,另一个是标签)。所以我需要在地图图块上方显示标签图层(图层透明)。
我继承自 RMAbstractWebMapSource
并制作了一个 class AxMapKitTileSource
,其中覆盖了提供 URL 模板的方法。
所以,这就是我初始化的方式 RMMapView
。我有一个 class,在 我首先像这样进行初始化:
- (void) commonInitializer
{
self.mapView = [[RMMapView alloc] initWithFrame:self.bounds];
self.mapView.autoresizingMask = UIViewAutoresizingFlexibleHeight |
UIViewAutoresizingFlexibleWidth;
[self addSubview:self.mapView];
[self updateTiledLayer: self.tiledLayerMode];
}
在这个方法中,我将图块添加到 mapView:
- (void) updateTiledLayer:(AxMapTiledLayerMode)layerMode
{
[self.mapView removeTileSource:self.mapView.tileSource];
[self.mapView removeTileSource:self.mainTileSourse];
[self.mapView removeTileSource:self.auxTileSourse];
[self.mapView removeAllCachedImages];
self.mainTileSourse = nil;
self.auxTileSourse = nil;
NSString *mainTemplateURL = [[AxMapKitConfiguration sharedInstance] URLTemplateForMainTiledLayerForMode:layerMode];
NSInteger mainLayerZoomCorrection = [[AxMapKitConfiguration sharedInstance] zoomOffsetForMainTiledLayerForMode:layerMode];
if (mainTemplateURL && mainTemplateURL.length > 0) {
self.mainTileSourse = [[AxMapKitTileSource alloc] initWithURLTemplate:mainTemplateURL withZoomCorrection:mainLayerZoomCorrection];
[self.mapView setTileSource:self.mainTileSourse];
}
NSString *auxTemplateURL = [[AxMapKitConfiguration sharedInstance] URLTemplateForAuxTiledLayerForMode:layerMode];
NSInteger auxLayerZoomCorrection = [[AxMapKitConfiguration sharedInstance] zoomOffsetForAuxTiledLayerForMode:layerMode];
if (auxTemplateURL && auxTemplateURL.length > 0) {
self.auxTileSourse = [[AxMapKitTileSource alloc] initWithURLTemplate:auxTemplateURL withZoomCorrection:auxLayerZoomCorrection];
[self.mapView addTileSource:self.auxTileSourse];
}
}
正如我从文档中看到的那样 addTileSource:
应该在当前层之上添加该层,但是第二层没有出现在 mapView 上。我想,我这里有一些初始化问题 - 你能帮我解决吗?
用法看起来正确。如果您不希望切换任何一层的可见性,您可能想要查看的一件事是 RMCompositeSource
,它将并行获取并在客户端合成层,缓存结果,这是一种更有效的方法显示始终可见的图层。