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.

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

Functions

addOnCameraChangeListener
Link copied to clipboard

Add a listener that's going to be invoked whenever the camera position changes.

open override fun addOnCameraChangeListener(onCameraChangeListener: OnCameraChangeListener)
addOnDidFinishRenderingFrameListener
Link copied to clipboard

Add a listener that's going to be invoked whenever frame finished rendering.

open override fun addOnDidFinishRenderingFrameListener(onDidFinishRenderingFrameListener: OnDidFinishRenderingFrameListener)
addOnDidFinishRenderingMapListener
Link copied to clipboard

Add a listener that's going to be invoked whenever the map finished rendering.

open override fun addOnDidFinishRenderingMapListener(onDidFinishRenderingMapListener: OnDidFinishRenderingMapListener)
addOnMapChangedListener
Link copied to clipboard

Add a listener that's going to be invoked whenever map state changes.

open override fun addOnMapChangedListener(onMapChangeListener: OnMapChangedListener)
addOnMapLoadErrorListener
Link copied to clipboard

Add a listener that's going to be invoked whenever a map load error occurs.

open override fun addOnMapLoadErrorListener(onMapLoadErrorListener: OnMapLoadErrorListener)
addOnSourceChangeListener
Link copied to clipboard

Add a listener that's going to be invoked whenever a source changes.

open override fun addOnSourceChangeListener(onSourceChangeListener: OnSourceChangeListener)
addOnStyleImageChangeListener
Link copied to clipboard

Add a listener that's going to be invoked whenever style image state changes.

open override fun addOnStyleImageChangeListener(onStyleImageChangeListener: OnStyleImageChangeListener)
cameraForCoordinateBounds
Link copied to clipboard

Convert to a camera options from a given LatLngBounds, padding, bearing and pitch values.

open override fun cameraForCoordinateBounds(coordinateBounds: CoordinateBounds, padding: EdgeInsets, bearing: Double?, pitch: Double?): CameraOptions
cameraForCoordinates
Link copied to clipboard

Convert to a camera options from a given list of points, padding, bearing and pitch values.

open override fun cameraForCoordinates(coordinates: List<Point>, padding: EdgeInsets, bearing: Double?, pitch: Double?): CameraOptions
cameraForGeometry
Link copied to clipboard

Convert to a camera options from a given geometry, padding, bearing and pitch values.

open override fun cameraForGeometry(geometry: Geometry, padding: EdgeInsets, bearing: Double?, pitch: Double?): CameraOptions
coordinateBoundsForCamera
Link copied to clipboard

Convert to a LatLngBounds from a given camera options.

open override fun coordinateBoundsForCamera(cameraOptions: CameraOptions): CoordinateBounds
coordinateBoundsZoomForCamera
Link copied to clipboard

Returns the coordinate bounds and zoom for a given camera.

Note that if the given camera shows the antimeridian, the returned wrapped bounds might not represent the minimum bounding box.

