简体   繁体   中英

Can't show two layers one above another in RMMapView from Mapbox SDK iOS

I have two URL templates (one is a terrain and another is labels). So I need to show the label layer (which is transparent with layers) above the map tiles.

I inherited from RMAbstractWebMapSource and made a class AxMapKitTileSource where override a method of providing URL template.

So, that's how I initialize RMMapView . I have a class, in witch I firstly made the initializing like this:

- (void) commonInitializer
{
    self.mapView = [[RMMapView alloc] initWithFrame:self.bounds];

    self.mapView.autoresizingMask = UIViewAutoresizingFlexibleHeight |
                                    UIViewAutoresizingFlexibleWidth;
    [self addSubview:self.mapView];
    [self updateTiledLayer: self.tiledLayerMode];
}

And in this method I add the tiles to the 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];
    }
}

As I see from the docs addTileSource: should add the layer above the current layers, but the second layer is not appearing on the mapView. I think, I have some initialization issue here - do you help me to solve it?

The usage looks right. One thing you might want to look at if you are not expecting to toggle the visibility of either layer is RMCompositeSource , which will fetch in parallel and client-side composite the layers, caching the result, and is a more efficient way to show layers that are always visible.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM