summaryrefslogtreecommitdiff
path: root/platform/darwin/src/MGLFeature.h
blob: ed4ff627b9c07c73bf72993cd14749cdd95ab44d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#import <Foundation/Foundation.h>

#import "MGLPolyline.h"
#import "MGLPolygon.h"
#import "MGLPointAnnotation.h"
#import "MGLPointCollection.h"
#import "MGLShapeCollection.h"

NS_ASSUME_NONNULL_BEGIN

/**
 The `MGLFeature` protocol is used to provide details about geographic features
 contained in a map view’s
 <a href="https://www.mapbox.com/mapbox-gl-style-spec/#sources">tile sources</a>.
 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 an `MGLShapeSource` or
 `-[MGLMapView addAnnotations:]` and related methods.
 */
@protocol MGLFeature <MGLAnnotation>

/**
 An object that uniquely identifies the feature in its containing
 <a href="https://www.mapbox.com/mapbox-gl-style-spec/#sources">tile source</a>.
 
 The identifier corresponds to the
 <a href="https://github.com/mapbox/vector-tile-spec/tree/master/2.1#42-features">feature identifier</a>
 (`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:
 
 <table>
 <thead>
 <tr><th>In the tile source</th><th>This property</th></tr>
 </thead>
 <tbody>
 <tr><td>Integer</td>               <td><code>NSNumber</code> (use the <code>unsignedLongLongValue</code> or <code>longLongValue</code> property)</td></tr>
 <tr><td>Floating-point number</td> <td><code>NSNumber</code> (use the <code>doubleValue</code> property)</td></tr>
 <tr><td>String</td>                <td><code>NSString</code></td></tr>
 </tbody>
 </table>
 
 For details about the identifiers used in most Mapbox-provided styles, consult
 the
 <a href="https://www.mapbox.com/vector-tiles/mapbox-streets/">Mapbox Streets</a>
 layer reference. Note that while it is possible to change this value on feature 
 instances obtained from `-[MGLMapView visibleFeaturesAtPoint:]` and related 
 methods, there will be no effect on the map. Setting this value can be useful
 when the feature instance is used to initialize an `MGLShapeSource` and that 
 source is added to the map and styled.
 */
@property (nonatomic, copy, nullable) id identifier;

/**
 A dictionary of attributes for this feature specified by the
 <a href="https://www.mapbox.com/mapbox-gl-style-spec/#sources">tile source</a>.
 
 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:
 
 <table>
 <thead>
 <tr><th>In the tile source</th><th>In this dictionary</th></tr>
 </thead>
 <tbody>
 <tr><td>Null</td>                  <td><code>NSNull</code></td></tr>
 <tr><td>Boolean</td>               <td><code>NSNumber</code> (use the <code>boolValue</code> property)</td></tr>
 <tr><td>Integer</td>               <td><code>NSNumber</code> (use the <code>unsignedLongLongValue</code> or <code>longLongValue</code> property)</td></tr>
 <tr><td>Floating-point number</td> <td><code>NSNumber</code> (use the <code>doubleValue</code> property)</td></tr>
 <tr><td>String</td>                <td><code>NSString</code></td></tr>
 </tbody>
 </table>
 
 For details about the attribute names and values found in Mapbox-provided
 vector tile sources, consult the
 <a href="https://www.mapbox.com/vector-tiles/mapbox-streets/">Mapbox Streets</a>
 and
 <a href="https://www.mapbox.com/vector-tiles/mapbox-terrain/">Mapbox Terrain</a>
 layer references. Note that while it is possible to change this value on feature
 instances obtained from `-[MGLMapView visibleFeaturesAtPoint:]` and related
 methods, there will be no effect on the map. Setting this value can be useful
 when the feature instance is used to initialize an `MGLShapeSource` and that
 source is added to the map and styled.
 */
@property (nonatomic, copy) NS_DICTIONARY_OF(NSString *, id) *attributes;

/**
 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.
 */
- (nullable id)attributeForKey:(NSString *)key;

/**
 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.
 */
- (NS_DICTIONARY_OF(NSString *, id) *)geoJSONDictionary;

@end

/**
 The `MGLPointFeature` class represents a point in a
 <a href="https://www.mapbox.com/mapbox-gl-style-spec/#sources">tile source</a>.
 */
@interface MGLPointFeature : MGLPointAnnotation <MGLFeature>
@end

/**
 The `MGLPolylineFeature` class represents a polyline in a
 <a href="https://www.mapbox.com/mapbox-gl-style-spec/#sources">tile source</a>.
 */
@interface MGLPolylineFeature : MGLPolyline <MGLFeature>
@end

/**
 The `MGLPolygonFeature` class represents a polygon in a
 <a href="https://www.mapbox.com/mapbox-gl-style-spec/#sources">tile source</a>.
 */
@interface MGLPolygonFeature : MGLPolygon <MGLFeature>
@end

/**
 The `MGLPointCollectionFeature` class represents a multipoint in a
 <a href="https://www.mapbox.com/mapbox-gl-style-spec/#sources">tile source</a>.
 */
@interface MGLPointCollectionFeature : MGLPointCollection <MGLFeature>
@end

/**
 The `MGLMultiPolylineFeature` class represents a multipolyline in a
 <a href="https://www.mapbox.com/mapbox-gl-style-spec/#sources">tile source</a>.
 */
@interface MGLMultiPolylineFeature : MGLMultiPolyline <MGLFeature>
@end

/**
 The `MGLMultiPolygonFeature` class represents a multipolygon in a
 <a href="https://www.mapbox.com/mapbox-gl-style-spec/#sources">tile source</a>.
 */
@interface MGLMultiPolygonFeature : MGLMultiPolygon <MGLFeature>
@end

/**
 The `MGLShapeCollectionFeature` class represents a shape collection in a
 <a href="https://www.mapbox.com/mapbox-gl-style-spec/#sources">tile source</a>.
 */
@interface MGLShapeCollectionFeature : MGLShapeCollection <MGLFeature>

@property (nonatomic, copy, readonly) NS_ARRAY_OF(MGLShape<MGLFeature> *) *shapes;

+ (instancetype)shapeCollectionWithShapes:(NS_ARRAY_OF(MGLShape<MGLFeature> *) *)shapes;

@end

NS_ASSUME_NONNULL_END