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 getStyleAsync() method on MapboxMap.

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

class Style : StyleInterface

Types

Companion
Link copied to clipboard

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

object Companion
OnStyleLoaded
Link copied to clipboard

Callback to be invoked when a style has finished loading.

fun fun interface OnStyleLoaded

Functions

addImage
Link copied to clipboard

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.

The image can be used in icon-image, fill-pattern, and line-pattern.

See https://www.mapbox.com/mapbox-gl-js/style-spec/#layout-symbol-icon-image See https://www.mapbox.com/mapbox-gl-js/style-spec/#paint-line-line-pattern See https://www.mapbox.com/mapbox-gl-js/style-spec/#paint-fill-fill-pattern

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>
addPersistentStyleCustomLayer
Link copied to clipboard

Adds a new style custom layer.

Note: This is an experimental API and is a subject to change.

Whenever a new style is being parsed and currently used style has persistent layers, an engine will try to do following:

  • keep the persistent layer at its relative position

  • keep the source used by a persistent layer

  • keep images added through addStyleImage method

In cases when a new style has the same layer, source or image resource, style's resources would be used instead and MapLoadingError event will be emitted.

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

Adds a new style layer.

Note: This is an experimental API and is a subject to change.

Whenever a new style is being parsed and currently used style has persistent layers, an engine will try to do following:

  • keep the persistent layer at its relative position

  • keep the source used by a persistent layer

  • keep images added through addStyleImage method

In cases when a new style has the same layer, source or image resource, style's resources would be used instead and MapLoadingError event will be emitted.

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

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

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

Adds a new style custom layer.

style-spec#layers

Runtime style layers are valid until they are either removed or a new style is loaded.

Note: Custom layers are only valid on OpenGL rendering backend. Attempting to add a custom layer on Metal rendering backend results in undefined behavior.

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

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.

The image can be used in icon-image, fill-pattern, and line-pattern.

See https://www.mapbox.com/mapbox-gl-js/style-spec/#layout-symbol-icon-image See https://www.mapbox.com/mapbox-gl-js/style-spec/#paint-line-line-pattern See https://www.mapbox.com/mapbox-gl-js/style-spec/#paint-fill-fill-pattern

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

Adds a new style layer.

See https://docs.mapbox.com/mapbox-gl-js/style-spec/#layers

Runtime style layers are valid until they are either removed or a new style is loaded.

open override fun addStyleLayer(parameters: Value, position: LayerPosition?): Expected<String, None>
addStyleSource
Link copied to clipboard
open override fun addStyleSource(sourceId: String, properties: Value): Expected<String, None>
equals
Link copied to clipboard
open operator override fun equals(other: Any?): Boolean
getStyleDefaultCamera
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:

The style default camera is re-evaluated when a new style is loaded.

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

Get an image from the style.

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

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

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

Gets style layer properties.

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

Gets the value of style layer \p property.

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

Returns the existing style layers.

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

Gets the value of a style light property.

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

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

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

Gets the value of style source property.

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

Returns the existing style sources.

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

Returns the current sources metadata.

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

Get the value of a style terrain property.

open override fun getStyleTerrainProperty(property: String): StylePropertyValue
getStyleTransition
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 overriden via setStyleTransition, but the options are reset once a new style has been loaded.

The style transition is re-evaluated when a new style is loaded.

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

Get the URI of the current Mapbox Style in use.

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

Invalidate region for provided custom geometry source.

open override fun invalidateStyleCustomGeometrySourceRegion(sourceId: String, coordinateBounds: CoordinateBounds): Expected<String, None>
invalidateStyleCustomGeometrySourceTile
Link copied to clipboard

Invalidate tile for provided custom geometry source.

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

Checks if a style layer is persistent.

Note: This is an experimental API and is a subject to change.

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

Check if the style is completely loaded.

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

Moves an existing style layer.

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

Removes an image from the style.

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

Removes an existing style layer

Runtime style layers are valid until they are either removed or a new style is loaded.

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

Removes an existing style source.

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

Set tile data of a custom geometry.

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

Load the style from a provided JSON string.

attention This method should be called on the same thread where Map object is initialized.

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

Sets style layer metadata.

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

Sets a value to a style layer property.

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

Sets the style global light source properties.

See https://docs.mapbox.com/mapbox-gl-js/style-spec/#light

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

Sets a value to the the style light property.

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

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 \sa https://docs.mapbox.com/mapbox-gl-js/style-spec/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.

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

Sets a value to a style source property.

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

Sets the style global terrain source properties.

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

Gets the value of a style terrain property.

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

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

The style transition is re-evaluated when a new style is loaded.

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

Load style from provided URI.

This is an asynchronous call. In order to get result of this operation please use OnStyleLoadedListener, OnStyleDataLoadedListener or OnMapLoadErrorListener. In case of successful style load you should get notified by OnStyleLoadedListener.

And in case of error @see MapLoadError#StyleLoadError will be generated.

\attention This method should be called on the same thread where @see Map object is initialized.

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

Checks whether a given style layer exists.

Runtime style layers are valid until they are either removed or a new style is loaded.

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

Checks whether a given style source exists.

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

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.

open override fun subscribe(observer: Observer, events: MutableList<String>)
toString
Link copied to clipboard
open override fun toString(): String
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: MutableList<String>)
updateStyleImageSourceImage
Link copied to clipboard

Updates the image of an image style source.

See https://docs.mapbox.com/mapbox-gl-js/style-spec/#sources-image

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

Properties

pixelRatio
Link copied to clipboard

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

open override val pixelRatio: Float