MGLLineStyleLayer


@interface MGLLineStyleLayer : MGLVectorStyleLayer

An MGLLineStyleLayer is a style layer that renders one or more stroked polylines on the map.

Use a line style layer to configure the visual appearance of polyline or multipolyline features. These features can come from vector tiles loaded by an MGLVectorTileSource object, or they can be MGLPolyline, MGLPolylineFeature, MGLMultiPolyline, or MGLMultiPolylineFeature instances in an MGLShapeSource or MGLComputedShapeSource object.

You can access an existing line style layer using the -[MGLStyle layerWithIdentifier:] method if you know its identifier; otherwise, find it using the MGLStyle.layers property. You can also create a new line style layer and add it to the style using a method such as -[MGLStyle addLayer:].

See the Add multiple shapes from a single shape source example to learn how to add a line to your map using this style layer. See the Add a line style layer from GeoJSON example to learn how to add and style line data to an MGLMapView object at runtime.

Example

let layer = MGLLineStyleLayer(identifier: "trails-path", source: trails)
layer.sourceLayerIdentifier = "trails"
layer.lineWidth = NSExpression(format: "mgl_interpolate:withCurveType:parameters:stops:($zoomLevel, 'exponential', 1.5, %@)",
                               [14: 2,
                                18: 20])
