如何自定义Mapbox的主题

How to customize the theme of Mapbox

刚开始使用 Mapbox。我找到了 Objective-c 的代码,但我不知道如何在 Swift 中找到它。有任何想法吗?

这里是 Objective-C 代码:

#import "Mapbox.h"

@interface ViewController ()
@property (nonatomic, strong) RMMapView *mapView;
@end

@implementation MyViewController

- (void)viewDidLoad
{
    [super viewDidLoad];

    [[RMConfiguration sharedInstance] setAccessToken:@"<access token>"];
     // Specially this line below
    RMMapboxSource *tileSource = [[RMMapboxSource alloc] initWithMapID:@"mapbox.wheatpaste"];

    // set coordinates
    CLLocationCoordinate2D center = CLLocationCoordinate2DMake(38.910003, -77.015533);
    self.mapView = [[RMMapView alloc] initWithFrame:self.view.bounds
                                      andTilesource:tileSource]; 
    [self.view addSubview:self.mapView];
}
@end

这是我的 Swift 代码

import MapboxGL
class AppViewController: UIViewController, CLLocationManagerDelegate, MKMapViewDelegate {
   var mapView: MGLMapView!
   override func viewDidLoad() {
       mapView = MGLMapView(frame: mapBoxWrapper.bounds, styleURL: NSURL(string:"dark-v7.json"))
        mapView = Mapbox.configure(mapView)
        // set the map's center coordinate
        mapView.setCenterCoordinate(appleMap.userLocation.coordinate,
            zoomLevel: 12, animated: true)
        mapBoxWrapper.addSubview(mapView)
   }

}

我还想使用地图 ID 而不是 URL。有任何想法吗?

地图 ID 用于栅格地图图块图像,而不是 GL。您想做以下两件事之一:

  1. 实际使用栅格地图:https://www.mapbox.com/mapbox-gl-ios/examples/raster-styles/

  2. 我们将允许完全自定义 vector 样式并导出样式 ID 以应用于您的 MGLMapView,敬请期待。观看blog