summaryrefslogtreecommitdiff
path: root/platform/darwin/src/MGLShape.h
blob: e965710552126b5199cee1f50f052819b778d228 (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
#import <Foundation/Foundation.h>

#import "MGLFoundation.h"
#import "MGLAnnotation.h"

NS_ASSUME_NONNULL_BEGIN

/**
 `MGLShape` is an abstract class that represents a shape or annotation. Shapes
 constitute the content of a map – not only the overlays atop the map, but also
 the content that forms the base map.

 Create instances of `MGLPointAnnotation`, `MGLPointCollection`, `MGLPolyline`,
 `MGLMultiPolyline`, `MGLPolygon`, `MGLMultiPolygon`, or `MGLShapeCollection` in
 order to use `MGLShape`'s methods. Do not create instances of `MGLShape` directly,
 and do not create your own subclasses of this class. The shape classes correspond
 to the <a href="https://tools.ietf.org/html/rfc7946#section-3.1">Geometry</a> object
 types in the GeoJSON standard, but some have nonstandard names for backwards
 compatibility.

 Although you do not create instances of this class directly, you can use its
 `+[MGLShape shapeWithData:encoding:error:]` factory method to create one of the
 concrete subclasses of `MGLShape` noted above from GeoJSON data.

 You can add shapes to the map by adding them to an `MGLShapeSource` object.
 Configure the appearance of an `MGLShapeSource`’s or `MGLVectorSource`’s shapes
 collectively using a concrete instance of `MGLVectorStyleLayer`. Alternatively,
 you can add some kinds of shapes directly to a map view as annotations or
 overlays.
 */
MGL_EXPORT
@interface MGLShape : NSObject <MGLAnnotation, NSSecureCoding>

#pragma mark Creating a Shape

/**
 Returns an `MGLShape` object initialized with the given data interpreted as a
 string containing a GeoJSON object.

 If the GeoJSON object is a geometry, the returned value is a kind of
 `MGLShape`. If it is a feature object, the returned value is a kind of
 `MGLShape` that conforms to the `MGLFeature` protocol. If it is a feature
 collection object, the returned value is an instance of
 `MGLShapeCollectionFeature`.

 ### Example

 ```swift
 let url = mainBundle.url(forResource: "amsterdam", withExtension: "geojson")!
 let data = try! Data(contentsOf: url)
 let feature = try! MGLShape(data: data, encoding: String.Encoding.utf8.rawValue) as! MGLShapeCollectionFeature
 ```

 @param data String data containing GeoJSON source code.
 @param encoding The encoding used by `data`.
 @param outError Upon return, if an error has occurred, a pointer to an
    `NSError` object describing the error. Pass in `NULL` to ignore any error.
 @return An `MGLShape` object representation of `data`, or `nil` if `data` could
    not be parsed as valid GeoJSON source code. If `nil`, `outError` contains an
    `NSError` object describing the problem.
 */
+ (nullable MGLShape *)shapeWithData:(NSData *)data encoding:(NSStringEncoding)encoding error:(NSError * _Nullable *)outError;

#pragma mark Accessing the Shape Attributes

/**
 The title of the shape annotation.

 The default value of this property is `nil`.

 This property is ignored when the shape is used in an `MGLShapeSource`. To name
 a shape used in a shape source, create an `MGLFeature` and add an attribute to
 the `MGLFeature.attributes` property.
 */
@property (nonatomic, copy, nullable) NSString *title;

/**
 The subtitle of the shape annotation. The default value of this property is
 `nil`.

 This property is ignored when the shape is used in an `MGLShapeSource`. To
 provide additional information about a shape used in a shape source, create an
 `MGLFeature` and add an attribute to the `MGLFeature.attributes` property.
 */
@property (nonatomic, copy, nullable) NSString *subtitle;

#if !TARGET_OS_IPHONE

/**
 The tooltip of the shape annotation.

 The default value of this property is `nil`.

 This property is ignored when the shape is used in an `MGLShapeSource`.
 */
@property (nonatomic, copy, nullable) NSString *toolTip;

#endif

#pragma mark Creating GeoJSON Data

/**
 Returns the GeoJSON string representation of the shape encapsulated in a data
 object.

 @param encoding The string encoding to use.
 @return A data object containing the shape’s GeoJSON string representation.
 */
- (NSData *)geoJSONDataUsingEncoding:(NSStringEncoding)encoding;

@end

NS_ASSUME_NONNULL_END