MBXMapKit叠加不起作用

时间:2014-10-15 23:26:52

标签: ios objective-c mapkit mapbox

我试图使用MapBox的MBXMapKit为我的地图添加自定义样式。我已经关注了示例应用和文档,但我一直看到标准的MapKit用户界面。

我在这里错过了一些明显的东西吗?我已经从SampleApp @ MBXMapBox GitHub添加了协议方法,并添加了MBXRasterTileOverlay,因为我应该......所以我不确定缺少什么。

//
//  MapViewController.h
//

#import <UIKit/UIKit.h>
#import "MapKit/MapKit.h"
#import "MBXMapKit.h"

@interface MapViewController : UIViewController  <MKMapViewDelegate, MBXRasterTileOverlayDelegate>

@end

|

//
//  MapViewController.m
//

#import "MapViewController.h"

@interface MapViewController ()
@property (weak, nonatomic) IBOutlet MKMapView *mapView;
@end

@implementation MapViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setUpNavigationBarView];

    MBXRasterTileOverlay *blah = [[MBXRasterTileOverlay alloc] initWithMapID:@"sparkyrobinson.jp6f81f2" includeMetadata:YES includeMarkers:YES];

    MBXRasterTileOverlay *rasterOverlay = [[MBXRasterTileOverlay alloc] initWithMapID:@"sparkyrobinson.jp6f81f2"];
    rasterOverlay.delegate = self;
    [self.mapView addOverlay:blah];

}

- (void) setUpNavigationBarView
{
    UINavigationBar *navigationBar = self.navigationController.navigationBar;
    [navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
    navigationBar.shadowImage = [UIImage new];
    navigationBar.translucent = YES;
    navigationBar.titleTextAttributes = @{
                                          NSForegroundColorAttributeName: UIColorFromRGB(TURQUOISE),
                                          };
}

#pragma mark - MKMapViewDelegate protocol implementation

- (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id<MKOverlay>)overlay
{
    // This is boilerplate code to connect tile overlay layers with suitable renderers
    //
    if ([overlay isKindOfClass:[MBXRasterTileOverlay class]])
    {
        MKTileOverlayRenderer *renderer = [[MKTileOverlayRenderer alloc] initWithTileOverlay:overlay];
        return renderer;
    }
    return nil;
}


- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
{
    // This is boilerplate code to connect annotations with suitable views
    //
    if ([annotation isKindOfClass:[MBXPointAnnotation class]])
    {
        static NSString *MBXSimpleStyleReuseIdentifier = @"MBXSimpleStyleReuseIdentifier";
        MKAnnotationView *view = [mapView dequeueReusableAnnotationViewWithIdentifier:MBXSimpleStyleReuseIdentifier];
        if (!view)
        {
            view = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:MBXSimpleStyleReuseIdentifier];
        }
        view.image = ((MBXPointAnnotation *)annotation).image;
        view.canShowCallout = YES;
        return view;
    }
    return nil;
}

#pragma mark - MBXRasterTileOverlayDelegate implementation

- (void)tileOverlay:(MBXRasterTileOverlay *)overlay didLoadMetadata:(NSDictionary *)metadata withError:(NSError *)error
{
    // This delegate callback is for centering the map once the map metadata has been loaded
    //
    if (error)
    {
        NSLog(@"Failed to load metadata for map ID %@ - (%@)", overlay.mapID, error?error:@"");
    }
    else
    {
        [self.mapView mbx_setCenterCoordinate:overlay.center zoomLevel:overlay.centerZoom animated:NO];
    }
}


- (void)tileOverlay:(MBXRasterTileOverlay *)overlay didLoadMarkers:(NSArray *)markers withError:(NSError *)error
{
    // This delegate callback is for adding map markers to an MKMapView once all the markers for the tile overlay have loaded
    //
    if (error)
    {
        NSLog(@"Failed to load markers for map ID %@ - (%@)", overlay.mapID, error?error:@"");
    }
    else
    {
        [self.mapView addAnnotations:markers];
    }
}

- (void)tileOverlayDidFinishLoadingMetadataAndMarkers:(MBXRasterTileOverlay *)overlay
{
    [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
}

@end

干杯。

1 个答案:

答案 0 :(得分:0)

一切看起来都不错。您确定self.mapView插座已连接,并且您没有向nil添加叠加层吗?