MGLMapView


@interface MGLMapView : NSView

An interactive, customizable map view with an interface similar to the one provided by Apple’s MapKit.

Using MGLMapView, you can embed the map inside a view, allow users to manipulate it with standard gestures, animate the map between different viewpoints, and present information in the form of annotations and overlays.

The map view loads scalable vector tiles that conform to the Mapbox Vector Tile Specification. It styles them with a style that conforms to the Mapbox Style Specification. Such styles can be designed in Mapbox Studio and hosted on mapbox.com.

A collection of Mapbox-hosted styles is available through the MGLStyle class. These basic styles use Mapbox Streets or Mapbox Satellite data sources, but you can specify a custom style that makes use of your own data.

Mapbox-hosted vector tiles and styles require an API access token, which you can obtain from the Mapbox account page. Access tokens associate requests to Mapbox’s vector tile and style APIs with your Mapbox account. They also deter other developers from using your styles without your permission.

Adding your own gesture recognizer to MGLMapView will block the corresponding gesture recognizer built into MGLMapView. To avoid conflicts, define which gesture recognizer takes precedence. For example, you can subclass NSClickGestureRecognizer and override -[NSGestureRecognizer shouldRequireFailureOfGestureRecognizer:], so that your subclass will be invoked only if the default MGLMapView click gesture recognizer fails:

class MapClickGestureRecognizer: NSClickGestureRecognizer {
    override func shouldRequireFailure(of otherGestureRecognizer: NSGestureRecognizer) -> Bool {
        return otherGestureRecognizer is NSClickGestureRecognizer
    }
}

Note

