MGLMapCamera
@interface MGLMapCamera : NSObject <NSSecureCoding, NSCopying>
An MGLMapCamera
object represents a viewpoint from which the user observes
some point on an MGLMapView
.
#### Related examples
See the
Camera animation example to learn how to create a camera that rotates
around a central point. See the
Restrict map panning to an area example to learn how to restrict map
panning using MGLMapViewDelegate
‘s
-mapView:shouldChangeFromCamera:toCamera:
method.
-
Coordinate at the center of the map view.
Declaration
Objective-C
@property (nonatomic, assign, unsafe_unretained, readwrite) CLLocationCoordinate2D centerCoordinate;
Swift
var centerCoordinate: CLLocationCoordinate2D { get set }
-
Heading measured in degrees clockwise from true north.
Declaration
Objective-C
@property (nonatomic, assign, unsafe_unretained, readwrite) CLLocationDirection heading;
Swift
var heading: CLLocationDirection { get set }
-
Pitch toward the horizon measured in degrees, with 0 degrees resulting in a two-dimensional map.
Declaration
Objective-C
@property (nonatomic, assign, unsafe_unretained, readwrite) CGFloat pitch;
Swift
var pitch: CGFloat { get set }
-
The altitude (measured in meters) above the map at which the camera is situated.
The altitude is the distance from the viewpoint to the map, perpendicular to the map plane. This property does not account for physical elevation.
This property’s value may be less than that of the
viewingDistance
property. Setting this property automatically updates theviewingDistance
property based on thepitch
property’s current value.Declaration
Objective-C
@property (nonatomic, assign, unsafe_unretained, readwrite) CLLocationDistance altitude;
Swift
var altitude: CLLocationDistance { get set }
-
The straight-line distance from the viewpoint to the
centerCoordinate
.Setting this property automatically updates the
altitude
property based on thepitch
property’s current value.Declaration
Objective-C
@property (nonatomic, assign, unsafe_unretained, readwrite) CLLocationDistance viewingDistance;
Swift
var viewingDistance: CLLocationDistance { get set }
-
Returns a new camera with all properties set to 0.
Declaration
Objective-C
+ (nonnull instancetype)camera;
-
Returns a new camera based on information about the camera’s viewpoint and focus point.
Declaration
Objective-C
+ (nonnull instancetype) cameraLookingAtCenterCoordinate:(CLLocationCoordinate2D)centerCoordinate fromEyeCoordinate:(CLLocationCoordinate2D)eyeCoordinate eyeAltitude:(CLLocationDistance)eyeAltitude;
Swift
convenience init(lookingAtCenter centerCoordinate: CLLocationCoordinate2D, fromEyeCoordinate eyeCoordinate: CLLocationCoordinate2D, eyeAltitude: CLLocationDistance)
Parameters
centerCoordinate
The geographic coordinate on which the map should be centered.
eyeCoordinate
The geometric coordinate at which the camera should be situated.
eyeAltitude
The altitude (measured in meters) above the map at which the camera should be situated. The altitude may be less than the distance from the camera’s viewpoint to the camera’s focus point.
-
Returns a new camera with the given distance, pitch, and heading.
This method interprets the distance as a straight-line distance from the viewpoint to the center coordinate. To specify the altitude of the viewpoint, use the
-cameraLookingAtCenterCoordinate:altitude:pitch:heading:
method.Declaration
Objective-C
+ (nonnull instancetype) cameraLookingAtCenterCoordinate:(CLLocationCoordinate2D)centerCoordinate acrossDistance:(CLLocationDistance)distance pitch:(CGFloat)pitch heading:(CLLocationDirection)heading;
Swift
convenience init(lookingAtCenter centerCoordinate: CLLocationCoordinate2D, acrossDistance distance: CLLocationDistance, pitch: CGFloat, heading: CLLocationDirection)
Parameters
centerCoordinate
The geographic coordinate on which the map should be centered.
distance
The straight-line distance from the viewpoint to the
centerCoordinate
.pitch
The viewing angle of the camera, measured in degrees. A value of
0
results in a camera pointed straight down at the map. Angles greater than0
result in a camera angled toward the horizon.heading
The camera’s heading, measured in degrees clockwise from true north. A value of
0
means that the top edge of the map view corresponds to true north. The value90
means the top of the map is pointing due east. The value180
means the top of the map points due south, and so on. -
Returns a new camera with the given altitude, pitch, and heading.
Declaration
Objective-C
+ (nonnull instancetype) cameraLookingAtCenterCoordinate:(CLLocationCoordinate2D)centerCoordinate altitude:(CLLocationDistance)altitude pitch:(CGFloat)pitch heading:(CLLocationDirection)heading;
Swift
convenience init(lookingAtCenter centerCoordinate: CLLocationCoordinate2D, altitude: CLLocationDistance, pitch: CGFloat, heading: CLLocationDirection)
Parameters
centerCoordinate
The geographic coordinate on which the map should be centered.
altitude
The altitude (measured in meters) above the map at which the camera should be situated. The altitude may be less than the distance from the camera’s viewpoint to the camera’s focus point.
pitch
The viewing angle of the camera, measured in degrees. A value of
0
results in a camera pointed straight down at the map. Angles greater than0
result in a camera angled toward the horizon.heading
The camera’s heading, measured in degrees clockwise from true north. A value of
0
means that the top edge of the map view corresponds to true north. The value90
means the top of the map is pointing due east. The value180
means the top of the map points due south, and so on. -
Deprecated
Use -cameraLookingAtCenterCoordinate:acrossDistance:pitch:heading: or -cameraLookingAtCenterCoordinate:altitude:pitch:heading:.
Note
This initializer incorrectly interprets thedistance
parameter. To specify the straight-line distance from the viewpoint tocenterCoordinate
, use the-cameraLookingAtCenterCoordinate:acrossDistance:pitch:heading:
method. To specify the altitude of the viewpoint, use the-cameraLookingAtCenterCoordinate:altitude:pitch:heading:
method, which has the same behavior as this initializer.Declaration
Objective-C
+ (nonnull instancetype) cameraLookingAtCenterCoordinate:(CLLocationCoordinate2D)centerCoordinate fromDistance:(CLLocationDistance)distance pitch:(CGFloat)pitch heading:(CLLocationDirection)heading;
Swift
convenience init(lookingAtCenter centerCoordinate: CLLocationCoordinate2D, fromDistance distance: CLLocationDistance, pitch: CGFloat, heading: CLLocationDirection)
-
Returns a Boolean value indicating whether the given camera is functionally equivalent to the receiver.
Unlike
-isEqual:
, this method returnsYES
if the difference between the coordinates, altitudes, pitches, or headings of the two camera objects is negligible.Declaration
Objective-C
- (BOOL)isEqualToMapCamera:(nonnull MGLMapCamera *)otherCamera;
Swift
func isEqual(to otherCamera: MGLMapCamera) -> Bool
Parameters
otherCamera
The camera with which to compare the receiver.
Return Value
A Boolean value indicating whether the two cameras are functionally equivalent.