2015-08-15 114 views
1

使用Mapbox剛剛起步,管理由locationManaged didUpdateLocations自定義MGLPolyline使用mapbox

添加此
var shape = MGLPolyline(coordinates: &a, count: UInt(a.count)) 
    mapView.addAnnotation(shape) 
  1. 改變線寬不會改變它在屏幕上畫一個MGLPolyline

func mapView(mapView: MGLMapView, lineWidthForPolylineAnnotation annotation: MGLPolyline) -> CGFloat { return 20.0 }

  1. 如何將筆觸默認顏色從黑色更改爲某些東西els è?

回答

3

您需要將地圖代表設置爲self以使函數可以工作。下面是代碼:

啓動您的viewController與MGLMapViewDelegate

class yourController: UIViewController, CLLocationManagerDelegate, MKMapViewDelegate, MGLMapViewDelegate{ 

然後,設置地圖後,加self.mapView.delegate = self像這樣

mapView = MGLMapView(frame: mapViewWrapper.bounds, styleURL: NSURL(string: Mapbox.getTheme())) 
mapView = Mapbox.configure(mapView) 
mapView.setCenterCoordinate(appleMap.userLocation.coordinate, zoomLevel: 12, animated: true) 
mapViewWrapper.addSubview(mapView) 
self.mapView.delegate = self 

那麼你的功能將工作:

func mapView(mapView: MGLMapView, alphaForShapeAnnotation annotation: MGLShape) -> CGFloat { 
    // Set the alpha for all shape annotations to 1 (full opacity) 
    return 1 
} 

func mapView(mapView: MGLMapView, lineWidthForPolylineAnnotation annotation: MGLPolyline) -> CGFloat { 
    // Set the line width for polyline annotations 
    return 5.0 
} 

func mapView(mapView: MGLMapView, strokeColorForShapeAnnotation annotation: MGLShape) -> UIColor { 
    // Give our polyline a unique color by checking for its `title` property 
    return UIColor.redColor() 
} 
1

@denislexic說了什麼,但是,請注意,您不能更改wid一旦初始寬度設定完畢。

相關問題