刚开始使用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。有任何想法吗?
答案 0 :(得分:1)
地图ID用于栅格地图图块图像,而不是GL。你想做两件事之一:
实际使用栅格地图:MSDN documentation
敬请期待我们完全自定义 vector 样式并导出样式ID以应用于MGLMapView
。观看https://www.mapbox.com/mapbox-gl-ios/examples/raster-styles/。