Style

class Style : StyleInterface

The general class to interact with Styles in the Modular Mapbox Maps SDK for Android. It exposes the entry point for all methods related to the Style. You cannot instantiate Style object directly, rather, you must obtain one from the getStyle(onStyleLoaded) method on MapboxMap.

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

Types

Companion
Link copied to clipboard
object Companion

A convenience object to access the style ID strings of the professionally-designed map styles made by Mapbox.

OnStyleLoaded
Link copied to clipboard
fun interface OnStyleLoaded

Callback to be invoked when a style has finished loading.

Functions

addImage
Link copied to clipboard
open override fun addImage(imageId: String, bitmap: Bitmap): Expected<String, None>
fun addImage(imageId: String, image: Image): Expected<String, None>
fun addImage(imageId: String, bitmap: Bitmap, sdf: Boolean): Expected<String, None>
fun addImage(imageId: String, image: Image, sdf: Boolean): Expected<String, None>

Adds an image to be used in the style. This API can also be used for updating an image. If the image id was already added, it gets replaced by the new image.

addPersistentStyleCustomLayer
Link copied to clipboard
open override fun addPersistentStyleCustomLayer(layerId: String, layerHost: CustomLayerHost, layerPosition: LayerPosition?): Expected<String, None>

Adds a new style custom layer.

addPersistentStyleLayer
Link copied to clipboard
open override fun addPersistentStyleLayer(properties: Value, layerPosition: LayerPosition?): Expected<String, None>

Adds a new style layer.

addStyleCustomGeometrySource
Link copied to clipboard
open override fun addStyleCustomGeometrySource(sourceId: String, options: CustomGeometrySourceOptions): Expected<String, None>

Adds a custom geometry to be used in the style. To add the data, implement the CustomGeometrySourceOptions.fetchTileFunction callback in the options and call setStyleCustomGeometrySourceTileData

addStyleCustomLayer
Link copied to clipboard
open override fun addStyleCustomLayer(layerId: String, layerHost: CustomLayerHost, layerPosition: LayerPosition?): Expected<String, None>

Adds a new style custom layer.

addStyleImage
Link copied to clipboard
open override fun addStyleImage(imageId: String, scale: Float, image: Image, sdf: Boolean, stretchX: List<ImageStretches>, stretchY: List<ImageStretches>, content: ImageContent?): Expected<String, None>

Adds an image to be used in the style. This API can also be used for updating an image. If the image id was already added, it gets replaced by the new image.

addStyleLayer
Link copied to clipboard
open override fun addStyleLayer(parameters: Value, position: LayerPosition?): Expected<String, None>

Adds a new style layer.

addStyleModel
Link copied to clipboard
open override fun addStyleModel(modelId: String, modelUri: String): Expected<String, None>

Adds a model to be used in the style. This API can also be used for updating a model. If the model for a given modelId was already added, it gets replaced by the new model.

addStyleSource
Link copied to clipboard
open override fun addStyleSource(sourceId: String, properties: Value): Expected<String, None>

Adds a new style source.

getStyleAtmosphereProperty
Link copied to clipboard
open override fun getStyleAtmosphereProperty(property: String): StylePropertyValue

Gets the value of a style atmosphere property.

getStyleDefaultCamera
Link copied to clipboard
open override fun getStyleDefaultCamera(): CameraOptions

Returns the map style's default camera, if any, or a default camera otherwise. The map style default camera is defined as follows:

getStyleImage
Link copied to clipboard
open override fun getStyleImage(imageId: String): Image?

Get an image from the style.

getStyleJSON
Link copied to clipboard
open override fun getStyleJSON(): String

Get the JSON serialization string of the current Mapbox Style in use.

getStyleLayerProperties
Link copied to clipboard
open override fun getStyleLayerProperties(layerId: String): Expected<String, Value>

Gets style layer properties.

getStyleLayerProperty
Link copied to clipboard
open override fun getStyleLayerProperty(layerId: String, property: String): StylePropertyValue

Gets the value of style layer property.

getStyleLayers
Link copied to clipboard
open override fun getStyleLayers(): List<StyleObjectInfo>

