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 isnil
. 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 source This property Integer NSNumber
(use theunsignedLongLongValue
orlongLongValue
property)Floating-point number NSNumber
(use thedoubleValue
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
@NSCopying var identifier: AnyObject? { 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 source In this dictionary Null NSNull
Boolean NSNumber
(use theboolValue
property)Integer NSNumber
(use theunsignedLongLongValue
orlongLongValue
property)Floating-point number NSNumber
(use thedoubleValue
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 : AnyObject] { 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 attributeForKey(key: String) -> AnyObject?