1

我需要一条指示线来告诉某人一条线的顺序。

我使用mapbox-ios中的MGLLineStyleLayer添加了虚线样式(示例:- - - -)但我不知道它是否支持(>>>>)样式或箭头(--->---) , 请告诉我应该怎么做。

4

1 回答 1

2

MGLineStyleLayer.linePattern您可以使用该属性创建带箭头的线。

首先,UIImage使用您想要使用的模式创建一个(在本例中,一条带箭头的线)。然后使用 . 将该图像添加到您的样式中[MGLStyle setImage:forName]。然后可以将该图像用于线条图案。

    func mapView(_ mapView: MGLMapView, didFinishLoading style: MGLStyle) {
        if let image = UIImage(named: "arrow.png") {
            style.setImage(image, forName: "arrow")
            let source = MGLShapeSource(identifier: "polyline", shape: shapeFromGeoJSON, options: nil)
            style.addSource(source)

            let layer = MGLLineStyleLayer(identifier: "polyline", source: source)
            layer.linePattern = NSExpression(forConstantValue: "arrow")
            layer.lineWidth = NSExpression(forConstantValue: 10)
            style.addLayer(layer)
        }
    }

于 2019-08-23T18:40:06.697 回答