Returns the existing style layers.

getStyleLightProperty
Link copied to clipboard
open override fun getStyleLightProperty(property: String): StylePropertyValue

Gets the value of a style light property.

open override fun getStyleLightProperty(id: String, property: String): StylePropertyValue

This API is for internal use only and will return a no-op result.

getStyleLights
Link copied to clipboard
open override fun getStyleLights(): MutableList<StyleObjectInfo>

This API is for internal use only and will return a no-op result.

getStyleProjectionProperty
Link copied to clipboard
open override fun getStyleProjectionProperty(property: String): StylePropertyValue

Gets the value of a style projection property.

getStyleSourceProperties
Link copied to clipboard
open override fun getStyleSourceProperties(sourceId: String): Expected<String, Value>

Gets style source parameters. In order to convert returned value to a json string please take a look at Value.toJson.

getStyleSourceProperty
Link copied to clipboard
open override fun getStyleSourceProperty(sourceId: String, property: String): StylePropertyValue

Gets the value of style source property.

getStyleSources
Link copied to clipboard
open override fun getStyleSources(): List<StyleObjectInfo>

Returns the existing style sources.

getStyleSourcesAttribution
Link copied to clipboard
fun getStyleSourcesAttribution(): List<String>

Returns the current sources metadata.

getStyleTerrainProperty
Link copied to clipboard
open override fun getStyleTerrainProperty(property: String): StylePropertyValue

Get the value of a style terrain property.

getStyleTransition
Link copied to clipboard
open override fun getStyleTransition(): TransitionOptions

Returns the map style's transition options. By default, the style parser will attempt to read the style default transition options, if any, fallbacking to an immediate transition otherwise. Transition options can be overridden via setStyleTransition, but the options are reset once a new style has been loaded.

getStyleURI
Link copied to clipboard
open override fun getStyleURI(): String

Get the URI of the current Mapbox Style in use.

hasStyleImage
Link copied to clipboard
open override fun hasStyleImage(imageId: String): Boolean

Checks whether an image exists.

hasStyleModel
Link copied to clipboard
open override fun hasStyleModel(modelId: String): Boolean

Checks whether a model exists.

open override fun invalidateStyleCustomGeometrySourceRegion(sourceId: String, coordinateBounds: CoordinateBounds): Expected<String, None>

Invalidate region for provided custom geometry source.

invalidateStyleCustomGeometrySourceTile
Link copied to clipboard
open override fun invalidateStyleCustomGeometrySourceTile(sourceId: String, tileId: CanonicalTileID): Expected<String, None>

Invalidate tile for provided custom geometry source.

isStyleLayerPersistent
Link copied to clipboard
open override fun isStyleLayerPersistent(layerId: String): Expected<String, Boolean>

Checks if a style layer is persistent.

isStyleLoaded
Link copied to clipboard
open override fun isStyleLoaded(): Boolean

Check if the style is completely loaded.

isValid
Link copied to clipboard
open override fun isValid(): Boolean

Whether the Style instance is valid.

moveStyleLayer
Link copied to clipboard
open override fun moveStyleLayer(layerId: String, layerPosition: LayerPosition?): Expected<String, None>

Moves an existing style layer.

removeStyleImage
Link copied to clipboard
open override fun removeStyleImage(imageId: String): Expected<String, None>

Removes an image from the style.

removeStyleLayer
Link copied to clipboard
open override fun removeStyleLayer(layerId: String): Expected<String, None>

Removes an existing style layer

removeStyleModel
Link copied to clipboard
open override fun removeStyleModel(modelId: String): Expected<String, None>

Removes a model from the style.

removeStyleSource
Link copied to clipboard
open override fun removeStyleSource(sourceId: String): Expected<String, None>

Removes an existing style source.

setStyleAtmosphere
Link copied to clipboard
open override fun setStyleAtmosphere(properties: Value): Expected<String, None>

Sets the style global atmosphere properties.

setStyleAtmosphereProperty
Link copied to clipboard
open override fun setStyleAtmosphereProperty(property: String, value: Value): Expected<String, None>

