【发布时间】:2021-09-23 02:14:20
【问题描述】:
我目前正在使用curvyRoute 库来绘制弯曲的折线。它将折线绘制为法线,但我希望折线被点缀。该库使用 addquadcurve 绘制曲线。有没有办法让它变成虚线?
【问题讨论】:
标签: ios swift mapkit mkmapview
我目前正在使用curvyRoute 库来绘制弯曲的折线。它将折线绘制为法线,但我希望折线被点缀。该库使用 addquadcurve 绘制曲线。有没有办法让它变成虚线?
【问题讨论】:
标签: ios swift mapkit mkmapview
你可以通过添加这个样式来绘制虚线。
polyline = MGLPolyline(coordinates: mapCoordinates, count: UInt(mapCoordinates.count))
source = MGLShapeSource(identifier: "line", shape: polyline, options: nil)
style.addSource(source)
let dottedLayer = MGLLineStyleLayer(identifier: "dotted-line-layer", source: source)
dottedLayer.lineColor = NSExpression(forConstantValue: UIColor.darkGray)
dottedLayer.lineWidth = NSExpression(forConstantValue: 4.0)
dottedLayer.lineCap = NSExpression(forConstantValue: "round")
dottedLayer.lineDashPattern = NSExpression(forConstantValue: [0.25, 1.5])
如果我们使用 MKMapView 那么我们可以使用它,
func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer {
guard let polyline = overlay as? MKPolyline else {
fatalError("Not a MKPolyline")
}
let renderer = MKPolylineRenderer(polyline: polyline)
renderer.strokeColor = #colorLiteral(red: 0.2, green: 0.5, blue: 0.77, alpha: 1)
renderer.lineWidth = 6
renderer.lineDashPattern = [0, 10]
return renderer
}
【讨论】:
MGLPolyline的人从哪里来? MGLShapeSource?