MGLFeature

@protocol MGLFeature <MGLAnnotation>

The MGLFeature protocol is used to provide details about geographic features contained in a map view’s tile sources. Each concrete subclass of MGLShape in turn has a subclass that conforms to this protocol.

Typically, you do not create feature objects yourself but rather obtain them using -[MGLMapView visibleFeaturesAtPoint:] and related methods. Each feature object associates a shape with an identifier and attributes as specified by the source. Like ordinary MGLAnnotation objects, some kinds of MGLFeature objects can also be added to a map view using -[MGLMapView addAnnotations:] and related methods.

  • An object that uniquely identifies the feature in its containing tile source.

    The identifier corresponds to the feature identifier (id) in the tile source. If the source does not specify the feature’s identifier, the value of this property is nil. If specified, the identifier may be an integer, floating-point number, or string. These data types are mapped to instances of the following Foundation classes:

    In the tile sourceThis property
    Integer NSNumber (use the unsignedLongLongValue or longLongValue property)
    Floating-point number NSNumber (use the doubleValue property)
    String NSString

    For details about the identifiers used in most Mapbox-provided styles, consult the Mapbox Streets layer reference.

    Declaration

    Objective-C

    @property (readonly, copy, nonatomic, nullable) id identifier;

    Swift

    var identifier: Any? { get }
  • A dictionary of attributes for this feature specified by the tile source.

    The keys and values of this dictionary are determined by the tile source. In the tile source, each attribute name is a string, while each attribute value may be a null value, Boolean value, integer, floating-point number, or string. These data types are mapped to instances of the following Foundation classes:

    In the tile sourceIn this dictionary
    Null NSNull
    Boolean NSNumber (use the boolValue property)
    Integer NSNumber (use the unsignedLongLongValue or longLongValue property)
    Floating-point number NSNumber (use the doubleValue property)
    String NSString

    For details about the attribute names and values found in Mapbox-provided vector tile sources, consult the Mapbox Streets and Mapbox Terrain layer references.

    Declaration

    Objective-C

    @property (readonly, copy, nonatomic)
        NSDictionary<NSString *, id> *_Nonnull attributes;

    Swift

    var attributes: [String : Any] { get }
  • Returns the feature attribute for the given attribute name.

    See the attributes property’s documentation for details on keys and values associated with this method.

    Declaration

    Objective-C

    - (nullable id)attributeForKey:(nonnull NSString *)key;

    Swift

    func attribute(forKey key: String) -> Any?
  • Returns a dictionary that can be serialized as a GeoJSON Feature representation of an instance of an MGLFeature subclass.

    The dictionary includes a geometry key corresponding to the receiver’s underlying geometry data, a properties key corresponding to the receiver’s attributes property, and an id key corresponding to the receiver’s identifier property.

    Declaration

    Objective-C

    - (nonnull NSDictionary<NSString *, id> *)geoJSONDictionary;

    Swift

    func geoJSONDictionary() -> [String : Any]