MapboxMap

MapboxMap provides access to the map model, including the camera, style, observable map events, and querying rendered features. Obtain the MapboxMap instance for a MapView via MapView.mapboxMap.

Important

MapboxMap should only be used from the main thread.
  • The style object supports run time styling.

  • Triggers a repaint of the map. Calling this method is typically unnecessary but may be needed if using a custom layer that needs to be redrawn independently of other map changes.

  • When loading a map, if prefetchZoomDelta is set to any number greater than 0, the map will first request a tile for zoom - prefetchZoomDelta in an attempt to display a full map at lower resolution as quick as possible.

    It will get clamped at the tile source minimum zoom. The default delta is 4.

  • The memory budget hint to be used by the map. The budget can be given in tile units or in megabytes. A Map will do its best to keep the memory allocations for non-essential resources within the budget.

    The memory budget distribution and resource eviction logic is subject to change. Current implementation sets a memory budget hint per data source.

    If nil is set, the memory budget in tile units will be dynamically calculated based on the current viewport size.

  • Enables or disables the experimental render cache feature.

    Render cache is an experimental feature aiming to reduce resource usage of map rendering by caching intermediate rendering results of tiles into specific cache textures for reuse between frames. Performance benefit of the cache depends on the style as not all layers are cacheable due to e.g. viewport aligned features. Render cache always prefers quality over performance.

  • Defines whether multiple copies of the world will be rendered side by side beyond -180 and 180 degrees longitude.

    If disabled, when the map is zoomed out far enough that a single representation of the world does not fill the map’s entire container, there will be blank space beyond 180 and -180 degrees longitude. In this case, features that cross 180 and -180 degrees longitude will be cut in two (with one portion on the right edge of the map and the other on the left edge of the map) at every zoom level.

    By default, shouldRenderWorldCopies is set to true.

  • Gets the resource options for the map.

    All optional fields of the returned object are initialized with the actual values.

    Note

    The result of this property is different from the ResourceOptions that were provided to the map’s initializer.
  • Clears temporary map data.

    Clears temporary map data from the data path defined in the given resource options. Useful to reduce the disk usage or in case the disk cache contains invalid data.

    Note

    Calling this API will affect all maps that use the same data path and does not affect persistent map data like offline style packages.

  • Gets elevation for the given coordinate.

    Note

    Elevation is only available for the visible region on the screen.

  • The array of MapDebugOptions. Setting this property to an empty array disables previously enabled MapDebugOptions. The default value is an empty array.

  • Returns the map’s options

  • Calculates a CameraOptions to fit a CoordinateBounds

    This API isn’t supported by Globe projection.

  • Calculates a CameraOptions to fit a list of coordinates into a sub-rect of the map.

    Adjusts the zoom of camera to fit coordinates into rect.

    Returns the provided camera with zoom adjusted to fit coordinates into rect, so that the coordinates on the left, top and right of the effective camera center at the principal point of the projection (defined by padding) fit into the rect.

    This API isn’t supported by Globe projection.

    Note

    This method may fail if the principal point of the projection is not inside rect or if there is insufficient screen space, defined by principal point and rect, to fit the geometry.

  • Converts a point in the mapView’s coordinate system to a geographic coordinate. The point must exist in the coordinate space of the MapView

    This API isn’t supported by Globe projection.

  • Converts a map coordinate to a CGPoint, relative to the MapView.

    This API isn’t supported by Globe projection.

  • Converts map coordinates to an array of CGPoint, relative to the MapView.

    This API isn’t supported by Globe projection.

  • Converts points in the mapView’s coordinate system to geographic coordinates. The points must exist in the coordinate space of the MapView.

    This API isn’t supported by Globe projection.

  • Changes the map view by any combination of center, zoom, bearing, and pitch, without an animated transition. The map will retain its current values for any details not passed via the camera options argument. It is not guaranteed that the provided CameraOptions will be set, the map may apply constraints resulting in a different CameraState.

    Important

    This method does not cancel existing animations. Call CameraAnimationsManager.cancelAnimations()to cancel existing animations.

  • Returns the current camera state

  • Sets/get the map view with the free camera options.

    FreeCameraOptions provides more direct access to the underlying camera entity. For backwards compatibility the state set using this API must be representable with CameraOptions as well. Parameters are clamped to a valid range or discarded as invalid if the conversion to the pitch and bearing presentation is ambiguous. For example orientation can be invalid if it leads to the camera being upside down or the quaternion has zero length.

  • Returns the bounds of the map.

  • Sets the bounds of the map.

    Throws

    MapError
  • Prepares the drag gesture to use the provided screen coordinate as a pivot point. This function should be called each time when user starts a dragging action (e.g. by clicking on the map). The following dragging will be relative to the pivot.

  • Calculates target point where camera should move after drag. The method should be called after dragStart and before dragEnd.

  • Ends the ongoing drag gesture. This function should be called always after the user has ended a drag gesture initiated by dragStart.

  • If implementing a custom animation mechanism, call this method when the animation begins. Must always be paired with a corresponding call to endAnimation()

  • If implementing a custom animation mechanism, call this method when the animation ends. Must always be paired with a corresponding call to beginAnimation()

  • If implementing a custom gesture, call this method when the gesture begins. Must always be paired with a corresponding call to endGesture()

  • If implementing a custom gesture, call this method when the gesture ends. Must always be paired with a corresponding call to beginGesture()

  • Queries the map for source features.

  • Queries for feature extension values in a GeoJSON source.

      1. `children`: returns the children of a cluster (on the next zoom
        level).
      2. `leaves`: returns all the leaves of a cluster (given its cluster_id)
      3. `expansion-zoom`: returns the zoom on which the cluster expands
        into several children (useful for "click to zoom" feature).
    
    • args: Used for further query specification when using ‘leaves’ extensionField. Now only support following two args:
      1. `limit`: the number of points to return from the query (must
            use type 'UInt64', set to maximum for all points)
      2. `offset`: the amount of points to skip (for pagination, must
            use type 'UInt64')
    
    • completion: The result could be a feature extension value containing either a value (expansion-zoom) or a feature collection (children or leaves). An error is passed if the operation was not successful. Deprecated. Use getGeoJsonClusterLeaves/getGeoJsonClusterChildren/getGeoJsonClusterExpansionZoom to instead.
  • Returns all the leaves (original points) of a cluster (given its cluster_id) from a GeoJSON source, with pagination support: limit is the number of leaves to return (set to Infinity for all points), and offset is the amount of points to skip (for pagination).

  • Returns the children (original points or clusters) of a cluster (on the next zoom level) given its id (cluster_id value from feature properties) from a GeoJSON source.

  • Returns the zoom on which the cluster expands into several children (useful for “click to zoom” feature) given the cluster’s cluster_id (cluster_id value from feature properties) from a GeoJSON source.

  • Subscribes an observer to a list of events.

    MapboxMap holds a strong reference to observer while it is subscribed. To stop receiving notifications, pass the same observer to unsubscribe(_:events:).

    Note

    Prefer onNext(eventTypes:handler:), onNext(_:handler:), and onEvery(_:handler:) to using this lower-level APIs

  • Unsubscribes an observer from a provided list of event types.

    MapboxMap holds a strong reference to observer while it is subscribed. To stop receiving notifications, pass the same observer to this method as was passed to subscribe(_:events:).

  • Listen to a single occurrence of a Map event.

    This will observe the next (and only the next) event of the specified type. After observation, the underlying subscriber will unsubscribe from the map or snapshotter.

    If you need to unsubscribe before the event fires, call cancel() on the returned Cancelable object.

  • Listen to multiple occurrences of a Map event.

  • Clears temporary map data.

    Clears temporary map data from the data path defined in the given resource options. Useful to reduce the disk usage or in case the disk cache contains invalid data.

    Note

    Calling this API will affect all maps that use the same data path and does not affect persistent map data like offline style packages.