MGLLight
@interface MGLLight : NSObject
An MGLLight object represents the light source for extruded geometries in
MGLStyle.
Example
let light = MGLLight()
let position = MGLSphericalPosition(radial: 5, azimuthal: 180, polar: 80)
light.position = NSExpression(forConstantValue: NSValue(mglSphericalPosition: position))
light.anchor = NSExpression(forConstantValue: "map")
mapView.style?.light = light
Related examples
See the Adjust light of 3D buildings to learn how to create and modify the light source for 3D geometries.
-
Whether extruded geometries are lit relative to the map or viewport.
The default value of this property is an expression that evaluates to
viewport.You can set this property to an expression containing any of the following:
- Constant
MGLAnchorvalues - Any of the following constant string values:
map: The position of the light source is aligned to the rotation of the map.viewport: The position of the light source is aligned to the rotation of the viewport.
- Predefined functions, including mathematical and string operators
- Conditional expressions
- Variable assignments and references to assigned variables
- Step functions applied to the
$zoomLevelvariable
This property does not support applying interpolation functions to the
$zoomLevelvariable or applying interpolation or step functions to feature attributes.This property corresponds to the
anchorlight property in the Mapbox Style Specification.Declaration
Objective-C
@property (nonatomic) NSExpression *_Nonnull anchor;Swift
var anchor: NSExpression { get set } - Constant
-
Position of the
MGLLightsource relative to lit (extruded) geometries, in aMGLSphericalPositionstruct [radial coordinate, azimuthal angle, polar angle] where radial indicates the distance from the center of the base of an object to its light, azimuthal indicates the position of the light relative to 0° (0° whenMGLLight.anchoris set toMGLLightAnchorViewportcorresponds to the top of the viewport, or 0° whenMGLLight.anchoris set toMGLLightAnchorMapcorresponds to due north, and degrees proceed clockwise), and polar indicates the height of the light (from 0°, directly above, to 180°, directly below).The default value of this property is an expression that evaluates to an
MGLSphericalPositionstruct set to 1.15 radial, 210 azimuthal and 30 polar.You can set this property to an expression containing any of the following:
- Constant
MGLSphericalPositionvalues - Predefined functions, including mathematical and string operators
- Conditional expressions
- Variable assignments and references to assigned variables
- Interpolation and step functions applied to the
$zoomLevelvariable
This property does not support applying interpolation or step functions to feature attributes.
This property corresponds to the
positionlight property in the Mapbox Style Specification.Related examples
See the Adjust light of 3D buildings example to learn how to create and modify the position of value of an
MGLLightobject for 3D geometries.Declaration
Objective-C
@property (nonatomic) NSExpression *_Nonnull position;Swift
var position: NSExpression { get set } - Constant
-
The transition affecting any changes to this layer’s
positionproperty.This property corresponds to the
position-transitionproperty in the style JSON file format.Declaration
Objective-C
@property (nonatomic) MGLTransition positionTransition;Swift
var positionTransition: MGLTransition { get set } -
Color tint for lighting extruded geometries.
The default value of this property is an expression that evaluates to
NSColor.whiteColor.You can set this property to an expression containing any of the following:
- Constant
NSColorvalues - Predefined functions, including mathematical and string operators
- Conditional expressions
- Variable assignments and references to assigned variables
- Interpolation and step functions applied to the
$zoomLevelvariable
This property does not support applying interpolation or step functions to feature attributes.
This property corresponds to the
colorlight property in the Mapbox Style Specification.Declaration
Objective-C
@property (nonatomic) NSExpression *_Nonnull color;Swift
var color: NSExpression { get set } - Constant
-
The transition affecting any changes to this layer’s
colorproperty.This property corresponds to the
color-transitionproperty in the style JSON file format.Declaration
Objective-C
@property (nonatomic) MGLTransition colorTransition;Swift
var colorTransition: MGLTransition { get set } -
Intensity of lighting (on a scale from 0 to 1). Higher numbers will present as more extreme contrast.
The default value of this property is an expression that evaluates to the float
0.5.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
$zoomLevelvariable
This property does not support applying interpolation or step functions to feature attributes.
This property corresponds to the
intensitylight property in the Mapbox Style Specification.Declaration
Objective-C
@property (nonatomic) NSExpression *_Nonnull intensity;Swift
var intensity: NSExpression { get set } -
The transition affecting any changes to this layer’s
intensityproperty.This property corresponds to the
intensity-transitionproperty in the style JSON file format.Declaration
Objective-C
@property (nonatomic) MGLTransition intensityTransition;Swift
var intensityTransition: MGLTransition { get set }
Install in Dash
MGLLight Class Reference