MGLFeatureprotocol is used to provide details about geographic features contained in an
MGLVectorTileSourceobject. Each concrete subclass of
MGLShapein turn has a subclass that conforms to this protocol. A feature object associates a shape with an optional identifier and attributes.
You can add custom data to display on the map by creating feature objects and adding them to an
-[MGLShapeSource initWithIdentifier:shape:options:]method or
In addition to adding data to the map, you can also extract data from the map:
-[MGLMapView visibleFeaturesAtPoint:]and related methods return feature objects that correspond to features in the source. This enables you to inspect the properties of features in vector tiles loaded by
MGLVectorTileSourceobjects. You also reuse these feature objects as overlay annotations.
While it is possible to add
MGLFeature-conforming objects to the map as annotations using
-[MGLMapView addAnnotations:]and related methods, doing so has trade-offs:
Features added as annotations will not have
attributesproperties when used with feature querying.
Features added as annotations become interactive. Taps and selection can be handled in
@protocol MGLFeature <MGLAnnotation>
protocol MGLFeature : MGLAnnotation
MGLPointFeatureobject associates a point shape with an optional identifier and attributes.
See the Dynamically style interactive points example to learn how to initialize
MGLPointFeatureobjects and add them to your map.
MGLPolylineFeatureobject associates a polyline shape with an optional identifier and attributes.
A polyline feature is known as a LineString feature in GeoJSON.
MGLMultiPolylineFeatureobject associates a multipolyline shape with an optional identifier and attributes.
A multipolyline feature is known as a MultiLineString feature in GeoJSON.
MGLPointCollectionFeatureobject associates a point collection with an optional identifier and attributes.
A point collection feature is known as a MultiPoint feature in GeoJSON.
MGLShapeCollectionFeatureobject associates a shape collection with an optional identifier and attributes.
MGLShapeCollectionFeatureis most commonly used to add multiple shapes to a single
MGLShapeSource. Configure the appearance of an
MGLSource’s shape collection collectively using an
MGLSymbolStyleLayerobject, or use multiple instances of
MGLLineStyleLayerto configure the appearance of each kind of shape inside the collection.
A shape collection feature is known as a feature collection in GeoJSON.
See the Add multiple shapes from a single shape source example to learn how to add shape data to your map using an