layer.lineColor = NSExpression(forConstantValue: UIColor.brown)
layer.lineCap = NSExpression(forConstantValue: "round")
layer.predicate = NSPredicate(format: "%K == %@", "trail-type", "mountain-biking")
mapView.style?.addLayer(layer)
  • Returns a line style layer initialized with an identifier and source.

    After initializing and configuring the style layer, add it to a map view’s style using the -[MGLStyle addLayer:] or -[MGLStyle insertLayer:belowLayer:] method.

    Declaration

    Objective-C

    - (nonnull instancetype)initWithIdentifier:(nonnull NSString *)identifier
                                        source:(nonnull MGLSource *)source;

    Swift

    init(identifier: String, source: MGLSource)

    Parameters

    identifier

    A string that uniquely identifies the source in the style to which it is added.

    source

    The source from which to obtain the data to style. If the source has not yet been added to the current style, the behavior is undefined.

    Return Value

    An initialized foreground style layer.

  • The display of line endings.

    The default value of this property is an expression that evaluates to butt. Set this property to nil to reset it to the default value.

    You can set this property to an expression containing any of the following:

    • Constant MGLLineCap values
    • Any of the following constant string values:
      • butt: A cap with a squared-off end which is drawn to the exact endpoint of the line.
      • round: A cap with a rounded end which is drawn beyond the endpoint of the line at a radius of one-half of the line’s width and centered on the endpoint of the line.
      • square: A cap with a squared-off end which is drawn beyond the endpoint of the line at a distance of one-half of the line’s width.
    • Predefined functions, including mathematical and string operators
    • Conditional expressions
    • Variable assignments and references to assigned variables
    • Step functions applied to the $zoomLevel variable

    This property does not support applying interpolation functions to the $zoomLevel variable or applying interpolation or step functions to feature attributes.

    Declaration

    Objective-C

    @property (nonatomic, null_resettable) NSExpression *lineCap;

    Swift

    var lineCap: NSExpression! { get set }
  • The display of lines when joining.

    The default value of this property is an expression that evaluates to miter. Set this property to nil to reset it to the default value.

    You can set this property to an expression containing any of the following:

    • Constant MGLLineJoin values
    • Any of the following constant string values:
      • bevel: A join with a squared-off end which is drawn beyond the endpoint of the line at a distance of one-half of the line’s width.
      • round: A join with a rounded end which is drawn beyond the endpoint of the line at a radius of one-half of the line’s width and centered on the endpoint of the line.
      • miter: A join with a sharp, angled corner which is drawn with the outer sides beyond the endpoint of the path until they meet.
    • Predefined functions, including mathematical and string operators
    • Conditional expressions
    • Variable assignments and references to assigned variables
    • Interpolation and step functions applied to the $zoomLevel variable and/or feature attributes

    Declaration

    Objective-C

    @property (nonatomic, null_resettable) NSExpression *lineJoin;

    Swift

    var lineJoin: NSExpression! { get set }
  • Used to automatically convert miter joins to bevel joins for sharp angles.

    The default value of this property is an expression that evaluates to the float 2. Set this property to nil to reset it to the default value.

    This property is only applied to the style if lineJoin is set to an expression that evaluates to miter. Otherwise, it is ignored.

    You can set this property to an expression containing any of the following:

    • Constant numeric values
    • Predefined functions, including mathematical and string operators
    • Conditional expressions
    • Variable assignments and references to assigned variables
    • Interpolation and step functions applied to the $zoomLevel variable

    This property does not support applying interpolation or step functions to feature attributes.

    Declaration

    Objective-C

    @property (nonatomic, null_resettable) NSExpression *lineMiterLimit;

    Swift

    var lineMiterLimit: NSExpression! { get set }
  • Used to automatically convert round joins to miter joins for shallow angles.

    The default value of this property is an expression that evaluates to the float 1.05. Set this property to nil to reset it to the default value.

    This property is only applied to the style if lineJoin is set to an expression that evaluates to round. Otherwise, it is ignored.

    You can set this property to an expression containing any of the following:

    • Constant numeric values
    • Predefined functions, including mathematical and string operators
    • Conditional expressions
    • Variable assignments and references to assigned variables
    • Interpolation and step functions applied to the $zoomLevel variable

    This property does not support applying interpolation or step functions to feature attributes.

    Declaration

    Objective-C

    @property (nonatomic, null_resettable) NSExpression *lineRoundLimit;

    Swift

    var lineRoundLimit: NSExpression! { get set }
  • Sorts features in ascending order based on this value. Features with a higher sort key will appear above features with a lower sort key.

    You can set this property to an expression containing any of the following:

    • Constant numeric values
    • Predefined functions, including mathematical and string operators
    • Conditional expressions
    • Variable assignments and references to assigned variables
    • Interpolation and step functions applied to the $zoomLevel variable and/or feature attributes

    Declaration

    Objective-C

    @property (nonatomic, null_resettable) NSExpression *lineSortKey;

    Swift

    var lineSortKey: NSExpression! { get set }
  • Blur applied to the line, in points.

    This property is measured in points.

    The default value of this property is an expression that evaluates to the float 0. Set this property to nil to reset it to the default value.

    You can set this property to an expression containing any of the following:

    • Constant numeric values no less than 0
    • Predefined functions, including mathematical and string operators
    • Conditional expressions
    • Variable assignments and references to assigned variables
    • Interpolation and step functions applied to the $zoomLevel variable and/or feature attributes

    Declaration

    Objective-C

    @property (nonatomic, null_resettable) NSExpression *lineBlur;

    Swift

    var lineBlur: NSExpression! { get set }
  • The transition affecting any changes to this layer’s lineBlur property.

    This property corresponds to the line-blur-transition property in the style JSON file format.

    Declaration

    Objective-C

    @property (nonatomic) MGLTransition lineBlurTransition;

    Swift

    var lineBlurTransition: MGLTransition { get set }
  • The color with which the line will be drawn.

    The default value of this property is an expression that evaluates to UIColor.blackColor. Set this property to nil to reset it to the default value.

    This property is only applied to the style if linePattern is set to nil. Otherwise, it is ignored.

    You can set this property to an expression containing any of the following:

    • Constant UIColor values
    • Predefined functions, including mathematical and string operators
    • Conditional expressions
    • Variable assignments and references to assigned variables
    • Interpolation and step functions applied to the $zoomLevel variable and/or feature attributes

    Declaration

    Objective-C

    @property (nonatomic, null_resettable) NSExpression *lineColor;

    Swift

    var lineColor: NSExpression! { get set }
  • The transition affecting any changes to this layer’s lineColor property.

    This property corresponds to the line-color-transition property in the style JSON file format.

    Declaration

    Objective-C

    @property (nonatomic) MGLTransition lineColorTransition;

    Swift

    var lineColorTransition: MGLTransition { get set }
  • Specifies the lengths of the alternating dashes and gaps that form the dash pattern. The lengths are later scaled by the line width. To convert a dash length to points, multiply the length by the current line width. Note that GeoJSON sources with lineMetrics: true specified won’t render dashed lines to the expected scale. Also note that zoom-dependent expressions will be evaluated only at integer zoom levels.

    This property is measured in line widths.

    This property is only applied to the style if linePattern is set to nil. Otherwise, it is ignored.

    This attribute corresponds to the line-dasharray layout property in the Mapbox Style Specification.

    You can set this property to an expression containing any of the following:

    • Constant array values no less than 0
    • Predefined functions, including mathematical and string operators
    • Conditional expressions
    • Variable assignments and references to assigned variables
    • Step functions applied to the $zoomLevel variable

    This property does not support applying interpolation functions to the $zoomLevel variable or applying interpolation or step functions to feature attributes.

    Declaration

    Objective-C

    @property (nonatomic, null_resettable) NSExpression *lineDashPattern;

    Swift

    var lineDashPattern: NSExpression! { get set }
  • The transition affecting any changes to this layer’s lineDashPattern property.

    This property corresponds to the line-dasharray-transition property in the style JSON file format.

    Declaration

    Objective-C

    @property (nonatomic) MGLTransition lineDashPatternTransition;

    Swift

    var lineDashPatternTransition: MGLTransition { get set }
  • Draws a line casing outside of a line’s actual path. Value indicates the width of the inner gap.

    This property is measured in points.

    The default value of this property is an expression that evaluates to the float 0. Set this property to nil to reset it to the default value.

    You can set this property to an expression containing any of the following:

    • Constant numeric values no less than 0
    • Predefined functions, including mathematical and string operators
    • Conditional expressions
    • Variable assignments and references to assigned variables
    • Interpolation and step functions applied to the $zoomLevel variable and/or feature attributes

    Declaration

    Objective-C

    @property (nonatomic, null_resettable) NSExpression *lineGapWidth;

    Swift

    var lineGapWidth: NSExpression! { get set }
  • The transition affecting any changes to this layer’s lineGapWidth property.

    This property corresponds to the line-gap-width-transition property in the style JSON file format.

    Declaration

    Objective-C

    @property (nonatomic) MGLTransition lineGapWidthTransition;

    Swift

    var lineGapWidthTransition: MGLTransition { get set }
  • The color gradient with which the line will be drawn. This property only has an effect on lines defined by an MGLShapeSource whose MGLShapeSourceOptionLineDistanceMetrics option is set to YES.

    This property is only applied to the style if lineDasharray is set to nil, and linePattern is set to nil, and the data source requirements are met. Otherwise, it is ignored.

    You can set this property to an expression containing any of the following:

    • Constant UIColor values
    • Predefined functions, including mathematical and string operators
    • Conditional expressions
    • Variable assignments and references to assigned variables
    • Interpolation and step functions applied to the $lineProgress variable

    This property does not support applying interpolation or step functions to feature attributes.

    Declaration

    Objective-C

    @property (nonatomic, null_resettable) NSExpression *lineGradient;

    Swift

    var lineGradient: NSExpression! { get set }
  • The line’s offset. For linear features, a positive value offsets the line to the right, relative to the direction of the line, and a negative value to the left. For polygon features, a positive value results in an inset, and a negative value results in an outset.

    This property is measured in points.

    The default value of this property is an expression that evaluates to the float 0. Set this property to nil to reset it to the default value.

    You can set this property to an expression containing any of the following:

    • Constant numeric values
    • Predefined functions, including mathematical and string operators
    • Conditional expressions
    • Variable assignments and references to assigned variables
    • Interpolation and step functions applied to the $zoomLevel variable and/or feature attributes

    Declaration

    Objective-C

    @property (nonatomic, null_resettable) NSExpression *lineOffset;

    Swift

    var lineOffset: NSExpression! { get set }
  • The transition affecting any changes to this layer’s lineOffset property.

    This property corresponds to the line-offset-transition property in the style JSON file format.

    Declaration

    Objective-C

    @property (nonatomic) MGLTransition lineOffsetTransition;

    Swift

    var lineOffsetTransition: MGLTransition { get set }
  • The opacity at which the line will be drawn.

    The default value of this property is an expression that evaluates to the float 1. Set this property to nil to reset it to the default value.

    You can set this property to an expression containing any of the following:

    • Constant numeric values between 0 and 1 inclusive
    • Predefined functions, including mathematical and string operators
    • Conditional expressions
    • Variable assignments and references to assigned variables
    • Interpolation and step functions applied to the $zoomLevel variable and/or feature attributes

    Declaration

    Objective-C

    @property (nonatomic, null_resettable) NSExpression *lineOpacity;

    Swift

    var lineOpacity: NSExpression! { get set }
  • The transition affecting any changes to this layer’s lineOpacity property.

    This property corresponds to the line-opacity-transition property in the style JSON file format.

    Declaration

    Objective-C

    @property (nonatomic) MGLTransition lineOpacityTransition;

    Swift

    var lineOpacityTransition: MGLTransition { get set }
  • Name of image in style images to use for drawing image lines. For seamless patterns, image width must be a factor of two (2, 4, 8, …, 512).

    You can set this property to an expression containing any of the following:

    • Constant string values
    • Predefined functions, including mathematical and string operators
    • Conditional expressions
    • Variable assignments and references to assigned variables
    • Interpolation and step functions applied to the $zoomLevel variable and/or feature attributes

    Declaration

    Objective-C

    @property (nonatomic, null_resettable) NSExpression *linePattern;

    Swift

    var linePattern: NSExpression! { get set }
  • The transition affecting any changes to this layer’s linePattern property.

    This property corresponds to the line-pattern-transition property in the style JSON file format.

    Declaration

    Objective-C

    @property (nonatomic) MGLTransition linePatternTransition;

    Swift

    var linePatternTransition: MGLTransition { get set }
  • The geometry’s offset.

    This property is measured in points.

    The default value of this property is an expression that evaluates to an NSValue object containing a CGVector struct set to 0 points rightward and 0 points downward. Set this property to nil to reset it to the default value.

    This attribute corresponds to the line-translate layout property in the Mapbox Style Specification.

    You can set this property to an expression containing any of the following:

    • Constant CGVector values
    • Predefined functions, including mathematical and string operators
    • Conditional expressions
    • Variable assignments and references to assigned variables
    • Interpolation and step functions applied to the $zoomLevel variable

    This property does not support applying interpolation or step functions to feature attributes.

    Declaration

    Objective-C

    @property (nonatomic, null_resettable) NSExpression *lineTranslation;

    Swift

    var lineTranslation: NSExpression! { get set }
  • The transition affecting any changes to this layer’s lineTranslation property.

    This property corresponds to the line-translate-transition property in the style JSON file format.

    Declaration

    Objective-C

    @property (nonatomic) MGLTransition lineTranslationTransition;

    Swift

    var lineTranslationTransition: MGLTransition { get set }
  • Controls the frame of reference for lineTranslation.

    The default value of this property is an expression that evaluates to map. Set this property to nil to reset it to the default value.

    This property is only applied to the style if lineTranslation is non-nil. Otherwise, it is ignored.

    This attribute corresponds to the line-translate-anchor layout property in the Mapbox Style Specification.

    You can set this property to an expression containing any of the following:

    • Constant MGLLineTranslationAnchor values
    • Any of the following constant string values:
      • map: The line is translated relative to the map.
      • viewport: The line is translated relative to the viewport.
    • Predefined functions, including mathematical and string operators
    • Conditional expressions
    • Variable assignments and references to assigned variables
    • Step functions applied to the $zoomLevel variable

    This property does not support applying interpolation functions to the $zoomLevel variable or applying interpolation or step functions to feature attributes.

    Declaration

    Objective-C

    @property (nonatomic, null_resettable) NSExpression *lineTranslationAnchor;

    Swift

    var lineTranslationAnchor: NSExpression! { get set }
  • Stroke thickness.

    This property is measured in points.

    The default value of this property is an expression that evaluates to the float 1. Set this property to nil to reset it to the default value.

    You can set this property to an expression containing any of the following:

    • Constant numeric values no less than 0
    • Predefined functions, including mathematical and string operators
    • Conditional expressions
    • Variable assignments and references to assigned variables
    • Interpolation and step functions applied to the $zoomLevel variable and/or feature attributes

    Declaration

    Objective-C

    @property (nonatomic, null_resettable) NSExpression *lineWidth;

    Swift

    var lineWidth: NSExpression! { get set }
  • The transition affecting any changes to this layer’s lineWidth property.

    This property corresponds to the line-width-transition property in the style JSON file format.

    Declaration

    Objective-C

    @property (nonatomic) MGLTransition lineWidthTransition;

    Swift

    var lineWidthTransition: MGLTransition { get set }