Sets a value to the the style atmosphere property.

setStyleCustomGeometrySourceTileData
Link copied to clipboard
open override fun setStyleCustomGeometrySourceTileData(sourceId: String, tileId: CanonicalTileID, featureCollection: MutableList<Feature>): Expected<String, None>

Set tile data of a custom geometry.

setStyleGeoJSONSourceData
Link copied to clipboard
open override fun setStyleGeoJSONSourceData(sourceId: String, data: GeoJSONSourceData): Expected<String, None>
open override fun setStyleGeoJSONSourceData(sourceId: String, dataId: String, data: GeoJSONSourceData): Expected<String, None>

This method is for internal use.

setStyleJSON
Link copied to clipboard
open override fun setStyleJSON(json: String)

Load the style from a provided JSON string.

setStyleLayerProperties
Link copied to clipboard
open override fun setStyleLayerProperties(layerId: String, properties: Value): Expected<String, None>

Sets style layer metadata.

setStyleLayerProperty
Link copied to clipboard
open override fun setStyleLayerProperty(layerId: String, property: String, value: Value): Expected<String, None>

Sets a value to a style layer property.

setStyleLight
Link copied to clipboard
open override fun setStyleLight(parameters: Value): Expected<String, None>

Sets the style global light source properties.

setStyleLightProperty
Link copied to clipboard
open override fun setStyleLightProperty(id: String, light: Value): Expected<String, None>

Sets a value to the the style light property.

open override fun setStyleLightProperty(id: String, property: String, value: Value): Expected<String, None>

This API is for internal use only and will return a no-op result.

setStyleLights
Link copied to clipboard
open override fun setStyleLights(lights: Value): Expected<String, None>

This API is for internal use only and will return a no-op result.

setStyleProjection
Link copied to clipboard
open override fun setStyleProjection(properties: Value): Expected<String, None>

Sets the map's projection. If called with null, the map will reset to Mercator.

setStyleProjectionProperty
Link copied to clipboard
open override fun setStyleProjectionProperty(property: String, value: Value): Expected<String, None>

Sets a value to the the style projection property.

setStyleSourceProperties
Link copied to clipboard
open override fun setStyleSourceProperties(sourceId: String, properties: Value): Expected<String, None>

Sets style source parameters. This method can be used to perform batch update for a style source parameters. The structure of a provided parameters value must conform to Style Specification - Sources format for a corresponding source type. Modification of a source type https://docs.mapbox.com/mapbox-gl-js/style-spec/sources/#type is not allowed.

setStyleSourceProperty
Link copied to clipboard
open override fun setStyleSourceProperty(sourceId: String, property: String, value: Value): Expected<String, None>

Sets a value to a style source property.

setStyleTerrain
Link copied to clipboard
open override fun setStyleTerrain(properties: Value): Expected<String, None>

Sets the style global terrain source properties.

setStyleTerrainProperty
Link copied to clipboard
open override fun setStyleTerrainProperty(property: String, value: Value): Expected<String, None>

Sets the value of a style terrain property.

setStyleTransition
Link copied to clipboard
open override fun setStyleTransition(transitionOptions: TransitionOptions)

Overrides the map style's transition options with user-provided options.

setStyleURI
Link copied to clipboard
open override fun setStyleURI(uri: String)

Load style from provided URI.

styleLayerExists
Link copied to clipboard
open override fun styleLayerExists(layerId: String): Boolean

Checks whether a given style layer exists.

styleSourceExists
Link copied to clipboard
open override fun styleSourceExists(sourceId: String): Boolean

Checks whether a given style source exists.

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

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

unsubscribe
Link copied to clipboard
open override fun unsubscribe(observer: Observer)

Unsubscribes an Observer from all events.

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

Unsubscribes an Observer from a provided list of event types.

updateStyleImageSourceImage
Link copied to clipboard
open override fun updateStyleImageSourceImage(sourceId: String, image: Image): Expected<String, None>

Updates the image of an image style source.

Properties

pixelRatio
Link copied to clipboard
open override val pixelRatio: Float

the scale ratio of the style, default the device pixel ratio