MGLPolygon
@interface MGLPolygon : MGLMultiPoint <MGLOverlay>
An MGLPolygon
object represents a closed shape consisting of four or more vertices, specified as CLLocationCoordinate2D
instances, and the edges that connect them. For example, you could use a polygon shape to represent a building, a lake, or an area you want to highlight.
You can add polygon shapes to the map by adding them to an MGLShapeSource
object. Configure the appearance of an MGLShapeSource
’s or MGLVectorTileSource
’s polygons collectively using an MGLFillStyleLayer
or MGLSymbolStyleLayer
object. To access a polygon’s attributes, use an MGLPolygonFeature
object.
Alternatively, you can add a polygon overlay directly to a map view using the -[MGLMapView addAnnotation:]
or -[MGLMapView addOverlay:]
method. Configure a polygon overlay’s appearance using -[MGLMapViewDelegate mapView:strokeColorForShapeAnnotation:]
and -[MGLMapViewDelegate mapView:fillColorForPolygonAnnotation:]
.
The vertices are automatically connected in the order in which you provide them. You should close the polygon by specifying the same CLLocationCoordinate2D
as the first and last vertices; otherwise, the polygon’s fill may not cover the area you expect it to. To avoid filling the space within the shape, give the polygon a transparent fill or use an MGLPolyline
object.
A polygon may have one or more interior polygons, or holes, that you specify as MGLPolygon
objects with the +polygonWithCoordinates:count:interiorPolygons:
method. For example, if a polygon represents a lake, it could exclude an island within the lake using an interior polygon. Interior polygons may not themselves have interior polygons. To represent a shape that includes a polygon within a hole or, more generally, to group multiple polygons together in one shape, use an MGLMultiPolygon
or MGLShapeCollection
object.
To make the polygon straddle the antimeridian, specify some longitudes less than −180 degrees or greater than 180 degrees.
interiorPolygons
The array of polygons nested inside the receiver.
The area occupied by any interior polygons is excluded from the overall shape. Interior polygons should not overlap. An interior polygon should not have interior polygons of its own.
If there are no interior polygons, the value of this property is nil
.
Declaration
Objective-C
@property (nonatomic, readonly, nullable)
NSArray<MGLPolygon *> *interiorPolygons;
Swift
var interiorPolygons: [MGLPolygon]? { get }
+polygonWithCoordinates:count:
Creates and returns an MGLPolygon
object from the specified set of coordinates.
Declaration
Objective-C
+ (nonnull instancetype)polygonWithCoordinates:
(nonnull const CLLocationCoordinate2D *)coords
count:(NSUInteger)count;
Swift
convenience init(coordinates coords: UnsafePointer<CLLocationCoordinate2D>, count: UInt)
Parameters
coords
The array of coordinates defining the shape. The data in this array is copied to the new object.
count
The number of items in the coords
array.
Return Value
A new polygon object.
+polygonWithCoordinates:count:interiorPolygons:
Creates and returns an MGLPolygon
object from the specified set of coordinates and interior polygons.
Declaration
Objective-C
+ (nonnull instancetype)
polygonWithCoordinates:(nonnull const CLLocationCoordinate2D *)coords
count:(NSUInteger)count
interiorPolygons:(nullable NSArray<MGLPolygon *> *)interiorPolygons;
Swift
convenience init(coordinates coords: UnsafePointer<CLLocationCoordinate2D>, count: UInt, interiorPolygons: [MGLPolygon]?)
Parameters
coords
The array of coordinates defining the shape. The data in this array is copied to the new object.
count
The number of items in the coords
array.
interiorPolygons
An array of MGLPolygon
objects that define regions excluded from the overall shape. If this array is nil
or empty, the shape is considered to have no interior polygons.
Return Value
A new polygon object.
iOS SDK
Examples
SDK JS Reference
- Annotations
- Appendices
- NSExpression(MGLAdditions)
- NSValue(MGLAdditions)
- NSValue(MGLCircleStyleLayerAdditions)
- NSValue(MGLFillExtrusionStyleLayerAdditions)
- NSValue(MGLFillStyleLayerAdditions)
- NSValue(MGLHillshadeStyleLayerAdditions)
- NSValue(MGLLineStyleLayerAdditions)
- NSValue(MGLRasterStyleLayerAdditions)
- NSValue(MGLSymbolStyleLayerAdditions)
- MGLAccountManager
- MGLAnnotationImage
- MGLAnnotationView
- MGLAttributedExpression
- MGLAttributionInfo
- MGLBackgroundStyleLayer
- MGLCircleStyleLayer
- MGLClockDirectionFormatter
- MGLCompassButton
- MGLCompassDirectionFormatter
- MGLComputedShapeSource
- MGLCoordinateFormatter
- MGLDistanceFormatter
- MGLFillExtrusionStyleLayer
- MGLFillStyleLayer
- MGLForegroundStyleLayer
- MGLHeatmapStyleLayer
- MGLHillshadeStyleLayer
- MGLImageSource
- MGLLight
- MGLLineStyleLayer
- MGLLoggingConfiguration
- MGLMapCamera
- MGLMapSnapshot
- MGLMapSnapshotOptions
- MGLMapSnapshotOverlay
- MGLMapSnapshotter
- MGLMapView
- MGLMultiPoint
- MGLMultiPolygon
- MGLMultiPolyline
- MGLNetworkConfiguration
- MGLOfflinePack
- MGLOfflineStorage
- MGLPointAnnotation
- MGLPointCollection
- MGLPolygon
- MGLPolyline
- MGLRasterStyleLayer
- MGLRasterTileSource
- MGLShape
- MGLShapeCollection
- MGLShapeOfflineRegion
- MGLShapeSource
- MGLSource
- MGLStyle
- MGLStyleLayer
- MGLSymbolStyleLayer
- MGLTilePyramidOfflineRegion
- MGLTileSource
- MGLUserLocation
- MGLUserLocationAnnotationView
- MGLUserLocationAnnotationViewStyle
- MGLVectorStyleLayer
- MGLVectorTileSource
- MGLAnnotationVerticalAlignment
- MGLAnnotationViewDragState
- MGLAttributionInfoStyle
- MGLCirclePitchAlignment
- MGLCircleScaleAlignment
- MGLCircleTranslationAnchor
- MGLDEMEncoding
- MGLErrorCode
- MGLFillExtrusionTranslationAnchor
- MGLFillTranslationAnchor
- MGLHillshadeIlluminationAnchor
- MGLIconAnchor
- MGLIconPitchAlignment
- MGLIconRotationAlignment
- MGLIconTextFit
- MGLIconTranslationAnchor
- MGLLightAnchor
- MGLLineCap
- MGLLineJoin
- MGLLineTranslationAnchor
- MGLLoggingLevel
- MGLMapDebugMaskOptions
- MGLOfflinePackState
- MGLOrnamentPosition
- MGLOrnamentVisibility
- MGLRasterResamplingMode
- MGLResourceKind
- MGLSymbolPlacement
- MGLSymbolZOrder
- MGLTextAnchor
- MGLTextJustification
- MGLTextPitchAlignment
- MGLTextRotationAlignment
- MGLTextTransform
- MGLTextTranslationAnchor
- MGLTextWritingMode
- MGLTileCoordinateSystem
- MGLUserTrackingMode
- Formatters
- Geometry
- Location Updates
- Maps
- Offline Maps
- Other Categories
- Other Classes
- Other Constants
- Other Enumerations
- Other Functions
- Other Protocols
- Other Structures
- Other Type Definitions
- Primitive Shapes
- MGLAnnotation
- MGLCalloutView
- MGLCalloutViewDelegate
- MGLCluster
- MGLComputedShapeSourceDataSource
- MGLFeature
- MGLLocationManager
- MGLLocationManagerDelegate
- MGLMapSnapshotterDelegate
- MGLMapViewDelegate
- MGLOfflineRegion
- MGLOfflineStorageDelegate
- MGLOverlay
- MGLStylable
- MGLCoordinateBounds
- MGLCoordinateQuad
- MGLCoordinateSpan
- MGLOfflinePackProgress
- MGLSphericalPosition
- MGLTransition
- Style Content
- Style Layers
- Style Primitives
- Styling the Map
- MGLCoordinateBounds
- MGLCoordinateQuad
- MGLCoordinateSpan
- MGLOfflinePackProgress
- MGLSphericalPosition
- MGLTransition
- User Interaction
- Customizing Fonts
- Information for Style Authors
- Gesture Recognizers
- Info.plist Keys
- Migrating to Expressions
- Predicates and expressions
- Tile URL Templates
- Working with GeoJSON Data