我正在使用Mapbox iOS SDK并尝试绘制一条没有GeoJSON的折线。我尝试使用以下方法获取路线:
func calculateRoute() {
...
let options = NavigationRouteOptions(waypoints: [origin, destination], profileIdentifier: .automobileAvoidingTraffic)
Directions.shared.calculate(options) { (waypoints, routes, error) in
guard let route = routes?.first else { return }
self.showPreview(route: route)
}
}
然后我尝试绘制一条路线。
func showPreview(route: Route) {
guard let steps = route.legs.first?.steps else { return }
var points = [CLLocationCoordinate2D]()
for step in steps {
points.append(step.maneuverLocation)
}
let line = MGLPolyline(coordinates: &points, count: UInt(points.count))
mapView?.addAnnotation(line)
}
它在地图视图上绘制折线。我可以通过两个委托方法(MGLMapViewDelegate)改变折线的颜色和宽度。
func mapView(_ mapView: MGLMapView, lineWidthForPolylineAnnotation annotation: MGLPolyline) -> CGFloat {
return 10
}
func mapView(_ mapView: MGLMapView, strokeColorForShapeAnnotation annotation: MGLShape) -> UIColor {
return .blue
}
但是我找不到一种方法来设置折线周围的边框宽度和边框颜色。有什么办法可以做到这一点吗?