MGLShape

@interface MGLShape : NSObject <MGLAnnotation>

The MGLShape class is an abstract class that defines the basic properties for all shape-based annotation objects. This class must be subclassed and cannot be used as is. Subclasses are responsible for defining the geometry of the shape and providing an appropriate value for the coordinate property inherited from the MGLAnnotation protocol.

  • 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.

    Declaration

    Objective-C

    + (nullable instancetype)shapeWithData:(nonnull NSData *)data
                                  encoding:(NSStringEncoding)encoding
                                     error:(NSError *_Nullable *_Nullable)outError;

    Swift

    convenience init(data: Data, encoding: UInt) throws

    Parameters

    data

    String data containing GeoJSON source code.

    encoding

    The encoding used by data.

    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 Value

    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.

  • The title of the shape annotation. The default value of this property is nil.

    Declaration

    Objective-C

    @property (readwrite, copy, nonatomic, nullable) NSString *title;

    Swift

    var title: String? { get set }
  • The subtitle of the shape annotation. The default value of this property is nil.

    Declaration

    Objective-C

    @property (readwrite, copy, nonatomic, nullable) NSString *subtitle;

    Swift

    var subtitle: String? { get set }
  • Returns the GeoJSON string representation of the shape encapsulated in a data object.

    Declaration

    Objective-C

    - (nonnull NSData *)geoJSONDataUsingEncoding:(NSStringEncoding)encoding;

    Swift

    func geoJSONData(usingEncoding encoding: UInt) -> Data

    Parameters

    encoding

    The string encoding to use.

    Return Value

    A data object containing the shape’s GeoJSON string representation.