轨迹的渐变折线渲染正常,但是地图缩放的时候会崩溃。单色轨道线工作正常。可能是什么问题呢?
私人 func addPolyline() {
if (mapView?.style?.source(withIdentifier: "polyline") as? MGLShapeSource) == nil {
guard let style = mapView?.style else {return}
//let source = MGLShapeSource(identifier: "polyline", shape: nil, options: nil)
let source = MGLShapeSource(identifier: "polyline", shape: nil, options: [.lineDistanceMetrics: true])
style.addSource(source)
polylineSource = source
// Add a layer to style our polyline.
let layer = MGLLineStyleLayer(identifier: "polyline", source: source)
layer.lineJoin = NSExpression(forConstantValue: "round")
layer.lineCap = NSExpression(forConstantValue: "round")
layer.lineColor = NSExpression(forConstantValue: UIColor.init(cgColor: #colorLiteral(red: 0.9372549057, green: 0.3490196168, blue: 0.1921568662, alpha: 1)))
let stops = [0: UIColor.red,
0.1: UIColor.yellow,
0.3: UIColor.green,
0.5: UIColor.cyan,
0.7: UIColor.systemBlue,
1: UIColor.blue]
//FIXME: - CRACH when adding this line when zooming !!!!!!!!!!!!!
layer.lineGradient = NSExpression(format: "mgl_interpolate:withCurveType:parameters:stops:($lineProgress, 'linear', nil, %@)", stops)
// The line width should gradually increase based on the zoom level.
layer.lineWidth = NSExpression(format: "mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'linear', nil, %@)",[13: 2, 18: 5])
style.addLayer(layer)
}
}