Style

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

Link copied to clipboard
object Companion

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

Link copied to clipboard
fun interface OnStyleLoaded

Callback to be invoked when a style has finished loading.

Functions

Link copied to clipboard
open override fun addGeoJSONSourceFeatures(sourceId: String, dataId: String, features: List<Feature>): Expected<String, None>

Add additional features to a GeoJSON style source.

Link copied to clipboard
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>
Link copied to clipboard
open override fun addPersistentStyleCustomLayer(layerId: String, layerHost: CustomLayerHost, layerPosition: LayerPosition?): Expected<String, None>

Adds a new style custom layer.

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

Adds a new style layer.

Link copied to clipboard

Adds a custom geometry to be used in the style. To add the data, implement the CustomGeometrySourceOptions.fetchTile@MainThread override function callback in the options and call setStyleCustomGeometrySourceTileData

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

Adds a new style custom layer.

Link copied to clipboard

Note! This is an experimental feature. It can be changed or removed in future versions.

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.

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

Adds a new style layer.

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.

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

Adds a new style source.

Link copied to clipboard

Gets the value of a style atmosphere property.

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

Get an image from the style.

Link copied to clipboard

Gets style import config.

Link copied to clipboard

Gets the value of style import config.

Link copied to clipboard

Returns the existing style imports.

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

Gets style import schema.

Link copied to clipboard

Gets style layer properties.

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

Gets the value of style layer property.

Link copied to clipboard

Gets the value of the style light property.

Link copied to clipboard

Gets added lights to the style.

Link copied to clipboard

Gets the value of a style projection property.

Link copied to clipboard

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

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

Gets the value of style source property.

Link copied to clipboard

Get the value of a style terrain property.

Link copied to clipboard

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.

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

Checks whether an image exists.

Link copied to clipboard

Checks whether a model exists.

Invalidate region for provided custom geometry source.

Link copied to clipboard

Invalidate tile for provided custom geometry source.

Link copied to clipboard

Note! This is an experimental feature. It can be changed or removed in future versions.

Link copied to clipboard

Note! This is an experimental feature. It can be changed or removed in future versions.

Link copied to clipboard

Checks if a style layer is persistent.

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

Check if the style is completely loaded.

Link copied to clipboard

Whether the Style instance is valid.

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

Moves an existing style layer.

Link copied to clipboard
open override fun removeGeoJSONSourceFeatures(sourceId: String, dataId: String, featureIds: List<String>): Expected<String, None>

Remove features from a GeoJSON style source.

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

Removes an image from the style.

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

Removes an existing style import.

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

Removes an existing style layer

Link copied to clipboard

Removes a model from the style.

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

Removes an existing style source.

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

Sets the style global atmosphere properties.

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

Sets a value to the the style atmosphere property.

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.

Link copied to clipboard

Note! This is an experimental feature. It can be changed or removed in future versions.

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

Set geojson source data. Call may take significant time for parsing and marshalling depending on the data size.

Link copied to clipboard

Sets style import config. This method can be used to perform batch update for a style import configurations.

Link copied to clipboard
open override fun setStyleImportConfigProperty(importId: String, config: String, value: Value): Expected<String, None>

Sets a value to a style import config.

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

Sets style layer metadata.

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.

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

Sets a value to the light property.

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

Sets lights to the style.

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.

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

Sets a value to the the style projection property.

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.

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. Note: When setting the "data" property of a geojson source, this method does not synchronously parse the GeoJSON data. The events API shall be used to make sure the provided GeoJSON data is valid. In case the GeoJSON is valid, a MapLoaded event will be propagated. In case of errors, a MapLoadingError event will be propagated instead.

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

Sets the style global terrain source properties.

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

Sets the value of a style terrain property.

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

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

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

Checks whether a given style layer exists.

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

Checks whether a given style source exists.

Link copied to clipboard
open override fun updateGeoJSONSourceFeatures(sourceId: String, dataId: String, features: List<Feature>): Expected<String, None>

Update existing features in a GeoJSON style source.

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

Updates the image of an image style source.

Properties

Link copied to clipboard
Link copied to clipboard

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

Link copied to clipboard
open override val styleJSON: String

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

Link copied to clipboard
open override val styleLayers: List<StyleObjectInfo>

Returns the existing style layers.

Link copied to clipboard
val styleManager: StyleManager
Link copied to clipboard

Returns the existing style sources.

Link copied to clipboard
open override val styleURI: String

Get the styleURI of the current Mapbox Style in use.

Extensions

Link copied to clipboard

Extension function to add an image provided by the Style Extension to the Style.

Link copied to clipboard

Extension function to add 9-patch image provided by the Style Extension to the Style.

fun MapboxStyleManager.addImage9Patch(imageId: String, bitmap: Bitmap, scale: Float = pixelRatio, sdf: Boolean = false): Expected<String, None>

Adds an 9-patch image to be used in the style. X-stretches, Y-stretches and padding will be calculated from Bitmap.getNinePatchChunk.

Link copied to clipboard

Extension function to add a Layer provided by the Style Extension to the Style.

Link copied to clipboard

Extension function to add a Layer provided by the Style Extension to the Style.

Link copied to clipboard

Extension function to add a Layer provided by the Style Extension to the Style.

Link copied to clipboard

Extension function to add a Layer provided by the Style Extension to the Style.

Link copied to clipboard

Extension function to add a model provided by the Style Extension to the Style.

Link copied to clipboard

Add layer to the style persistently.

Link copied to clipboard

Extension function to add a Source provided by the Style Extension to the Style.

Link copied to clipboard

Extension function to get the atmosphere provided by the Style Extension.

Link copied to clipboard

Extension function to get a Layer provided by the Style Extension by layer id.

Link copied to clipboard
inline fun <T : Layer> MapboxStyleManager.getLayerAs(layerId: String): T?

Tries to cast the Layer to T.

Link copied to clipboard

Extension function to get 3D Light that has been applied to the style.

Link copied to clipboard

Extension function to get the projection provided by the Style Extension.

Link copied to clipboard

Extension function to get a Source provided by the Style Extension by source id.

Link copied to clipboard
inline fun <T : Source> MapboxStyleManager.getSourceAs(sourceId: String): T?

Tries to cast the Source to T.

Link copied to clipboard

Extension function to get the terrain provided by the Style Extension.

Link copied to clipboard

Extension function to localize style labels

Link copied to clipboard

Removes atmosphere from style if it was set.

Link copied to clipboard

Removes terrain from style if it was set.

Link copied to clipboard

Extension function to set the Atmosphere provided by the Style Extension to the Style.

Link copied to clipboard
fun MapboxStyleManager.setLight(ambientLight: AmbientLight, directionalLight: DirectionalLight)

Extension function to add dynamic light to the Style. dynamic light is built from AmbientLight and DirectionalLight.

Extension function to add the FlatLight to the Style.

Link copied to clipboard

Extension function to add list of lights.

Link copied to clipboard

Extension function to set the Projection provided by the Style Extension to the Style.

Link copied to clipboard

Extension function to set the Terrain provided by the Style Extension to the Style.