MGLMapProjection


@interface MGLMapProjection : NSObject

The aim of this class is to provide the functionality of changing the camera state and converting between map view screen coordinates and geographical coordinates without changing the actual map view camera state.

  • Initializes and returns the new projection object with the current camera state from the provided map view.

    Declaration

    Objective-C

    - (nonnull instancetype)initWithMapView:(nonnull MGLMapView *)mapView;

    Swift

    init(mapView: MGLMapView)

    Parameters

    mapView

    The map view the camera state to use for the initialization.

    Return Value

    An initialized map projection.

  • A camera representing the current projection state

    Declaration

    Objective-C

    @property (copy, readonly) MGLMapCamera *_Nonnull camera;

    Swift

    @NSCopying var camera: MGLMapCamera { get }
  • Change the projection state with camera and padding values.

    Note

    MGLMapView instance frame must not be changed since this projection is initialized, otherwise the calculation may be wrong.

    Declaration

    Objective-C

    - (void)setCamera:(MGLMapCamera *_Nonnull)camera
        withEdgeInsets:(UIEdgeInsets)insets;

    Swift

    func setCamera(_ camera: MGLMapCamera, with insets: UIEdgeInsets)

    Parameters

    camera

    The new camera to be used in the projection calculation.

    insets

    The insets applied on top of the camera be used in the projection calculation.

  • Change the projection state to make the provided bounds visible with the specified inset.

    Note

    MGLMapView instance frame must not be changed since this projection is initialized, otherwise the calculation may be wrong.

    Declaration

    Objective-C

    - (void)setVisibleCoordinateBounds:(MGLCoordinateBounds)bounds
                           edgePadding:(UIEdgeInsets)insets;

    Swift

    func setVisibleCoordinateBounds(_ bounds: MGLCoordinateBounds, edgePadding insets: UIEdgeInsets)

    Parameters

    bounds

    The bounds that the viewport should fit.

    insets

    The insets applied on top of the viewport to be used in the projection calculation.

  • Converts a point in the coordinate system of the map view the projection was initialized with to the geographical coordinate.

    Declaration

    Objective-C

    - (CLLocationCoordinate2D)convertPoint:(CGPoint)point;

    Swift

    func convert(_ point: CGPoint) -> CLLocationCoordinate2D

    Parameters

    point

    The point to convert.

    Return Value

    The geographic coordinate at the given point.

  • Converts a geographic coordinate to a point in the map view’s the projection was initialized with coordinate system.

    Declaration

    Objective-C

    - (CGPoint)convertCoordinate:(CLLocationCoordinate2D)coordinate;

    Swift

    func convert(_ coordinate: CLLocationCoordinate2D) -> CGPoint

    Parameters

    coordinate

    The geographic coordinate to convert.

    Return Value

    The point corresponding to the given geographic coordinate.

  • The distance in meters spanned by a single point for the current camera.

    Declaration

    Objective-C

    @property (readonly) CLLocationDistance metersPerPoint;

    Swift

    var metersPerPoint: CLLocationDistance { get }