MapboxMap

The general class to interact with in the Mapbox Maps SDK for Android. It exposes the entry point for all methods related to the Map object. You cannot instantiate MapboxMap object directly, rather, you must obtain one from the getMapboxMap() method MapView that you have added to your application.

Note: Similar to a View object, a MapboxMap should only be read and modified from the main thread.

Types

Companion
Link copied to clipboard
object Companion
A convenience object to access MapboxMap's static utilities.

Functions

addOnCameraChangeListener
Link copied to clipboard
open override fun addOnCameraChangeListener(onCameraChangeListener: OnCameraChangeListener)
Add a listener that's going to be invoked whenever map camera changes.
addOnMapIdleListener
Link copied to clipboard
open override fun addOnMapIdleListener(onMapIdleListener: OnMapIdleListener)
Add a listener that's going to be invoked whenever map has entered the idle state.
addOnMapLoadedListener
Link copied to clipboard
open override fun addOnMapLoadedListener(onMapLoadedListener: OnMapLoadedListener)
Add a listener that's going to be invoked whenever the Map's style has been fully loaded, and the Map has rendered all visible tiles.
addOnMapLoadErrorListener
Link copied to clipboard
open override fun addOnMapLoadErrorListener(onMapLoadErrorListener: OnMapLoadErrorListener)
Add a listener that's going to be invoked whenever there's a map load error.
addOnRenderFrameFinishedListener
Link copied to clipboard
open override fun addOnRenderFrameFinishedListener(onRenderFrameFinishedListener: OnRenderFrameFinishedListener)
Add a listener that's going to be invoked whenever the Map finished rendering a frame.
addOnRenderFrameStartedListener
Link copied to clipboard
open override fun addOnRenderFrameStartedListener(onRenderFrameStartedListener: OnRenderFrameStartedListener)
Add a listener that's going to be invoked whenever the Map started rendering a frame.
addOnSourceAddedListener
Link copied to clipboard
open override fun addOnSourceAddedListener(onSourceAddedListener: OnSourceAddedListener)
Add a listener that's going to be invoked whenever a source has been added with StyleManager#addStyleSource runtime API.
addOnSourceDataLoadedListener
Link copied to clipboard
open override fun addOnSourceDataLoadedListener(onSourceDataLoadedListener: OnSourceDataLoadedListener)
Add a listener that's going to be invoked whenever the source data has been loaded.
addOnSourceRemovedListener
Link copied to clipboard
open override fun addOnSourceRemovedListener(onSourceRemovedListener: OnSourceRemovedListener)
Add a listener that's going to be invoked whenever a source has been removed with StyleManager#removeStyleSource runtime API.
addOnStyleDataLoadedListener
Link copied to clipboard
open override fun addOnStyleDataLoadedListener(onStyleDataLoadedListener: OnStyleDataLoadedListener)
Add a listener that's going to be invoked whenever the requested style data been loaded.
addOnStyleImageMissingListener
Link copied to clipboard
open override fun addOnStyleImageMissingListener(onStyleImageMissingListener: OnStyleImageMissingListener)
Add a listener that's going to be invoked whenever a style has a missing image.
addOnStyleImageUnusedListener
Link copied to clipboard
open override fun addOnStyleImageUnusedListener(onStyleImageUnusedListener: OnStyleImageUnusedListener)
Add a listener that's going to be invoked whenever an image added to the Style is no longer needed and can be removed using StyleManager#removeStyleImage method.
addOnStyleLoadedListener
Link copied to clipboard
open override fun addOnStyleLoadedListener(onStyleLoadedListener: OnStyleLoadedListener)
Add a listener that's going to be invoked whenever the requested style has been fully loaded, including the style specified sprite and sources.
cameraAnimationsPlugin
Link copied to clipboard
open override fun cameraAnimationsPlugin(function: CameraAnimationsPlugin.() -> Any?): Any?
Call extension function on CameraAnimationsPlugin.
cameraForCoordinateBounds
Link copied to clipboard
open override fun cameraForCoordinateBounds(bounds: CoordinateBounds, padding: EdgeInsets, bearing: Double?, pitch: Double?): CameraOptions
Convert to a camera options from a given LatLngBounds, padding, bearing and pitch values.
cameraForCoordinates
Link copied to clipboard
open override fun cameraForCoordinates(coordinates: List<Point>, camera: CameraOptions, box: ScreenBox): CameraOptions
Convenience method that returns the camera options object for given argumentsIn order for this method to produce correct results MapView must be already measured and inflated to have correct width and height values.
open override fun cameraForCoordinates(coordinates: List<Point>, padding: EdgeInsets, bearing: Double?, pitch: Double?): CameraOptions
Convert to a camera options from a given list of points, padding, bearing and pitch values.
cameraForGeometry
Link copied to clipboard
open override fun cameraForGeometry(geometry: Geometry, padding: EdgeInsets, bearing: Double?, pitch: Double?): CameraOptions
Convert to a camera options from a given geometry, padding, bearing and pitch values.
clearData
Link copied to clipboard
fun clearData(callback: AsyncOperationResultCallback)
Clears temporary map data.
coordinateBoundsForCamera
Link copied to clipboard
open override fun coordinateBoundsForCamera(camera: CameraOptions): CoordinateBounds
Returns the CoordinateBounds for a given camera.
coordinateBoundsForCameraUnwrapped
Link copied to clipboard
open override fun coordinateBoundsForCameraUnwrapped(camera: CameraOptions): CoordinateBounds
Returns the CoordinateBounds for a given camera.
coordinateBoundsZoomForCamera
Link copied to clipboard
open override fun coordinateBoundsZoomForCamera(camera: CameraOptions): CoordinateBoundsZoom
Returns the coordinate bounds and zoom for a given camera.
coordinateBoundsZoomForCameraUnwrapped
Link copied to clipboard
open override fun coordinateBoundsZoomForCameraUnwrapped(camera: CameraOptions): CoordinateBoundsZoom
Returns the unwrapped coordinate bounds and zoom for a given camera.
coordinateForPixel
Link copied to clipboard
open override fun coordinateForPixel(pixel: ScreenCoordinate): Point
Calculate a geographical coordinate(i.e., longitude-latitude pair) that corresponds to a screen coordinate.
coordinateForProjectedMeters
Link copied to clipboard
open override fun coordinateForProjectedMeters(projectedMeters: ProjectedMeters): Point
Calculate a longitude-latitude pair for a Spherical Mercator projected meters.
coordinatesForPixels
Link copied to clipboard
open override fun coordinatesForPixels(pixels: List<ScreenCoordinate>): List<Point>
Calculate geographical coordinates(i.e., longitude-latitude pair) that corresponds to screen coordinates.
dragEnd
Link copied to clipboard
open override fun dragEnd()
Ends the ongoing drag gesture.
dragStart
Link copied to clipboard
open override fun dragStart(point: ScreenCoordinate)
Prepares the drag gesture to use the provided screen coordinate as a pivot point.
equals
Link copied to clipboard
open operator fun equals(other: Any?): Boolean
executeOnRenderThread
Link copied to clipboard
open override fun executeOnRenderThread(runnable: Runnable)
In some cases querying source / render features is expected to be a blocking operation e.g.
gesturesPlugin
Link copied to clipboard
open override fun gesturesPlugin(function: GesturesPlugin.() -> Any?): Any?
Call extension function on GesturesPlugin.
getBounds
Link copied to clipboard
open override fun getBounds(): CameraBounds
Get the map bounds options.
getDebug
Link copied to clipboard
fun getDebug(): List<MapDebugOptions>
Get debug options
getDragCameraOptions
Link copied to clipboard
open override fun getDragCameraOptions(fromPoint: ScreenCoordinate, toPoint: ScreenCoordinate): CameraOptions
Calculates target point where camera should move after drag.
getElevation
Link copied to clipboard
fun getElevation(coordinate: Point): Double?
Get elevation for given coordinate.
getFeatureState
Link copied to clipboard
fun getFeatureState(sourceId: String, sourceLayerId: String? = null, featureId: String, callback: QueryFeatureStateCallback)
Get the state map of a feature within a style source.
getFreeCameraOptions
Link copied to clipboard
open override fun getFreeCameraOptions(): FreeCameraOptions
Get the map's current free camera options.
getGeoJsonClusterChildren
Link copied to clipboard
fun getGeoJsonClusterChildren(sourceIdentifier: String, cluster: Feature, callback: QueryFeatureExtensionCallback)
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 GeoJsonSource.
getGeoJsonClusterExpansionZoom
Link copied to clipboard
fun getGeoJsonClusterExpansionZoom(sourceIdentifier: String, cluster: Feature, callback: QueryFeatureExtensionCallback)
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 GeoJsonSource.
getGeoJsonClusterLeaves
Link copied to clipboard
fun getGeoJsonClusterLeaves(sourceIdentifier: String, cluster: Feature, limit: Long = QFE_DEFAULT_LIMIT, offset: Long = QFE_DEFAULT_OFFSET, callback: QueryFeatureExtensionCallback)
Returns all the leaves (original points) of a cluster (given its cluster_id) from a GeoJsonSource, 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).
getMapOptions
Link copied to clipboard
open override fun getMapOptions(): MapOptions
Get map options.
getMapProjection
Link copied to clipboard
open override fun getMapProjection(): MapProjection
Get current map projection for the map.
getMetersPerPixelAtLatitude
Link copied to clipboard
open override fun getMetersPerPixelAtLatitude(latitude: Double): Double
Calculate distance spanned by one pixel at the specified latitude at current zoom level.
open override fun getMetersPerPixelAtLatitude(latitude: Double, zoom: Double): Double
Calculate distance spanned by one pixel at the specified latitude and zoom level.
getPrefetchZoomDelta
Link copied to clipboard
fun getPrefetchZoomDelta(): Byte
Get the prefetch zoom delta
getRenderCacheOptions
Link copied to clipboard
fun getRenderCacheOptions(): RenderCacheOptions
Get the current RenderCacheOptions.
getResourceOptions
Link copied to clipboard
fun getResourceOptions(): ResourceOptions
Get the ResourceOptions the map was initialized with.
getSize
Link copied to clipboard
open override fun getSize(): Size
Gets the size of the map.
getStyle
Link copied to clipboard
fun getStyle(): Style?
Get the Style of the map synchronously, will return null is style is not loaded yet.
fun getStyle(onStyleLoaded: Style.OnStyleLoaded)
Get the Style of the map asynchronously.
hashCode
Link copied to clipboard
open fun hashCode(): Int
isFullyLoaded
Link copied to clipboard
open override fun isFullyLoaded(): Boolean
Returns if the style has been fully loaded.
isGestureInProgress
Link copied to clipboard
open override fun isGestureInProgress(): Boolean
Returns if a gesture is in progress.
isUserAnimationInProgress
Link copied to clipboard
open override fun isUserAnimationInProgress(): Boolean
Returns if user animation is currently in progress.
isValid
Link copied to clipboard
fun isValid(): Boolean
Whether the MapboxMap instance is valid.
loadStyle
Link copied to clipboard
fun loadStyle(styleExtension: StyleContract.StyleExtension)
Load the style from Style Extension.
fun loadStyle(styleExtension: StyleContract.StyleExtension, onStyleLoaded: Style.OnStyleLoaded)
Load the style from Style Extension.
fun loadStyle(styleExtension: StyleContract.StyleExtension, onStyleLoaded: Style.OnStyleLoaded? = null, onMapLoadErrorListener: OnMapLoadErrorListener? = null)
Load the style from Style Extension.
fun loadStyle(styleExtension: StyleContract.StyleExtension, transitionOptions: TransitionOptions? = null, onStyleLoaded: Style.OnStyleLoaded? = null, onMapLoadErrorListener: OnMapLoadErrorListener? = null)
Load the style from Style Extension.
loadStyleJson
Link copied to clipboard
fun loadStyleJson(styleJson: String)
Load style JSON.
fun loadStyleJson(styleJson: String, onStyleLoaded: Style.OnStyleLoaded)
Load style JSON.
fun loadStyleJson(styleJson: String, onStyleLoaded: Style.OnStyleLoaded? = null, onMapLoadErrorListener: OnMapLoadErrorListener? = null)
Load style JSON
fun loadStyleJson(styleJson: String, styleTransitionOptions: TransitionOptions? = null, onStyleLoaded: Style.OnStyleLoaded? = null, onMapLoadErrorListener: OnMapLoadErrorListener? = null)
Load style JSON
loadStyleUri
Link copied to clipboard
fun loadStyleUri(styleUri: String)
Will load a new map style asynchronous from the specified URI.
fun loadStyleUri(styleUri: String, onStyleLoaded: Style.OnStyleLoaded)
Will load a new map style asynchronous from the specified URI.
fun loadStyleUri(styleUri: String, onStyleLoaded: Style.OnStyleLoaded? = null, onMapLoadErrorListener: OnMapLoadErrorListener? = null)
Will load a new map style asynchronous from the specified URI.
fun loadStyleUri(styleUri: String, styleTransitionOptions: TransitionOptions? = null, onStyleLoaded: Style.OnStyleLoaded? = null, onMapLoadErrorListener: OnMapLoadErrorListener? = null)
Will load a new map style asynchronous from the specified URI.
pixelForCoordinate
Link copied to clipboard
open override fun pixelForCoordinate(coordinate: Point): ScreenCoordinate
Calculate a screen coordinate that corresponds to a geographical coordinate (i.e., longitude-latitude pair).
pixelsForCoordinates
Link copied to clipboard
open override fun pixelsForCoordinates(coordinates: List<Point>): List<ScreenCoordinate>
Calculate screen coordinates that corresponds to geographical coordinates (i.e., longitude-latitude pair).
project
Link copied to clipboard
open override fun project(point: Point, zoomScale: Double): MercatorCoordinate
Calculate a point on the map in Mercator Projection for a given coordinate at the specified zoom scale.
projectedMetersForCoordinate
Link copied to clipboard
open override fun projectedMetersForCoordinate(point: Point): ProjectedMeters
Calculate Spherical Mercator ProjectedMeters coordinates.
queryFeatureExtensions
Link copied to clipboard
fun queryFeatureExtensions(sourceIdentifier: String, feature: Feature, extension: String, extensionField: String, args: HashMap<String, Value>?, callback: QueryFeatureExtensionCallback)
Queries for feature extension values in a GeoJSON source.
queryRenderedFeatures
Link copied to clipboard
open override fun queryRenderedFeatures(geometry: RenderedQueryGeometry, options: RenderedQueryOptions, callback: QueryFeaturesCallback): Cancelable
Queries the map for rendered features.
open override fun queryRenderedFeatures(box: ScreenBox, options: RenderedQueryOptions, callback: QueryFeaturesCallback)
Queries the map for rendered features.
open override fun queryRenderedFeatures(pixel: ScreenCoordinate, options: RenderedQueryOptions, callback: QueryFeaturesCallback)
Queries the map for rendered features.
open override fun queryRenderedFeatures(shape: List<ScreenCoordinate?>, options: RenderedQueryOptions, callback: QueryFeaturesCallback)
Queries the map for rendered features.
querySourceFeatures
Link copied to clipboard
open override fun querySourceFeatures(sourceId: String, options: SourceQueryOptions, callback: QueryFeaturesCallback)
Queries the map for source features.
reduceMemoryUse
Link copied to clipboard
fun reduceMemoryUse()
Reduce memory use.
removeFeatureState
Link copied to clipboard
fun removeFeatureState(sourceId: String, sourceLayerId: String? = null, featureId: String, stateKey: String? = null)
Remove entries from a feature state map.
removeOnCameraChangeListener
Link copied to clipboard
open override fun removeOnCameraChangeListener(onCameraChangeListener: OnCameraChangeListener)
Remove the camera change listener.
removeOnMapIdleListener
Link copied to clipboard
open override fun removeOnMapIdleListener(onMapIdleListener: OnMapIdleListener)
Remove the map idle listener.
removeOnMapLoadedListener
Link copied to clipboard
open override fun removeOnMapLoadedListener(onMapLoadedListener: OnMapLoadedListener)
Remove the map loaded listener.
removeOnMapLoadErrorListener
Link copied to clipboard
open override fun removeOnMapLoadErrorListener(onMapLoadErrorListener: OnMapLoadErrorListener)
Remove the map error listener.
removeOnRenderFrameFinishedListener
Link copied to clipboard
open override fun removeOnRenderFrameFinishedListener(onRenderFrameFinishedListener: OnRenderFrameFinishedListener)
Remove the render frame finished listener.
removeOnRenderFrameStartedListener
Link copied to clipboard
open override fun removeOnRenderFrameStartedListener(onRenderFrameStartedListener: OnRenderFrameStartedListener)
Remove the render frame started listener.
removeOnSourceAddedListener
Link copied to clipboard
open override fun removeOnSourceAddedListener(onSourceAddedListener: OnSourceAddedListener)
Remove the source added listener.
removeOnSourceDataLoadedListener
Link copied to clipboard
open override fun removeOnSourceDataLoadedListener(onSourceDataLoadedListener: OnSourceDataLoadedListener)
Remove the source data loaded listener.
removeOnSourceRemovedListener
Link copied to clipboard
open override fun removeOnSourceRemovedListener(onSourceRemovedListener: OnSourceRemovedListener)
Remove the source removed listener.
removeOnStyleDataLoadedListener
Link copied to clipboard
open override fun removeOnStyleDataLoadedListener(onStyleDataLoadedListener: OnStyleDataLoadedListener)
Remove the style data loaded listener
removeOnStyleImageMissingListener
Link copied to clipboard
open override fun removeOnStyleImageMissingListener(onStyleImageMissingListener: OnStyleImageMissingListener)
Remove the style image missing listener.
removeOnStyleImageUnusedListener
Link copied to clipboard
open override fun removeOnStyleImageUnusedListener(onStyleImageUnusedListener: OnStyleImageUnusedListener)
Remove the style image unused listener.
removeOnStyleLoadedListener
Link copied to clipboard
open override fun removeOnStyleLoadedListener(onStyleLoadedListener: OnStyleLoadedListener)
Remove the style loaded listener.
setBounds
Link copied to clipboard
open override fun setBounds(options: CameraBoundsOptions): Expected<String, None>
Set the map bounds.
setCamera
Link copied to clipboard
open override fun setCamera(cameraOptions: CameraOptions)
Changes the map view by any combination of center, zoom, bearing, and pitch, without an animated transition.
open override fun setCamera(freeCameraOptions: FreeCameraOptions)
Sets the map view with the free camera options.
setConstrainMode
Link copied to clipboard
open override fun setConstrainMode(constrainMode: ConstrainMode)
Set the map constrain mode
setDebug
Link copied to clipboard
fun setDebug(debugOptions: List<MapDebugOptions>, enabled: Boolean)
Set debug options
setFeatureState
Link copied to clipboard
fun setFeatureState(sourceId: String, sourceLayerId: String? = null, featureId: String, state: Value)
Update the state map of a feature within a style source.
setGestureInProgress
Link copied to clipboard
open override fun setGestureInProgress(inProgress: Boolean)
Notify map about gesture being in progress.
setMapProjection
Link copied to clipboard
open override fun setMapProjection(mapProjection: MapProjection)
Set current map projection for the map.
setMemoryBudget
Link copied to clipboard
fun setMemoryBudget(memoryBudget: MapMemoryBudget?)
The memory budget hint to be used by the map.
setNorthOrientation
Link copied to clipboard
open override fun setNorthOrientation(northOrientation: NorthOrientation)
Set the map north orientation
setPrefetchZoomDelta
Link copied to clipboard
fun setPrefetchZoomDelta(delta: Byte)
Set the prefetch zoom delta
setRenderCacheOptions
Link copied to clipboard
fun setRenderCacheOptions(options: RenderCacheOptions)
Enables or disables the experimental render cache feature.
setUserAnimationInProgress
Link copied to clipboard
open override fun setUserAnimationInProgress(inProgress: Boolean)
Tells the map rendering engine that the animation is currently performed by the user (e.g.
setViewportMode
Link copied to clipboard
open override fun setViewportMode(viewportMode: ViewportMode)
Set the map viewport mode
subscribe
Link copied to clipboard
open override fun subscribe(observer: Observer, events: List<String>)
Subscribes an Observer to a provided list of event types.
toString
Link copied to clipboard
open fun toString(): String
triggerRepaint
Link copied to clipboard
fun triggerRepaint()
Triggers a repaint of the map.
unproject
Link copied to clipboard
open override fun unproject(coordinate: MercatorCoordinate, zoomScale: Double): Point
Calculate a coordinate for a given point on the map in Mercator Projection.
unsubscribe
Link copied to clipboard
open override fun unsubscribe(observer: Observer)
Unsubscribes an Observer from all events.
open override fun unsubscribe(observer: Observer, events: List<String>)
Unsubscribes an Observer from a provided list of event types.

Properties

cameraState
Link copied to clipboard
open override val cameraState: CameraState
Represents current camera state.