1

I need a pointing line to tell someone the order of a line.

I added the dotted line style using MGLLineStyleLayer from mapbox-ios (example: - - - -) But I don't know if it supports the (>>>>) style, or the arrow (--->---), please tell me what to do.

Calm
  • 70
  • 8

1 Answers1

2

You can create a line with an arrow by using the MGLineStyleLayer.linePattern property.

First, create a UIImage with the pattern that you would like to use (in this case, a line with an arrow). Then add that image to your style using [MGLStyle setImage:forName]. That image can then be used for the line pattern.

    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)
        }
    }

jmkiley
  • 976
  • 5
  • 8
  • Thanks for your answer, it is very convenient to use. Besides, I would like to know what kinds of styles come with mapbox? – Calm Aug 27 '19 at 01:41
  • You can learn more about the [default styles](https://www.mapbox.com/maps/) on our website (Scroll down to "Choose a Map"). For more information about creating a custom style, see the [Create a New Style](https://docs.mapbox.com/help/tutorials/create-a-custom-style/) guide. – jmkiley Aug 27 '19 at 19:13