MGLShapeSource

@interface MGLShapeSource : MGLSource

MGLShapeSource is a map content source that supplies vector shapes to be shown on the map. The shapes may be instances of MGLShape or MGLFeature, or they may be defined by local or external GeoJSON code. A shape source is added to an MGLStyle object along with an MGLVectorStyleLayer object. The vector style layer defines the appearance of any content supplied by the shape source.

Each geojson source defined by the style JSON file is represented at runtime by an MGLShapeSource object that you can use to refine the map’s content and initialize new style layers. You can also add and remove sources dynamically using methods such as -[MGLStyle addSource:] and -[MGLStyle sourceWithIdentifier:].

Any vector style layer initialized with a shape source should have a nil value in its sourceLayerIdentifier property.

Example

var coordinates: [CLLocationCoordinate2D] = [
    CLLocationCoordinate2D(latitude: 37.77, longitude: -122.42),
    CLLocationCoordinate2D(latitude: 38.91, longitude: -77.04),
]
let polyline = MGLPolylineFeature(coordinates: &coordinates, count: UInt(coordinates.count))
let source = MGLShapeSource(identifier: lines, features: [polyline], options: nil)
mapView.style?.addSource(source)