MGLPolygonStyleAnnotation

@interface MGLPolygonStyleAnnotation : MGLStyleAnnotation

An MGLPolygonStyleAnnotation is a type of style layer annotation that renders one or more polygons on the map.

To display a line style annotation on a map, use one of the initializers below to create a polygon style annotation object. Then, use -[MGLPolygonAnnotationController add:] to add the annotation to a polygon style annotation controller.

Example

func mapView(_ mapView: MGLMapView, didFinishLoading style: MGLStyle) {
   let polygonAnnotationController = MGLPolygonAnnotationController(mapView: self.mapView)

   let polygonCoordinates = [
       CLLocationCoordinate2DMake(59, 18),
       CLLocationCoordinate2DMake(62, 19),
       CLLocationCoordinate2DMake(54, 20),
       CLLocationCoordinate2DMake(59, 18)
   ]

   let polygon = MGLPolygonStyleAnnotation(coordinates: polygonCoordinates, count: UInt(polygonCoordinates.count))
   polygon.fillOutlineColor = .red
   polygonAnnotationController.add(polygon)
}
  • Returns a polygon style annotation initialized with coordinates.

    Declaration

    Objective-C

    - (nonnull instancetype)initWithCoordinates:(id)coordinates
                                          count:(NSUInteger)count;

    Swift

    init(coordinates: Any!, count: UInt)

    Parameters

    coordinates

    An array of coordinates representing the polygon shape.

    Return Value

    An initialized polygon style annotation.

  • Returns a polygon style annotation initialized with coordinates and a specified fill color.

    Declaration

    Objective-C

    - (nonnull instancetype)initWithCoordinates:(id)coordinates
                                          count:(NSUInteger)count
                                      fillColor:(nonnull UIColor *)fillColor;

    Swift

    init(coordinates: Any!, count: UInt, fill fillColor: UIColor)

    Parameters

    coordinates

    An array of coordinates representing the polygon shape.

    fillColor

    The fill color of the polygon style annotation.

    Return Value

    An initialized polygon style annotation with a defined fill color.

  • Returns a polygon style annotation with interior polygons, initialized with coordinates and a specified fill color.

    Declaration

    Objective-C

    - (nonnull instancetype)initWithCoordinates:(id)coordinates
                                          count:(NSUInteger)count
                               interiorPolygons:(nonnull NSArray *)interiorPolygons;

    Swift

    init(coordinates: Any!, count: UInt, interiorPolygons: [Any])

    Parameters

    coordinates

    An array of coordinates representing the polygon shape.

    interiorPolygons

    An array of MGLPolygonFeatures that represent any holes the polygon may contain.

    Return Value

    An initialized polygon style annotation with a defined fill color.

  • The fill color of the polygon style annotation. Defaults to black.

    This property corresponds to the fill-color property in the style Mapbox Style Specification.

    Declaration

    Objective-C

    @property (readwrite, strong, nonatomic) UIColor *_Nonnull fillColor;

    Swift

    var fillColor: UIColor { get set }
  • The stroke or outline color of the polygon style annotation. Not set by default. Disabled if fillPattern is specified.

    This property corresponds to the fill-outline-color property in the style Mapbox Style Specification.

    Declaration

    Objective-C

    @property (readwrite, strong, nonatomic) UIColor *_Nonnull fillOutlineColor;

    Swift

    var fillOutlineColor: UIColor { get set }
  • The opacity of the fill color associated with the polygon style annotation, represented as a range of values between 0 and 1. Defaults to 1.

    This property corresponds to the fill-opacity property in the style Mapbox Style Specification.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic) CGFloat fillOpacity;

    Swift

    var fillOpacity: CGFloat { get set }
  • The name of the image within an MGLMapStyle‘s sprite to use for filling the polygon style annotation. Not set by default.

    To add an image to the map style’s sprite, use the -[MGLStyle setImage:forName:] method within the Mapbox Maps SDK for iOS. For seamless patterns, image width must be a factor of two (2, 4, 8, …, 512).

    This property corresponds to the fill-pattern property in the style Mapbox Style Specification.

    Declaration

    Objective-C

    @property (readwrite, strong, nonatomic) NSString *_Nonnull fillPattern;

    Swift

    var fillPattern: String { get set }