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.

  • Returns a shape source with an identifier, URL, and dictionary of options for the source.

    Declaration

    Objective-C

    - (nonnull instancetype)
    initWithIdentifier:(nonnull NSString *)identifier
                   URL:(nonnull NSURL *)url
               options:(nullable NSDictionary<MGLShapeSourceOption, id> *)options;

    Swift

    init(identifier: String, url: URL, options: [MGLShapeSourceOption : Any]? = nil)

    Parameters

    identifier

    A string that uniquely identifies the source.

    URL

    An HTTP(S) URL, absolute file URL, or local file URL relative to the current application’s resource bundle.

    options

    An NSDictionary of options for this source.

    Return Value

    An initialized shape source.

  • Returns a shape source with an identifier, a shape, and dictionary of options for the source.

    To specify attributes about the shape, use an instance of an MGLShape subclass that conforms to the MGLFeature protocol, such as MGLPointFeature. To include multiple shapes in the source, use an MGLShapeCollection or MGLShapeCollectionFeature object.

    To create a shape from GeoJSON source code, use the +[MGLShape shapeWithData:encoding:error:] method.

    Declaration

    Objective-C

    - (nonnull instancetype)
    initWithIdentifier:(nonnull NSString *)identifier
                 shape:(nullable MGLShape *)shape
               options:(nullable NSDictionary<MGLShapeSourceOption, id> *)options;

    Swift

    init(identifier: String, shape: MGLShape?, options: [MGLShapeSourceOption : Any]? = nil)

    Parameters

    identifier

    A string that uniquely identifies the source.

    shape

    A concrete subclass of MGLShape

    options

    An NSDictionary of options for this source.

    Return Value

    An initialized shape source.

  • The contents of the source. A shape can represent a GeoJSON geometry, a feature, or a collection of features.

    If the receiver was initialized using -initWithIdentifier:URL:options:, this property is set to nil. This property is unavailable until the receiver is passed into -[MGLStyle addSource:].

    Declaration

    Objective-C

    @property (readwrite, copy, nonatomic, nullable) MGLShape *shape;

    Swift

    @NSCopying var shape: MGLShape? { get set }
  • URL

    The URL to the GeoJSON document that specifies the contents of the source.

    If the receiver was initialized using -initWithIdentifier:shape:options:, this property is set to nil.

    Declaration

    Objective-C

    @property (readwrite, copy, nonatomic, nullable) NSURL *URL;

    Swift

    var url: URL? { get set }