看起来我有一个与您类似的用例(即不使用geojson),最终得到了类似的结果。将您的路线与
MGLLineStyleLayer
可以控制线条的视觉参数。
func showPreview(route: Route) {
guard route.coordinateCount > 0 else { return }
// Convert the routeâs coordinates into a polyline
var routeCoordinates = route.coordinates!
let polyline = MGLPolylineFeature(coordinates: &routeCoordinates, count: route.coordinateCount)
// If there's already a route line on the map, reset its shape to the new route
if let source = mapView.style?.source(withIdentifier: "route-source") as? MGLShapeSource {
source.shape = polyline
} else {
let source = MGLShapeSource(identifier: "route-source", features: [polyline], options: nil)
// Customize the route line color and width
let lineStyle = MGLLineStyleLayer(identifier: "route-style", source: source)
lineStyle.lineColor = NSExpression(forConstantValue: UIColor.blue)
lineStyle.lineWidth = NSExpression(forConstantValue: 3)
// Add the source and style layer of the route line to the map
mapView.style?.addSource(source)
mapView.style?.addLayer(lineStyle)
}
}
您要添加边框并控制边框的外观。如果您在Mapbox网站上查看此示例:
Line style Example
他们通过创造一秒钟来做你想做的事
mglinestylelayer公司
把它插在第一个的下面。他们称第二层
casingLayer
. 这是它们的代码,因此您可以看到它的形成方式与第一层相同。
let casingLayer = MGLLineStyleLayer(identifier: "polyline-case", source: source)
// Add your formatting attributes here. See example on website.
然后他们把它插入第一行下面,因为它有一个更宽的宽度,显示为一个边框。
style.insertLayer(casingLayer, below: lineStyle)
希望这有帮助。