MGLSymbolAnnotationController
@interface MGLSymbolAnnotationController : MGLAnnotationController
An MGLSymbolAnnotationController
is a controller that creates internally
instances of an MGLShapeSource
and MGLSymbolStyleLayer
to simplify the creation
of runtime styling based annotations to the map.
Create instances of MGLSymbolStyleAnnotation
and pass it to this controller.
An image must be supplied to the map style’s sprite before being able to assign it to be the icon image of a symbol.
Example
func mapView(_ mapView: MGLMapView, didFinishLoading style: MGLStyle) {
let attraction = UIImage(named: "attraction")
if let styleImage = attraction {
self.mapView.style?.setImage(styleImage, forName: "attraction")
}
let symbolAnnotationController = MGLSymbolAnnotationController(mapView: self.mapView)
let symbol = MGLSymbolStyleAnnotation(coordinate: CLLocationCoordinate2DMake(59, 18));
symbol.iconImageName = "attraction"
symbol.text = "This is a cool place!"
symbol.textFontSize = 16
symbolAnnotationController.add(symbol)
}
-
If true, the icon will be visible even if it collides with other previously drawn symbols. Requires
iconImageName
. Defaults toNO
.This property corresponds to the
icon-allow-overlap
property in the style Mapbox Style Specification.Declaration
Objective-C
@property (assign, readwrite, nonatomic) BOOL iconAllowsOverlap;
Swift
var iconAllowsOverlap: Bool { get set }
-
If true, other symbols can be visible even if they collide with the icon. Requires
iconImageName
. Defaults toNO
.This property corresponds to the
icon-ignore-placement
property in the style Mapbox Style Specification.Declaration
Objective-C
@property (assign, readwrite, nonatomic) BOOL iconIgnoresPlacement;
Swift
var iconIgnoresPlacement: Bool { get set }
-
If true, text will display without their corresponding icons only when the icon collides with other symbols and the text does not. Requires
iconImageName
. Defaults toNO
.This property corresponds to the
icon-optional
property in the style Mapbox Style Specification.Declaration
Objective-C
@property (assign, readwrite, nonatomic) BOOL iconOptional;
Swift
var iconOptional: Bool { get set }
-
The size of the additional area around the icon’s bounding box used for detecting symbol collisions. Requires
iconImageName
. Defaults to aCGFloat
with a value of2
.This property corresponds to the
icon-padding
property in the style Mapbox Style Specification.Declaration
Objective-C
@property (assign, readwrite, nonatomic) CGFloat iconPadding;
Swift
var iconPadding: Int32 { get set }
-
The orientation of the style annotation’s icon when map is pitched, as defined by
MGLIconPitchAlignment
. RequiresiconImageName
. Defaults toauto
.This property corresponds to the
icon-pitch-alignment
property in the style Mapbox Style Specification.Declaration
Objective-C
@property (assign, readwrite, nonatomic) int iconPitchAlignment;
Swift
var iconPitchAlignment: Int32 { get set }
-
Determines the rotation behavior of icons, in combination with
symbolPlacement
as defined byMGLIconRotationAlignment
. RequiresiconImageName
. Defaults toauto
.This property corresponds to the
icon-pitch-alignment
property in the style Mapbox Style Specification.Declaration
Objective-C
@property (assign, readwrite, nonatomic) int iconRotationAlignment;
Swift
var iconRotationAlignment: Int32 { get set }
-
Scales the icon to fit around the associated text, as defined by
MGLIconTextFit
. RequiresiconImageName
andtext
. Defaults tonone
.This property corresponds to the
icon-text-fit
property in the style Mapbox Style Specification.Declaration
Objective-C
@property (assign, readwrite, nonatomic) int iconTextFit;
Swift
var iconTextFit: Int32 { get set }
-
The size of the additional area added to dimensions determined by
iconTextFit
. Defaults toUIEdgeInsetsZero
.This property corresponds to the
icon-text-fit-padding
property in the style Mapbox Style Specification.Declaration
Objective-C
@property (assign, readwrite, nonatomic) UIEdgeInsets iconTextFitPadding;
Swift
var iconTextFitPadding: Int32 { get set }
-
If true, the icon may be flipped to prevent it from being rendered upside-down. Requires
iconImageName
. RequiresiconRotationAlignment
to be set tomap
. Defaults toNO
.This property corresponds to the
icon-keep-upright
property in the style Mapbox Style Specification.Declaration
Objective-C
@property (assign, readwrite, nonatomic) BOOL keepsIconUpright;
Swift
var keepsIconUpright: Bool { get set }
-
If true, the text may be flipped vertically to prevent it from being rendered upside-down. Requires
text
. RequirestextRotationAlignment
to be set tomap
. Defaults toYES
.This property corresponds to the
text-keep-upright
property in the style Mapbox Style Specification.Declaration
Objective-C
@property (assign, readwrite, nonatomic) BOOL keepsTextUpright;
Swift
var keepsTextUpright: Bool { get set }
-
Maximum angle change between adjacent characters, measured in degrees. Requires
text
. RequiressymbolPlacement
to be set toline
orcenter
. Defaults to45
degrees.This property corresponds to the
text-max-angle
property in the style Mapbox Style Specification.Declaration
Objective-C
@property (assign, readwrite, nonatomic) CGFloat maximumTextAngle;
Swift
var maximumTextAngle: Int32 { get set }
-
If true, the symbols will not cross tile edges to avoid mutual collisions. Recommended in layers that don’t have enough padding in the vector tile to prevent collisions.
This property corresponds to the
symbol-avoid-edges)
property in the style Mapbox Style Specification.Declaration
Objective-C
@property (assign, readwrite, nonatomic) BOOL symbolAvoidsEdges;
Swift
var symbolAvoidsEdges: Bool { get set }
-
The placement of the symbol annotation’s text relative to its geometry, as defined by
MGLSymbolPlacement
. Defaults topoint
.This property corresponds to the
symbol-placement
property in the style Mapbox Style Specification.Declaration
Objective-C
@property (assign, readwrite, nonatomic) int symbolPlacement;
Swift
var symbolPlacement: Int32 { get set }
-
Distance between two symbol anchors, measured in screen points. Requires
symbolPlacement
to be set toline
. Defaults to aCGFloat
that evaluates to250
.This property corresponds to the
symbol-spacing
property in the style Mapbox Style Specification.Declaration
Objective-C
@property (assign, readwrite, nonatomic) CGFloat symbolSpacing;
Swift
var symbolSpacing: Int32 { get set }
-
Controls the order in which overlapping symbol style annotations in the same
MGLSymbolAnnotationController
are rendered, as defined byMGLSymbolZOrder
. Defaults toauto
.This property corresponds to the
symbol-z-order
property in the style Mapbox Style Specification.Declaration
Objective-C
@property (assign, readwrite, nonatomic) int symbolZOrder;
Swift
var symbolZOrder: Int32 { get set }
-
If true, the symbol style annotation’s text will be visible even if it collides with other previously drawn symbol style annotations. Requires
text
. Defaults toNO
.This property corresponds to the
text-allow-overlap
property in the style Mapbox Style Specification.Declaration
Objective-C
@property (assign, readwrite, nonatomic) BOOL textAllowsOverlap;
Swift
var textAllowsOverlap: Bool { get set }
-
Text leading value for multi-line text, measured in ems. Requires
text
. Defaults to aCGFloat
that evaluates to1.2
.This property corresponds to the
text-line-height
property in the style Mapbox Style Specification.Declaration
Objective-C
@property (assign, readwrite, nonatomic) CGFloat textLineHeight;
Swift
var textLineHeight: Int32 { get set }
-
If true, symbol style annotation icons will display without their corresponding text if the text collides with other symbols and the icon does not. Requires
iconImageName
andtext
. Defaults toNO
.This property corresponds to the
text-optional
property in the style Mapbox Style Specification.Declaration
Objective-C
@property (assign, readwrite, nonatomic) BOOL textOptional;
Swift
var textOptional: Bool { get set }
-
The size of the additional area around the text bounding box used for detecting symbol collisions, measured in screen points greater than or equal to zero. Requires
text
. Defaults to aCGFloat
that evaluates to2
.This property corresponds to the
text-padding
property in the style Mapbox Style Specification.Declaration
Objective-C
@property (assign, readwrite, nonatomic) CGFloat textPadding;
Swift
var textPadding: Int32 { get set }
-
The orientation of the symbol style annotation’s text when map is pitched, as defined by
MGLTextPitchAlignment
. Requirestext
. Defaults toauto
.This property corresponds to the
text-pitch-alignment
property in the style Mapbox Style Specification.Declaration
Objective-C
@property (assign, readwrite, nonatomic) int textPitchAlignment;
Swift
var textPitchAlignment: Int32 { get set }
-
Determines the rotation behavior of the individual glyphs forming the text, in combination with
symbolPlacement
and defined byMGLTextRotationAlignment
. Requirestext
. Defaults toauto
.This property corresponds to the
text-rotation-alignment
property in the style Mapbox Style Specification.Declaration
Objective-C
@property (assign, readwrite, nonatomic) int textRotationAlignment;
Swift
var textRotationAlignment: Int32 { get set }
-
Determines the best placement for the text of multiple symbol style annotations given an array of preferred
MGLTextAnchor
values. This allows the renderer to auto-select a uniquetextAnchor
for each symbol style annotation. RequiressymbolPlacement
to be set topoint
. Disabled bytextOffset
andtextAnchor
. Not set by default.This property corresponds to the
text-variable-anchor
property in the style Mapbox Style Specification.Declaration
Objective-C
@property (assign, readwrite, nonatomic) NSArray<NSString *> *_Nonnull textVariableAnchor;
Swift
unowned(unsafe) var textVariableAnchor: NSArray { get set }
-
The distance that the icon anchor of the symbol style annotation is moved from its original placement, measured in screen points. Requires
iconImageName
. Defaults to aCGVector
struct set to 0 points rightward and 0 points downward.This property corresponds to the
icon-translate
property in the style Mapbox Style Specification.Declaration
Objective-C
@property (assign, readwrite, nonatomic) CGVector iconTranslation;
Swift
var iconTranslation: Int32 { get set }
-
Controls the frame of reference for
iconTranslation
, as defined byMGLIconTranslationAnchor
. RequiresiconImageName
. Defaults tomap
.This property corresponds to the
icon-translate-anchor
property in the style Mapbox Style Specification.Declaration
Objective-C
@property (assign, readwrite, nonatomic) int iconTranslationAnchor;
Swift
var iconTranslationAnchor: Int32 { get set }
-
The distance that the text anchor of the symbol style annotation is moved from its original placement, measured in screen points. Requires
text
. Defaults to aCGVector
struct set to 0 points rightward and 0 points downward.This property corresponds to the
text-translate
property in the style Mapbox Style Specification.Declaration
Objective-C
@property (assign, readwrite, nonatomic) CGVector textTranslation;
Swift
var textTranslation: Int32 { get set }
-
Controls the frame of reference for
textTranslation
, as defined byMGLTextTranslationAnchor
. Requirestext
. Defaults tomap
.This property corresponds to the
text-translate-anchor
property in the style Mapbox Style Specification.Declaration
Objective-C
@property (assign, readwrite, nonatomic) int textTranslationAnchor;
Swift
var textTranslationAnchor: Int32 { get set }