You are responsible for getting permission to use the map data and for ensuring that your use adheres to the relevant terms of use.
  • Initializes and returns a newly allocated map view with the specified frame and the default style.

    Declaration

    Objective-C

    - (nonnull instancetype)initWithFrame:(NSRect)frame;

    Swift

    init(frame: NSRect)

    Parameters

    frame

    The frame for the view, measured in points.

    Return Value

    An initialized map view.

  • Initializes and returns a newly allocated map view with the specified frame and style URL.

    Declaration

    Objective-C

    - (nonnull instancetype)initWithFrame:(NSRect)frame
                                 styleURL:(nullable NSURL *)styleURL;

    Swift

    init(frame: NSRect, styleURL: URL?)

    Parameters

    frame

    The frame for the view, measured in points.

    styleURL

    URL of the map style to display. The URL may be a full HTTP or HTTPS URL, a Mapbox URL indicating the style’s map ID (mapbox://styles/<user>/<style>), or a path to a local file relative to the application’s resource path. Specify nil for the default style.

    Return Value

    An initialized map view.

  • The receiver’s delegate.

    A map view sends messages to its delegate to notify it of changes to its contents or the viewpoint. The delegate also provides information about annotations displayed on the map, such as the styles to apply to individual annotations.

    Declaration

    Objective-C

    @property (readwrite, nonatomic, nullable) id<MGLMapViewDelegate> delegate;
  • The style currently displayed in the receiver.

    Unlike the styleURL property, this property is set to an object that allows you to manipulate every aspect of the style locally.

    If the style is loading, this property is set to nil until the style finishes loading. If the style has failed to load, this property is set to nil. Because the style loads asynchronously, you should manipulate it in the -[MGLMapViewDelegate mapView:didFinishLoadingStyle:] or -[MGLMapViewDelegate mapViewDidFinishLoadingMap:] method. It is not possible to manipulate the style before it has finished loading.

    Note

    The default styles provided by Mapbox contain sources and layers with identifiers that will change over time. Applications that use APIs that manipulate a style’s sources and layers must first set the style URL to an explicitly versioned style using a convenience method like +[MGLStyle outdoorsStyleURLWithVersion:], MGLMapView’s “Style URL” inspectable in Interface Builder, or a manually constructed NSURL.

    Declaration

    Objective-C

    @property (readonly, nonatomic, nullable) MGLStyle *style;

    Swift

    var style: MGLStyle? { get }
  • URL of the style currently displayed in the receiver.

    The URL may be a full HTTP or HTTPS URL, a Mapbox URL indicating the style’s map ID (mapbox://styles/<user>/<style>), or a path to a local file relative to the application’s resource path.

    If you set this property to nil, the receiver will use the default style and this property will automatically be set to that style’s URL.

    If you want to modify the current style without replacing it outright, or if you want to introspect individual style attributes, use the style property.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic, null_resettable) NSURL *styleURL;

    Swift

    var styleURL: URL! { get set }
  • Reloads the style.

    You do not normally need to call this method. The map view automatically responds to changes in network connectivity by reloading the style. You may need to call this method if you change the access token after a style has loaded but before loading a style associated with a different Mapbox account.

    Declaration

    Objective-C

    - (void)reloadStyle:(nonnull id)sender;

    Swift

    @IBAction func reloadStyle(_ sender: Any)
  • A control for zooming in and out, positioned in the lower-right corner.

    Declaration

    Objective-C

    @property (readonly, nonatomic) NSSegmentedControl *_Nonnull zoomControls;

    Swift

    var zoomControls: NSSegmentedControl { get }
  • A control indicating the map’s direction and allowing the user to manipulate the direction, positioned above the zoom controls in the lower-right corner.

    Declaration

    Objective-C

    @property (readonly, nonatomic) NSSlider *_Nonnull compass;

    Swift

    var compass: NSSlider { get }
  • The Mapbox logo, positioned in the lower-left corner.

    Note

    The Mapbox terms of service, which governs the use of Mapbox-hosted vector tiles and styles, requires most Mapbox customers to display the Mapbox logo. If this applies to you, do not hide this view or change its contents.

    Declaration

    Objective-C

    @property (readonly, nonatomic) NSImageView *_Nonnull logoView;

    Swift

    var logoView: NSImageView { get }
  • A view showing legally required copyright notices, positioned along the bottom of the map view, to the left of the Mapbox logo.

    Note

    The Mapbox terms of service, which governs the use of Mapbox-hosted vector tiles and styles, requires these copyright notices to accompany any map that features Mapbox-designed styles, OpenStreetMap data, or other Mapbox data such as satellite or terrain data. If that applies to this map view, do not hide this view or remove any notices from it.

    Declaration

    Objective-C

    @property (readonly, nonatomic) NSView *_Nonnull attributionView;

    Swift

    var attributionView: NSView { get }
  • The geographic coordinate at the center of the map view.

    Changing the value of this property centers the map on the new coordinate without changing the current zoom level.

    Changing the value of this property updates the map view immediately. If you want to animate the change, use the -setCenterCoordinate:animated: method instead.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic) CLLocationCoordinate2D centerCoordinate;

    Swift

    var centerCoordinate: CLLocationCoordinate2D { get set }
  • Changes the center coordinate of the map and optionally animates the change.

    Changing the center coordinate centers the map on the new coordinate without changing the current zoom level.

    Declaration

    Objective-C

    - (void)setCenterCoordinate:(CLLocationCoordinate2D)coordinate
                       animated:(BOOL)animated;

    Swift

    func setCenter(_ coordinate: CLLocationCoordinate2D, animated: Bool)

    Parameters

    coordinate

    The new center coordinate for the map.

    animated

    Specify YES if you want the map view to scroll to the new location or NO if you want the map to display the new location immediately.

  • The zoom level of the receiver.

    In addition to affecting the visual size and detail of features on the map, the zoom level affects the size of the vector tiles that are loaded. At zoom level 0, each tile covers the entire world map; at zoom level 1, it covers ¼ of the world; at zoom level 2, 116 of the world, and so on.

    Changing the value of this property updates the map view immediately. If you want to animate the change, use the -setZoomLevel:animated: method instead.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic) double zoomLevel;

    Swift

    var zoomLevel: Double { get set }
  • The minimum zoom level at which the map can be shown.

    Depending on the map view’s aspect ratio, the map view may be prevented from reaching the minimum zoom level, in order to keep the map from repeating within the current viewport.

    If the value of this property is greater than that of the maximumZoomLevel property, the behavior is undefined.

    The default value of this property is 0.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic) double minimumZoomLevel;

    Swift

    var minimumZoomLevel: Double { get set }
  • The maximum zoom level the map can be shown at.

    If the value of this property is smaller than that of the minimumZoomLevel property, the behavior is undefined.

    The default value of this property is 20.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic) double maximumZoomLevel;

    Swift

    var maximumZoomLevel: Double { get set }
  • Changes the zoom level of the map and optionally animates the change.

    Changing the zoom level scales the map without changing the current center coordinate.

    Declaration

    Objective-C

    - (void)setZoomLevel:(double)zoomLevel animated:(BOOL)animated;

    Swift

    func setZoomLevel(_ zoomLevel: Double, animated: Bool)

    Parameters

    zoomLevel

    The new zoom level for the map.

    animated

    Specify YES if you want the map view to animate the change to the new zoom level or NO if you want the map to display the new zoom level immediately.

  • The heading of the map, measured in degrees clockwise from true north.

    The value 0 means that the top edge of the map view corresponds to true north. The value 90 means the top of the map is pointing due east. The value 180 means the top of the map points due south, and so on.

    Changing the value of this property updates the map view immediately. If you want to animate the change, use the -setDirection:animated: method instead.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic) CLLocationDirection direction;

    Swift

    var direction: CLLocationDirection { get set }
  • Changes the heading of the map and optionally animates the change.

    Changing the heading rotates the map without changing the current center coordinate or zoom level.

    Declaration

    Objective-C

    - (void)setDirection:(CLLocationDirection)direction animated:(BOOL)animated;

    Swift

    func setDirection(_ direction: CLLocationDirection, animated: Bool)

    Parameters

    direction

    The heading of the map, measured in degrees clockwise from true north.

    animated

    Specify YES if you want the map view to animate the change to the new heading or NO if you want the map to display the new heading immediately.

  • A camera representing the current viewpoint of the map.

    Declaration

    Objective-C

    @property (readwrite, copy, nonatomic) MGLMapCamera *_Nonnull camera;

    Swift

    @NSCopying var camera: MGLMapCamera { get set }
  • Moves the viewpoint to a different location with respect to the map with an optional transition animation.

    Declaration

    Objective-C

    - (void)setCamera:(nonnull MGLMapCamera *)camera animated:(BOOL)animated;

    Swift

    func setCamera(_ camera: MGLMapCamera, animated: Bool)

    Parameters

    camera

    The new viewpoint.

    animated

    Specify YES if you want the map view to animate the change to the new viewpoint or NO if you want the map to display the new viewpoint immediately.

  • Moves the viewpoint to a different location with respect to the map with an optional transition duration and timing function.

    Declaration

    Objective-C

    - (void)setCamera:(nonnull MGLMapCamera *)camera
                   withDuration:(NSTimeInterval)duration
        animationTimingFunction:(nullable CAMediaTimingFunction *)function
              completionHandler:(nullable void (^)(void))completion;

    Swift

    func setCamera(_ camera: MGLMapCamera, withDuration duration: TimeInterval, animationTimingFunction function: CAMediaTimingFunction?, completionHandler completion: (() -> Void)? = nil)

    Parameters

    camera

    The new viewpoint.

    duration

    The amount of time, measured in seconds, that the transition animation should take. Specify 0 to jump to the new viewpoint instantaneously.

    function

    A timing function used for the animation. Set this parameter to nil for a transition that matches most system animations. If the duration is 0, this parameter is ignored.

    completion

    The block to execute after the animation finishes.

  • Moves the viewpoint to a different location using a transition animation that evokes powered flight and a default duration based on the length of the flight path.

    The transition animation seamlessly incorporates zooming and panning to help the user find his or her bearings even after traversing a great distance.

    Declaration

    Objective-C

    - (void)flyToCamera:(nonnull MGLMapCamera *)camera
        completionHandler:(nullable void (^)(void))completion;

    Swift

    func fly(to camera: MGLMapCamera, completionHandler completion: (() -> Void)? = nil)

    Parameters

    camera

    The new viewpoint.

    completion

    The block to execute after the animation finishes.

  • Moves the viewpoint to a different location using a transition animation that evokes powered flight and an optional transition duration.

    The transition animation seamlessly incorporates zooming and panning to help the user find his or her bearings even after traversing a great distance.

    Declaration

    Objective-C

    - (void)flyToCamera:(nonnull MGLMapCamera *)camera
             withDuration:(NSTimeInterval)duration
        completionHandler:(nullable void (^)(void))completion;

    Swift

    func fly(to camera: MGLMapCamera, withDuration duration: TimeInterval, completionHandler completion: (() -> Void)? = nil)

    Parameters

    camera

    The new viewpoint.

    duration

    The amount of time, measured in seconds, that the transition animation should take. Specify 0 to jump to the new viewpoint instantaneously. Specify a negative value to use the default duration, which is based on the length of the flight path.

    completion

    The block to execute after the animation finishes.

  • Moves the viewpoint to a different location using a transition animation that evokes powered flight and an optional transition duration and peak altitude.

    The transition animation seamlessly incorporates zooming and panning to help the user find his or her bearings even after traversing a great distance.

    Declaration

    Objective-C

    - (void)flyToCamera:(nonnull MGLMapCamera *)camera
             withDuration:(NSTimeInterval)duration
             peakAltitude:(CLLocationDistance)peakAltitude
        completionHandler:(nullable void (^)(void))completion;

    Swift

    func fly(to camera: MGLMapCamera, withDuration duration: TimeInterval, peakAltitude: CLLocationDistance, completionHandler completion: (() -> Void)? = nil)

    Parameters

    camera

    The new viewpoint.

    duration

    The amount of time, measured in seconds, that the transition animation should take. Specify 0 to jump to the new viewpoint instantaneously. Specify a negative value to use the default duration, which is based on the length of the flight path.

    peakAltitude

    The altitude, measured in meters, at the midpoint of the animation. The value of this parameter is ignored if it is negative or if the animation transition resulting from a similar call to -setCamera:animated: would have a midpoint at a higher altitude.

    completion

    The block to execute after the animation finishes.

  • The geographic coordinate bounds visible in the receiver’s viewport.

    Changing the value of this property updates the receiver immediately. If you want to animate the change, use the -setVisibleCoordinateBounds:animated: method instead.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic)
        MGLCoordinateBounds visibleCoordinateBounds;

    Swift

    var visibleCoordinateBounds: Int32 { get set }
  • Changes the receiver’s viewport to fit the given coordinate bounds, optionally animating the change.

    Declaration

    Objective-C

    - (void)setVisibleCoordinateBounds:(MGLCoordinateBounds)bounds
                              animated:(BOOL)animated;

    Swift

    func setVisibleCoordinateBounds(_ bounds: Any!, animated: Bool)

    Parameters

    bounds

    The bounds that the viewport will show in its entirety.

    animated

    Specify YES to animate the change by smoothly scrolling and zooming or NO to immediately display the given bounds.

  • Changes the receiver’s viewport to fit the given coordinate bounds and optionally some additional padding on each side.

    Declaration

    Objective-C

    - (void)setVisibleCoordinateBounds:(MGLCoordinateBounds)bounds
                           edgePadding:(NSEdgeInsets)insets
                              animated:(BOOL)animated;

    Swift

    func setVisibleCoordinateBounds(_ bounds: Any!, edgePadding insets: EdgeInsets, animated: Bool)

    Parameters

    bounds

    The bounds that the viewport will show in its entirety.

    insets

    The minimum padding (in screen points) that will be visible around the given coordinate bounds.

    animated

    Specify YES to animate the change by smoothly scrolling and zooming or NO to immediately display the given bounds.

  • Sets the visible region so that the map displays the specified annotations.

    Calling this method updates the value in the visibleCoordinateBounds property and potentially other properties to reflect the new map region. A small amount of padding is reserved around the edges of the map view. To specify a different amount of padding, use the -showAnnotations:edgePadding:animated: method.

    Declaration

    Objective-C

    - (void)showAnnotations:(nonnull NSArray<id<MGLAnnotation>> *)annotations
                   animated:(BOOL)animated;

    Swift

    func showAnnotations(_ annotations: Any!, animated: Bool)

    Parameters

    annotations

    The annotations that you want to be visible in the map.

    animated

    YES if you want the map region change to be animated, or NO if you want the map to display the new region immediately without animations.

  • Sets the visible region so that the map displays the specified annotations with the specified amount of padding on each side.

    Calling this method updates the value in the visibleCoordinateBounds property and potentially other properties to reflect the new map region.

    Declaration

    Objective-C

    - (void)showAnnotations:(nonnull NSArray<id<MGLAnnotation>> *)annotations
                edgePadding:(NSEdgeInsets)insets
                   animated:(BOOL)animated;

    Swift

    func showAnnotations(_ annotations: Any!, edgePadding insets: EdgeInsets, animated: Bool)

    Parameters

    annotations

    The annotations that you want to be visible in the map.

    insets

    The minimum padding (in screen points) around the edges of the map view to keep clear of annotations.

    animated

    YES if you want the map region change to be animated, or NO if you want the map to display the new region immediately without animations.

  • Returns the camera that best fits the given coordinate bounds.

    Declaration

    Objective-C

    - (nonnull MGLMapCamera *)cameraThatFitsCoordinateBounds:
        (MGLCoordinateBounds)bounds;

    Swift

    func cameraThatFitsCoordinateBounds(_ bounds: Any!) -> MGLMapCamera

    Parameters

    bounds

    The coordinate bounds to fit to the receiver’s viewport.

    Return Value

    A camera object centered on the same location as the coordinate bounds with zoom level as high (close to the ground) as possible while still including the entire coordinate bounds. The camera object uses the current direction and pitch.

  • Returns the camera that best fits the given coordinate bounds, optionally with some additional padding on each side.

    Declaration

    Objective-C

    - (nonnull MGLMapCamera *)cameraThatFitsCoordinateBounds:
                                  (MGLCoordinateBounds)bounds
                                                 edgePadding:(NSEdgeInsets)insets;

    Swift

    func cameraThatFitsCoordinateBounds(_ bounds: Any!, edgePadding insets: EdgeInsets) -> MGLMapCamera

    Parameters

    bounds

    The coordinate bounds to fit to the receiver’s viewport.

    insets

    The minimum padding (in screen points) that would be visible around the returned camera object if it were set as the receiver’s camera.

    Return Value

    A camera object centered on the same location as the coordinate bounds with zoom level as high (close to the ground) as possible while still including the entire coordinate bounds. The camera object uses the current direction and pitch.

  • A Boolean value indicating whether the receiver automatically adjusts its content insets.

    When the value of this property is YES, the map view automatically updates its contentInsets property to account for any overlapping title bar or toolbar. To overlap with the title bar or toolbar, the containing window’s style mask must have NSFullSizeContentViewWindowMask set, and the title bar must not be transparent.

    The default value of this property is YES.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic) BOOL automaticallyAdjustsContentInsets;

    Swift

    var automaticallyAdjustsContentInsets: Bool { get set }
  • The distance from the edges of the map view’s frame to the edges of the map view’s logical viewport.

    When the value of this property is equal to NSEdgeInsetsZero, viewport properties such as centerCoordinate assume a viewport that matches the map view’s frame. Otherwise, those properties are inset, excluding part of the frame from the viewport. For instance, if the only the top edge is inset, the map center is effectively shifted downward.

    When the value of the automaticallyAdjustsContentInsets property is YES, the value of this property may be overridden at any time.

    Changing the value of this property updates the map view immediately. If you want to animate the change, use the -setContentInsets:animated: method instead.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic) NSEdgeInsets contentInsets;

    Swift

    var contentInsets: EdgeInsets { get set }
  • Sets the distance from the edges of the map view’s frame to the edges of the map view’s logical viewport, with an optional transition animation.

    When the value of this property is equal to NSEdgeInsetsZero, viewport properties such as centerCoordinate assume a viewport that matches the map view’s frame. Otherwise, those properties are inset, excluding part of the frame from the viewport. For instance, if the only the top edge is inset, the map center is effectively shifted downward.

    When the value of the automaticallyAdjustsContentInsets property is YES, the value of this property may be overridden at any time.

    Declaration

    Objective-C

    - (void)setContentInsets:(NSEdgeInsets)contentInsets animated:(BOOL)animated;

    Swift

    func setContentInsets(_ contentInsets: EdgeInsets, animated: Bool)

    Parameters

    contentInsets

    The new values to inset the content by.

    animated

    Specify YES if you want the map view to animate the change to the content insets or NO if you want the map to inset the content immediately.

  • A Boolean value that determines whether the user may zoom the map in and out, changing the zoom level.

    When this property is set to YES, the default, the user may zoom the map in and out by pinching two fingers, by using a scroll wheel on a traditional mouse, or by dragging the mouse cursor up and down while holding down the Shift key. When the receiver has focus, the user may also zoom by pressing the up and down arrow keys while holding down the Option key.

    This property controls only user interactions with the map. If you set the value of this property to NO, you may still change the map zoom programmatically.

    Declaration

    Objective-C

    @property (getter=isZoomEnabled, assign, readwrite, nonatomic) BOOL zoomEnabled;

    Swift

    var isZoomEnabled: Bool { get set }
  • A Boolean value that determines whether the user may scroll around the map, changing the center coordinate.

    When this property is set to YES, the default, the user may scroll the map by swiping with two fingers or dragging the mouse cursor. When the receiver has focus, the user may also scroll around the map by pressing the arrow keys.

    This property controls only user interactions with the map. If you set the value of this property to NO, you may still change the map location programmatically.

    Declaration

    Objective-C

    @property (getter=isScrollEnabled, assign, readwrite, nonatomic)
        BOOL scrollEnabled;

    Swift

    var isScrollEnabled: Bool { get set }
  • A Boolean value that determines whether the user may rotate the map, changing the direction.

    When this property is set to YES, the default, the user may rotate the map by moving two fingers in a circular motion or by dragging the mouse cursor left and right while holding down the Option key. When the receiver has focus, the user may also zoom by pressing the left and right arrow keys while holding down the Option key.

    This property controls only user interactions with the map. If you set the value of this property to NO, you may still rotate the map programmatically.

    Declaration

    Objective-C

    @property (getter=isRotateEnabled, assign, readwrite, nonatomic)
        BOOL rotateEnabled;

    Swift

    var isRotateEnabled: Bool { get set }
  • A Boolean value that determines whether the user may tilt of the map, changing the pitch.

    When this property is set to YES, the default, the user may rotate the map by dragging the mouse cursor up and down while holding down the Option key.

    This property controls only user interactions with the map. If you set the value of this property to NO, you may still change the pitch of the map programmatically.

    Declaration

    Objective-C

    @property (getter=isPitchEnabled, assign, readwrite, nonatomic)
        BOOL pitchEnabled;

    Swift

    var isPitchEnabled: Bool { get set }
  • The complete list of annotations associated with the receiver. (read-only)

    The objects in this array must adopt the MGLAnnotation protocol. If no annotations are associated with the map view, the value of this property is nil.

    Declaration

    Objective-C

    @property (readonly, nonatomic, nullable)
        NSArray<id<MGLAnnotation>> *annotations;
  • Adds an annotation to the map view.

    Note

    MGLMultiPolyline, MGLMultiPolygon, and MGLShapeCollection objects cannot be added to the map view at this time. Nor can MGLMultiPoint objects that are not instances of MGLPolyline or MGLPolygon. Any multipoint, multipolyline, multipolygon, or shape collection object that is specified is silently ignored.

    Declaration

    Objective-C

    - (void)addAnnotation:(nonnull id<MGLAnnotation>)annotation;

    Parameters

    annotation

    The annotation object to add to the receiver. This object must conform to the MGLAnnotation protocol. The map view retains the annotation object.

  • Adds an array of annotations to the map view.

    Note

    MGLMultiPolyline, MGLMultiPolygon, and MGLShapeCollection objects cannot be added to the map view at this time. Nor can MGLMultiPoint objects that are not instances of MGLPolyline or MGLPolygon. Any multipoint, multipolyline, multipolygon, or shape collection objects that are specified are silently ignored.

    Declaration

    Objective-C

    - (void)addAnnotations:(nonnull NSArray<id<MGLAnnotation>> *)annotations;

    Swift

    func addAnnotations(_ annotations: Any!)

    Parameters

    annotations

    An array of annotation objects. Each object in the array must conform to the MGLAnnotation protocol. The map view retains each individual annotation object.

  • The complete list of annotations associated with the receiver that are currently visible.

    The objects in this array must adopt the MGLAnnotation protocol. If no annotations are associated with the map view or if no annotations associated with the map view are currently visible, the value of this property is nil.

    Declaration

    Objective-C

    @property (readonly, nonatomic, nullable)
        NSArray<id<MGLAnnotation>> *visibleAnnotations;
  • Removes an annotation from the map view, deselecting it if it is selected.

    Removing an annotation object dissociates it from the map view entirely, preventing it from being displayed on the map. Thus you would typically call this method only when you want to hide or delete a given annotation.

    Declaration

    Objective-C

    - (void)removeAnnotation:(nonnull id<MGLAnnotation>)annotation;

    Parameters

    annotation

    The annotation object to remove. This object must conform to the MGLAnnotation protocol.

  • Removes an array of annotations from the map view, deselecting any selected annotations in the array.

    Removing annotation objects dissociates them from the map view entirely, preventing them from being displayed on the map. Thus you would typically call this method only when you want to hide or delete the given annotations.

    Declaration

    Objective-C

    - (void)removeAnnotations:(nonnull NSArray<id<MGLAnnotation>> *)annotations;

    Swift

    func removeAnnotations(_ annotations: Any!)

    Parameters

    annotations

    The array of annotation objects to remove. Objects in the array must conform to the MGLAnnotation protocol.

  • Returns a reusable annotation image object associated with its identifier.

    For performance reasons, you should generally reuse MGLAnnotationImage objects for identical-looking annotations in your map views. Dequeueing saves time and memory during performance-critical operations such as scrolling.

    Declaration

    Objective-C

    - (nullable MGLAnnotationImage *)dequeueReusableAnnotationImageWithIdentifier:
        (nonnull NSString *)identifier;

    Swift

    func dequeueReusableAnnotationImage(withIdentifier identifier: String) -> MGLAnnotationImage?

    Parameters

    identifier

    A string identifying the annotation image to be reused. This string is the same one you specify when initially returning the annotation image object using the -mapView:imageForAnnotation: method.

    Return Value

    An annotation image object with the given identifier, or nil if no such object exists in the reuse queue.

  • Returns the list of annotations associated with the receiver that intersect with the given rectangle.

    Declaration

    Objective-C

    - (nullable NSArray<id<MGLAnnotation>> *)visibleAnnotationsInRect:(CGRect)rect;

    Swift

    func visibleAnnotations(in rect: CGRect) -> Any!

    Parameters

    rect

    A rectangle expressed in the map view’s coordinate system.

    Return Value

    An array of objects that adopt the MGLAnnotation protocol or nil if no annotations associated with the map view are currently visible in the rectangle.

  • The currently selected annotations.

    Assigning a new array to this property selects only the first annotation in the array.

    Declaration

    Objective-C

    @property (readwrite, copy, nonatomic)
        NSArray<id<MGLAnnotation>> *_Nonnull selectedAnnotations;
  • Selects an annotation and displays a callout popover for it.

    If the given annotation is not visible within the current viewport, this method has no effect.

    Declaration

    Objective-C

    - (void)selectAnnotation:(nonnull id<MGLAnnotation>)annotation;

    Parameters

    annotation

    The annotation object to select.

  • Deselects an annotation and hides its callout popover.

    Declaration

    Objective-C

    - (void)deselectAnnotation:(nullable id<MGLAnnotation>)annotation;

    Parameters

    annotation

    The annotation object to deselect.

  • A common view controller for managing a callout popover’s content view.

    Like any instance of NSPopover, an annotation callout manages its contents with a view controller. The annotation object is the view controller’s represented object. This means that you can bind controls in the view controller’s content view to KVO-compliant properties of the annotation object, such as title and subtitle.

    This property defines a common view controller that is used for every annotation’s callout view. If you set this property to nil, a default view controller will be used that manages a simple title label and subtitle label. If you need distinct view controllers for different annotations, the map view’s delegate should implement -mapView:calloutViewControllerForAnnotation: instead.

    Declaration

    Objective-C

    @property (readwrite, strong, nonatomic, null_resettable)
        NSViewController *calloutViewController;

    Swift

    @IBOutlet var calloutViewController: NSViewController! { get set }
  • Returns a point annotation located at the given point.

    Declaration

    Objective-C

    - (nonnull id<MGLAnnotation>)annotationAtPoint:(NSPoint)point;

    Parameters

    point

    A point in the view’s coordinate system.

    Return Value

    A point annotation whose annotation image coincides with the point. If multiple point annotations coincide with the point, the return value is the annotation that would be selected if the user clicks at this point.

  • Adds a single overlay to the map.

    To remove an overlay from a map, use the -removeOverlay: method.

    Declaration

    Objective-C

    - (void)addOverlay:(nonnull id<MGLOverlay>)overlay;

    Parameters

    overlay

    The overlay object to add. This object must conform to the MGLOverlay protocol.

  • Adds an array of overlays to the map.

    To remove multiple overlays from a map, use the -removeOverlays: method.

    Declaration

    Objective-C

    - (void)addOverlays:(nonnull NSArray<id<MGLOverlay>> *)overlays;

    Swift

    func addOverlays(_ overlays: Any!)

    Parameters

    overlays

    An array of objects, each of which must conform to the MGLOverlay protocol.

  • Removes a single overlay from the map.

    If the specified overlay is not currently associated with the map view, this method does nothing.

    Declaration

    Objective-C

    - (void)removeOverlay:(nonnull id<MGLOverlay>)overlay;

    Parameters

    overlay

    The overlay object to remove.

  • Removes an array of overlays from the map.

    If a given overlay object is not associated with the map view, it is ignored.

    Declaration

    Objective-C

    - (void)removeOverlays:(nonnull NSArray<id<MGLOverlay>> *)overlays;

    Swift

    func removeOverlays(_ overlays: Any!)

    Parameters

    overlays

    An array of objects, each of which conforms to the MGLOverlay protocol.

  • Returns an array of rendered map features that intersect with a given point.

    This method may return features from any of the map’s style layers. To restrict the search to a particular layer or layers, use the -visibleFeaturesAtPoint:inStyleLayersWithIdentifiers: method. For more information about searching for map features, see that method’s documentation.

    Declaration

    Objective-C

    - (nonnull NSArray<id<MGLFeature>> *)visibleFeaturesAtPoint:(NSPoint)point;

    Swift

    func visibleFeatures(at point: NSPoint) -> Any!

    Parameters

    point

    A point expressed in the map view’s coordinate system.

    Return Value

    An array of objects conforming to the MGLFeature protocol that represent features in the sources used by the current style.

  • Returns an array of rendered map features that intersect with a given point, restricted to the given style layers.

    This method returns all the intersecting features from the specified layers. To filter the returned features, use the -visibleFeaturesAtPoint:inStyleLayersWithIdentifiers:predicate: method. For more information about searching for map features, see that method’s documentation.

    Declaration

    Objective-C

    - (nonnull NSArray<id<MGLFeature>> *)visibleFeaturesAtPoint:(NSPoint)point
                                   inStyleLayersWithIdentifiers:
                                       (nullable NSSet<NSString *> *)
                                           styleLayerIdentifiers;

    Swift

    func visibleFeatures(at point: NSPoint, styleLayerIdentifiers: Any!) -> Any!

    Parameters

    point

    A point expressed in the map view’s coordinate system.

    styleLayerIdentifiers

    A set of strings that correspond to the names of layers defined in the current style. Only the features contained in these layers are included in the returned array.

    Return Value

    An array of objects conforming to the MGLFeature protocol that represent features in the sources used by the current style.

  • Returns an array of rendered map features that intersect with a given point, restricted to the given style layers and filtered by the given predicate.

    Each object in the returned array represents a feature rendered by the current style and provides access to attributes specified by the relevant map content sources. The returned array includes features loaded by MGLShapeSource and MGLVectorSource objects but does not include anything from MGLRasterSource objects, or from image, video, or canvas sources, which are unsupported by this SDK.

    The returned features are drawn by a style layer in the current style. For example, suppose the current style uses the Mapbox Streets source, but none of the specified style layers includes features that have the maki property set to bus. If you pass a point corresponding to the location of a bus stop into this method, the bus stop feature does not appear in the resulting array. On the other hand, if the style does include bus stops, an MGLFeature object representing that bus stop is returned and its attributes dictionary has the maki key set to bus (along with other attributes). The dictionary contains only the attributes provided by the tile source; it does not include computed attribute values or rules about how the feature is rendered by the current style.

    The returned array is sorted by z-order, starting with the topmost rendered feature and ending with the bottommost rendered feature. A feature that is rendered multiple times due to wrapping across the antimeridian at low zoom levels is included only once, subject to the caveat that follows.

    Features come from tiled vector data or GeoJSON data that is converted to tiles internally, so feature geometries are clipped at tile boundaries and features may appear duplicated across tiles. For example, suppose the specified point lies along a road that spans the screen. The resulting array includes those parts of the road that lie within the map tile that contain the specified point, even if the road extends into other tiles.

    To find out the layer names in a particular style, view the style in Mapbox Studio.

    Only visible features are returned. To obtain features regardless of visibility, use the -[MGLVectorSource featuresInSourceLayersWithIdentifiers:predicate:] and -[MGLShapeSource featuresMatchingPredicate:] methods on the relevant sources.

    Note

    Layer identifiers are not guaranteed to exist across styles or different versions of the same style. Applications that use this API must first set the style URL to an explicitly versioned style using a convenience method like +[MGLStyle outdoorsStyleURLWithVersion:], MGLMapView’s “Style URL” inspectable in Interface Builder, or a manually constructed NSURL. This approach also avoids layer identifer name changes that will occur in the default style’s layers over time.

    Declaration

    Objective-C

    - (nonnull NSArray<id<MGLFeature>> *)
          visibleFeaturesAtPoint:(NSPoint)point
    inStyleLayersWithIdentifiers:(nullable NSSet<NSString *> *)styleLayerIdentifiers
                       predicate:(nullable NSPredicate *)predicate;

    Swift

    func visibleFeatures(at point: NSPoint, styleLayerIdentifiers: Any!, predicate: NSPredicate?) -> Any!

    Parameters

    point

    A point expressed in the map view’s coordinate system.

    styleLayerIdentifiers

    A set of strings that correspond to the names of layers defined in the current style. Only the features contained in these layers are included in the returned array.

    predicate

    A predicate to filter the returned features.

    Return Value

    An array of objects conforming to the MGLFeature protocol that represent features in the sources used by the current style.

  • Returns an array of rendered map features that intersect with the given rectangle.

    This method may return features from any of the map’s style layers. To restrict the search to a particular layer or layers, use the -visibleFeaturesAtPoint:inStyleLayersWithIdentifiers: method. For more information about searching for map features, see that method’s documentation.

    Declaration

    Objective-C

    - (nonnull NSArray<id<MGLFeature>> *)visibleFeaturesInRect:(NSRect)rect;

    Swift

    func visibleFeatures(in rect: NSRect) -> Any!

    Parameters

    rect

    A rectangle expressed in the map view’s coordinate system.

    Return Value

    An array of objects conforming to the MGLFeature protocol that represent features in the sources used by the current style.

  • Returns an array of rendered map features that intersect with the given rectangle, restricted to the given style layers.

    This method returns all the intersecting features from the specified layers. To filter the returned features, use the -visibleFeaturesAtPoint:inStyleLayersWithIdentifiers:predicate: method. For more information about searching for map features, see that method’s documentation.

    Declaration

    Objective-C

    - (nonnull NSArray<id<MGLFeature>> *)visibleFeaturesInRect:(NSRect)rect
                                  inStyleLayersWithIdentifiers:
                                      (nullable NSSet<NSString *> *)
                                          styleLayerIdentifiers;

    Swift

    func visibleFeatures(at rect: NSRect, styleLayerIdentifiers: Any!) -> Any!

    Parameters

    rect

    A rectangle expressed in the map view’s coordinate system.

    styleLayerIdentifiers

    A set of strings that correspond to the names of layers defined in the current style. Only the features contained in these layers are included in the returned array.

    Return Value

    An array of objects conforming to the MGLFeature protocol that represent features in the sources used by the current style.

  • Returns an array of rendered map features that intersect with the given rectangle, restricted to the given style layers and filtered by the given predicate.

    Each object in the returned array represents a feature rendered by the current style and provides access to attributes specified by the relevant map content sources. The returned array includes features loaded by MGLShapeSource and MGLVectorSource objects but does not include anything from MGLRasterSource objects, or from image, video, or canvas sources, which are unsupported by this SDK.

    The returned features are drawn by a style layer in the current style. For example, suppose the current style uses the Mapbox Streets source, but none of the specified style layers includes features that have the maki property set to bus. If you pass a rectangle containing the location of a bus stop into this method, the bus stop feature does not appear in the resulting array. On the other hand, if the style does include bus stops, an MGLFeature object representing that bus stop is returned and its attributes dictionary has the maki key set to bus (along with other attributes). The dictionary contains only the attributes provided by the tile source; it does not include computed attribute values or rules about how the feature is rendered by the current style.

    The returned array is sorted by z-order, starting with the topmost rendered feature and ending with the bottommost rendered feature. A feature that is rendered multiple times due to wrapping across the antimeridian at low zoom levels is included only once, subject to the caveat that follows.

    Features come from tiled vector data or GeoJSON data that is converted to tiles internally, so feature geometries are clipped at tile boundaries and features may appear duplicated across tiles. For example, suppose the specified rectangle intersects with a road that spans the screen. The resulting array includes those parts of the road that lie within the map tiles covering the specified rectangle, even if the road extends into other tiles. The portion of the road within each map tile is included individually.

    To find out the layer names in a particular style, view the style in Mapbox Studio.

    Only visible features are returned. To obtain features regardless of visibility, use the -[MGLVectorSource featuresInSourceLayersWithIdentifiers:predicate:] and -[MGLShapeSource featuresMatchingPredicate:] methods on the relevant sources.

    Note

    Layer identifiers are not guaranteed to exist across styles or different versions of the same style. Applications that use this API must first set the style URL to an explicitly versioned style using a convenience method like +[MGLStyle outdoorsStyleURLWithVersion:], MGLMapView’s “Style URL” inspectable in Interface Builder, or a manually constructed NSURL. This approach also avoids layer identifer name changes that will occur in the default style’s layers over time.

    Declaration

    Objective-C

    - (nonnull NSArray<id<MGLFeature>> *)
           visibleFeaturesInRect:(NSRect)rect
    inStyleLayersWithIdentifiers:(nullable NSSet<NSString *> *)styleLayerIdentifiers
                       predicate:(nullable NSPredicate *)predicate;

    Swift

    func visibleFeatures(in rect: NSRect, styleLayerIdentifiers: Any!, predicate: NSPredicate?) -> Any!

    Parameters

    rect

    A rectangle expressed in the map view’s coordinate system.

    styleLayerIdentifiers

    A set of strings that correspond to the names of layers defined in the current style. Only the features contained in these layers are included in the returned array.

    predicate

    A predicate to filter the returned features.

    Return Value

    An array of objects conforming to the MGLFeature protocol that represent features in the sources used by the current style.

  • Converts a geographic coordinate to a point in the given view’s coordinate system.

    Declaration

    Objective-C

    - (NSPoint)convertCoordinate:(CLLocationCoordinate2D)coordinate
                   toPointToView:(nullable NSView *)view;

    Swift

    func convert(_ coordinate: CLLocationCoordinate2D, toPointTo view: NSView?) -> NSPoint

    Parameters

    coordinate

    The geographic coordinate to convert.

    view

    The view in whose coordinate system the returned point should be expressed. If this parameter is nil, the returned point is expressed in the window’s coordinate system. If view is not nil, it must belong to the same window as the map view.

    Return Value

    The point (in the appropriate view or window coordinate system) corresponding to the given geographic coordinate.

  • Converts a point in the given view’s coordinate system to a geographic coordinate.

    Declaration

    Objective-C

    - (CLLocationCoordinate2D)convertPoint:(NSPoint)point
                      toCoordinateFromView:(nullable NSView *)view;

    Swift

    func convert(_ point: NSPoint, toCoordinateFrom view: NSView?) -> CLLocationCoordinate2D

    Parameters

    point

    The point to convert.

    view

    The view in whose coordinate system the point is expressed.

    Return Value

    The geographic coordinate at the given point.

  • Converts a geographic bounding box to a rectangle in the given view’s coordinate system.

    Declaration

    Objective-C

    - (NSRect)convertCoordinateBounds:(MGLCoordinateBounds)bounds
                         toRectToView:(nullable NSView *)view;

    Swift

    func convertCoordinateBounds(_ bounds: Any!, toRectTo view: NSView?) -> NSRect

    Parameters

    bounds

    The geographic bounding box to convert.

    view

    The view in whose coordinate system the returned rectangle should be expressed. If this parameter is nil, the returned rectangle is expressed in the window’s coordinate system. If view is not nil, it must belong to the same window as the map view.

  • Converts a rectangle in the given view’s coordinate system to a geographic bounding box.

    Declaration

    Objective-C

    - (MGLCoordinateBounds)convertRect:(NSRect)rect
            toCoordinateBoundsFromView:(nullable NSView *)view;

    Swift

    func convert(_ rect: NSRect, toCoordinateBoundsFrom view: NSView?) -> Any!

    Parameters

    rect

    The rectangle to convert.

    view

    The view in whose coordinate system the rectangle is expressed.

    Return Value

    The geographic bounding box coextensive with the given rectangle.

  • Returns the distance spanned by one point in the map view’s coordinate system at the given latitude and current zoom level.

    The distance between points decreases as the latitude approaches the poles. This relationship parallels the relationship between longitudinal coordinates at different latitudes.

    Declaration

    Objective-C

    - (CLLocationDistance)metersPerPointAtLatitude:(CLLocationDegrees)latitude;

    Swift

    func metersPerPoint(atLatitude latitude: CLLocationDegrees) -> CLLocationDistance

    Parameters

    latitude

    The latitude of the geographic coordinate represented by the point.

    Return Value

    The distance in meters spanned by a single point.

  • Opens one or more webpages in the default Web browser in which the user can provide feedback about the map data.

    You should add a menu item to the Help menu of your application that invokes this method. Title it “Improve This Map” or similar. Set its target to the first responder and its action to giveFeedback:.

    This map view searches the current style’s sources for webpages to open. Specifically, each source’s tile set has an attribution property containing HTML code; if an <a> tag (link) within that code has an class attribute set to mapbox-improve-map, its href attribute defines the URL to open. Such links are omitted from the attribution view.

    Declaration

    Objective-C

    - (void)giveFeedback:(nonnull id)sender;

    Swift

    @IBAction func giveFeedback(_ sender: Any)
  • The options that determine which debugging aids are shown on the map.

    These options are all disabled by default and should remain disabled in released software for performance and aesthetic reasons.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic) MGLMapDebugMaskOptions debugMask;

    Swift

    var debugMask: Int32 { get set }