Customize MGLPolyline using mapbox

為{幸葍}努か 提交于 2019-12-08 05:02:30

You need to set the map delegate to self for the functions to work. Here is the code:

Initiate your viewController with MGLMapViewDelegate

class yourController: UIViewController, CLLocationManagerDelegate, MKMapViewDelegate, MGLMapViewDelegate{

Then after you set the map, add self.mapView.delegate = self like so

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

Then your functions will work:

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()
}

What @denislexic said, but also, note that you can't change width once the initial width has been set.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!