See also {@link #coordinateBoundsZoomForCameraUnwrapped}

open override fun coordinateBoundsZoomForCamera(cameraOptions: CameraOptions): CoordinateBoundsZoom
coordinateBoundsZoomForCameraUnwrapped
Link copied to clipboard

Returns the unwrapped coordinate bounds and zoom for a given camera.

This method is particularly useful, if the camera shows the antimeridian.

open override fun coordinateBoundsZoomForCameraUnwrapped(cameraOptions: CameraOptions): CoordinateBoundsZoom
coordinateForPixel
Link copied to clipboard

Calculate a geographical coordinate(i.e., longitude-latitude pair) that corresponds to a screen coordinate.

The screen coordinate is in MapOptions.size platform pixels relative to the top left of the map (not of the whole screen).

open override fun coordinateForPixel(screenCoordinate: ScreenCoordinate): Point
coordinateForProjectedMeters
Link copied to clipboard

Calculate a longitude-latitude pair for a Spherical Mercator projected meters.

open override fun coordinateForProjectedMeters(projectedMeters: ProjectedMeters): Point
coordinatesForPixels
Link copied to clipboard

Calculate geographical coordinates(i.e., longitude-latitude pair) that corresponds to screen coordinates.

The screen coordinates are in MapOptions.size platform pixels relative to the top left of the map (not of the whole screen).

open override fun coordinatesForPixels(pixels: List<ScreenCoordinate>): List<Point>
drag
Link copied to clipboard

Drags the map from one screen point to another. The method should be called after dragStart and before dragEnd.

open override fun drag(fromPoint: ScreenCoordinate, toPoint: ScreenCoordinate, animation: AnimationOptions?)
dragEnd
Link copied to clipboard

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

open override fun dragEnd()
dragStart
Link copied to clipboard

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.

open override fun dragStart(point: ScreenCoordinate)
dumpDebugLogs
Link copied to clipboard

Dump debug logs

fun dumpDebugLogs()
equals
Link copied to clipboard
open operator override fun equals(other: Any?): Boolean
getBounds
Link copied to clipboard

Get the map bounds options.

open override fun getBounds(): BoundOptions
getCameraOptions
Link copied to clipboard

Get the current camera options given an optional padding.

open override fun getCameraOptions(edgeInsets: EdgeInsets?): CameraOptions
getDebug
Link copied to clipboard

Get debug options

fun getDebug(): List<MapDebugOptions>
getElevation
Link copied to clipboard

Get elevation for given coordinate. Value is available only for the visible region on the screen, if terrain (DEM) tile is available.

fun getElevation(coordinate: Point): Float?
getFeatureState
Link copied to clipboard

Get the state map of a feature within a style source.

Note that updates to feature state are asynchronous, so changes made by other methods might not be immediately visible.

fun getFeatureState(sourceId: String, sourceLayerId: String?, featureId: String, callback: QueryFeatureStateCallback)
getFreeCameraOptions
Link copied to clipboard

Get the map's current free camera options. After mutation, it should be set back to the map.

fun getFreeCameraOptions(): FreeCameraOptions
getMapOptions
Link copied to clipboard

Get map options.

open override fun getMapOptions(): MapOptions
getMaxZoom
Link copied to clipboard

Get maximum zoom.

open override fun getMaxZoom(): Double
getMetersPerPixelAtLatitude
Link copied to clipboard

Calculate distance spanned by one pixel at the specified latitude at current zoom level.

open override fun getMetersPerPixelAtLatitude(latitude: Double): Double

Calculate distance spanned by one pixel at the specified latitude and zoom level.

open override fun getMetersPerPixelAtLatitude(latitude: Double, zoom: Double): Double
getMinZoom
Link copied to clipboard

Get minimum zoom.

open override fun getMinZoom(): Double
getPrefetchZoomDelta
Link copied to clipboard

Get the prefetch zoom delta

fun getPrefetchZoomDelta(): Byte
getResourceOptions
Link copied to clipboard

Get the ResourceOptions the map was initialized with.

fun getResourceOptions(): ResourceOptions
getScale
Link copied to clipboard

The current zoom factor applied on the map meaning 2 ^ Current zoom

open override fun getScale(): Double
getSize
Link copied to clipboard

Gets the size of the map.

open override fun getSize(): Size
getStyle
Link copied to clipboard

Get the Style of the map synchronously, will return null is style is not loaded yet.

fun getStyle(): Style?

Get the Style of the map asynchronously.

fun getStyle(onStyleLoaded: Style.OnStyleLoaded)
hashCode
Link copied to clipboard
open override fun hashCode(): Int
isFullyLoaded
Link copied to clipboard

Returns if the style has been fully loaded.

open override fun isFullyLoaded(): Boolean
isGestureInProgress
Link copied to clipboard

Returns if a gesture is in progress.

open override fun isGestureInProgress(): Boolean
isUserAnimationInProgress
Link copied to clipboard

Returns if user animation is currently in progress.

open override fun isUserAnimationInProgress(): Boolean
jumpTo
Link copied to clipboard

Set the map camera to a given camera options.

open override fun jumpTo(cameraOptions: CameraOptions)
loadStyle
Link copied to clipboard

Load the style from Style plugin.

fun loadStyle(styleExtension: StyleContract.StyleExtension, onStyleLoaded: Style.OnStyleLoaded)
fun loadStyle(styleExtension: StyleContract.StyleExtension, onStyleLoaded: Style.OnStyleLoaded?, onMapLoadErrorListener: OnMapLoadErrorListener?)
loadStyleJSON
Link copied to clipboard

Load style JSON

fun loadStyleJSON(json: String, onStyleLoaded: Style.OnStyleLoaded)
fun loadStyleJSON(json: String, onStyleLoaded: Style.OnStyleLoaded?, onMapLoadErrorListener: OnMapLoadErrorListener?)
loadStyleUri
Link copied to clipboard

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.

URI can take the following forms:

  • Constants: load one of the bundled styles in Style.

  • mapbox://styles/<user>/<style>: loads the style from a Mapbox account. user is your username. style is the ID of your custom style created in Mapbox Studio.

  • http://... or https://...: loads the style over the Internet from any web server.

  • asset://...: loads the style from the APK assets directory. This is used to load a style bundled with your app.

  • file://...: loads the style from a file path. This is used to load a style from disk.

fun loadStyleUri(styleUri: String, onStyleLoaded: Style.OnStyleLoaded?, onMapLoadErrorListener: OnMapLoadErrorListener?)
pixelForCoordinate
Link copied to clipboard

Calculate a screen coordinate that corresponds to a geographical coordinate (i.e., longitude-latitude pair).

The screen coordinate is in MapOptions.size platform pixels relative to the top left of the map (not of the whole screen).

open override fun pixelForCoordinate(point: Point): ScreenCoordinate
pixelsForCoordinates
Link copied to clipboard

Calculate screen coordinates that corresponds to geographical coordinates (i.e., longitude-latitude pair).

The screen coordinates are in MapOptions.size platform pixels relative to the top left of the map (not of the whole screen).

open override fun pixelsForCoordinates(coordinates: List<Point>): List<ScreenCoordinate>
project
Link copied to clipboard

Calculate a point on the map in Mercator Projection for a given coordinate at the specified zoom scale.

open override fun project(point: Point, zoomScale: Double): MercatorCoordinate
projectedMetersForCoordinate
Link copied to clipboard

Calculate Spherical Mercator ProjectedMeters coordinates.

open override fun projectedMetersForCoordinate(point: Point): ProjectedMeters
queryFeatureExtensions
Link copied to clipboard

Queries for feature extension values in a GeoJSON source.

fun queryFeatureExtensions(sourceIdentifier: String, feature: Feature, extension: String, extensionField: String, args: HashMap<String, Value>?, callback: QueryFeatureExtensionCallback)
queryRenderedFeatures
Link copied to clipboard

Queries the map for rendered features.

open override fun queryRenderedFeatures(box: ScreenBox, options: RenderedQueryOptions, callback: QueryFeaturesCallback)
open override fun queryRenderedFeatures(pixel: ScreenCoordinate, options: RenderedQueryOptions, callback: QueryFeaturesCallback)
open override fun queryRenderedFeatures(shape: List<ScreenCoordinate?>, options: RenderedQueryOptions, callback: QueryFeaturesCallback)
querySourceFeatures
Link copied to clipboard

Queries the map for source features.

open override fun querySourceFeatures(sourceId: String, options: SourceQueryOptions, callback: QueryFeaturesCallback)
reduceMemoryUse
Link copied to clipboard

Reduce memory use. Useful to call when the application gets paused or sent to background.

fun reduceMemoryUse()
removeFeatureState
Link copied to clipboard

Remove entries from a feature state map.

Remove a specified entry or all entries from a feature's state map, depending on the value of stateKey.

Note that updates to feature state are asynchronous, so changes made by this method migth not be immediately visible using getStateFeature().

fun removeFeatureState(sourceId: String, sourceLayerId: String?, featureId: String, stateKey: String?)
removeOnCameraChangeListener
Link copied to clipboard

Remove the camera change listener.

open override fun removeOnCameraChangeListener(onCameraChangeListener: OnCameraChangeListener)
removeOnDidFinishRenderingFrameListener
Link copied to clipboard

Remove the finish rendering frame listener.

open override fun removeOnDidFinishRenderingFrameListener(onDidFinishRenderingFrameListener: OnDidFinishRenderingFrameListener)
removeOnDidFinishRenderingMapListener
Link copied to clipboard

Remove the did finish rendering map listener.

open override fun removeOnDidFinishRenderingMapListener(onDidFinishRenderingMapListener: OnDidFinishRenderingMapListener)
removeOnMapChangedListener
Link copied to clipboard

Remove the map change listener.

open override fun removeOnMapChangedListener(onMapChangedListener: OnMapChangedListener)
removeOnMapLoadErrorListener
Link copied to clipboard

Remove the map load error listener.

open override fun removeOnMapLoadErrorListener(onMapLoadErrorListener: OnMapLoadErrorListener)
removeOnSourceChangeListener
Link copied to clipboard

Remove the source change listener.

open override fun removeOnSourceChangeListener(onSourceChangeListener: OnSourceChangeListener)
removeOnStyleImageChangeListener
Link copied to clipboard

Remove the style image change listener.

open override fun removeOnStyleImageChangeListener(onStyleImageChangeListener: OnStyleImageChangeListener)
renderStill
Link copied to clipboard

Render the map to an image asynchronously, resulting image will be provided through a callback interface.

fun renderStill(stillImageCallback: StillImageCallback)

Render an image of the map based on camera options and debug options asynchronously, resulting image will be provided through a callback interface.

fun renderStill(cameraOptions: CameraOptions, debugOptions: List<MapDebugOptions>, stillImageCallback: StillImageCallback)
setBounds
Link copied to clipboard

Set the map bounds.

open override fun setBounds(boundOptions: BoundOptions)
setConstrainMode
Link copied to clipboard

Set the map constrain mode

open override fun setConstrainMode(constrainMode: ConstrainMode)
setDebug
Link copied to clipboard

Set debug options

fun setDebug(debugOptions: List<MapDebugOptions>, enabled: Boolean)
setDefaultFramebufferObject
Link copied to clipboard
fun setDefaultFramebufferObject(framebufferId: Int)
setFeatureState
Link copied to clipboard

Update the state map of a feature within a style source.

Update entries in the state map of a given feature within a style source. Only entries listed in the \p state map will be updated. An entry in the feature state map that is not listed in \p state will retain its previous value.

Note that updates to feature state are asynchronous, so changes made by this method migth not be immediately visible using getStateFeature().

fun setFeatureState(sourceId: String, sourceLayerId: String?, featureId: String, state: Value)
setFreeCameraOptions
Link copied to clipboard

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.

fun setFreeCameraOptions(options: FreeCameraOptions)
setGestureInProgress
Link copied to clipboard

Notify map about gesture being in progress.

open override fun setGestureInProgress(inProgress: Boolean)
setNorthOrientation
Link copied to clipboard

Set the map north orientation

open override fun setNorthOrientation(northOrientation: NorthOrientation)
setPrefetchZoomDelta
Link copied to clipboard

Set the prefetch zoom delta

fun setPrefetchZoomDelta(delta: Byte)
setUserAnimationInProgress
Link copied to clipboard

Tells the map rendering engine that the animation is currently performed by the user (e.g. with a jumpTo() calls series). It adjusts the engine for the animation use case. In particular, it brings more stability to symbol placement and rendering.

open override fun setUserAnimationInProgress(inProgress: Boolean)
setViewportMode
Link copied to clipboard

Set the map viewport mode

open override fun setViewportMode(viewportMode: ViewportMode)
subscribe
Link copied to clipboard

Subscribes an Observer to a provided list of event types. Observable will hold a strong reference to an \sa Observer instance, therefore, in order to stop receiving notifications, caller must call unsubscribe with an \sa Observer instance used for an initial subscription.

open override fun subscribe(observer: Observer, events: List<String>)
terrainEnabled
Link copied to clipboard

Is terrain enabled for loaded style of the map.

open override fun terrainEnabled(): Boolean
toString
Link copied to clipboard
open override fun toString(): String
triggerRepaint
Link copied to clipboard

Triggers a repaint of the map.

fun triggerRepaint()
unproject
Link copied to clipboard

Calculate a coordinate for a given point on the map in Mercator Projection.

open override fun unproject(coordinate: MercatorCoordinate, zoomScale: Double): Point
unsubscribe
Link copied to clipboard

Unsubscribes an Observer from all events.

open override fun unsubscribe(observer: Observer)

Unsubscribes an Observer from a provided list of event types.

open override fun unsubscribe(observer: Observer, events: List<String>)