Style
Style provides access to the APIs used to dynamically modify the map’s style. Use it to read and write layers, sources, and images. Obtain the Style instance for a MapView via MapView.mapboxMap.style.
Important
Style should only be used from the main thread.-
Adds a
layer
to the mapThrows
StyleError
if there is a problem adding the givenlayer
at the givenposition
. -
Adds a persistent
layer
to the map. Persistent layers are valid acrossstyle
changes.Throws
StyleError
if there is a problem adding the persistent layer. -
Moves a
layer
to a new layer position in the style.Throws
StyleError
on failure, orNSError
with a _domain of “com.mapbox.bindgen” -
Gets a
layer
from the mapThrows
StyleError
if there is a problem getting the layer data.Throws
TypeConversionError
is there is a problem decoding the layer data to the giventype
. -
Gets a
layer
from the map.This function is useful if you do not know the concrete type of the layer you are fetching, or don’t need to know for your situation.
Throws
Type conversion errors
-
Updates a
layer
that exists in thestyle
alreadyThrows
TypeConversionError
if there is a problem getting a layer data.Throws
StyleError
if there is a problem updating the layer.Throws
An error when executing
update
block.
-
Adds a
source
to the mapThrows
StyleError
if there is a problem adding thesource
. -
Retrieves a
source
from the mapThrows
StyleError
if there is a problem getting the source data.Throws
TypeConversionError
if there is a problem decoding the source data to the giventype
. -
Retrieves a
source
from the mapThis function is useful if you do not know the concrete type of the source you are fetching, or don’t need to know for your situation.
Throws
StyleError
if there is a problem getting the source data. -
Updates the
data
property of a givenGeoJSONSource
with a new value conforming to theGeoJSONObject
protocol.Throws
StyleError
if there is a problem when updating GeoJSON source.Attention
This method is only effective with sources of
GeoJSONSource
type, and cannot be used to update other source types. -
true
if and only if the style JSON contents, the style specified sprite, and sources are all loaded, otherwise returnsfalse
. -
Get or set the style URI
Setting a new style is asynchronous. In order to get the result of this operation, listen to
MapEvents.styleDataLoaded
,MapEvents.styleLoaded
.Attention
This method should be called on the same thread where the MapboxMap object is initialized. -
Get or set the style via a JSON serialization string
Attention
This method should be called on the same thread where the MapboxMap object is initialized. -
Get or set the map
style
‘s transition options.By default, the style parser will attempt to read the style default transition, if any, falling back to a 0.3 s transition otherwise.
Overridden transitions are reset once a new style has been loaded. To customize the transition used when switching styles, set this property after
MapEvents.EventKind.styleDataLoaded
whereEvent.type == "style"
and beforeMapEvents.EventKind.styleDataLoaded
whereEvent.type == "sprite"
and whereEvent.type == "sources"
.See also
MapboxMap/onNext(_:handler:)
-
Adds a new style layer given its JSON properties
Runtime style layers are valid until they are either removed or a new style is loaded.
See
See Also: https://docs.mapbox.com/mapbox-gl-js/style-spec/#layers
Throws
An error describing why the operation was unsuccessful.
-
Adds a new persistent style layer given its JSON properties
Persistent style layers remain valid across style reloads.
Throws
An error describing why the operation was unsuccessful
-
Returns
true
if the id passed in is associated to a persistent layer -
Adds a new persistent style custom layer.
Persistent style layers are valid across style reloads.
See
See Also: https://docs.mapbox.com/mapbox-gl-js/style-spec/#layers
Throws
An error describing why the operation was unsuccessful.
-
Adds a new style custom layer.
Runtime style layers are valid until they are either removed or a new style is loaded.
See
See Also: https://docs.mapbox.com/mapbox-gl-js/style-spec/#layers
Throws
An error describing why the operation was unsuccessful.
-
Removes an existing style layer
Runtime style layers are valid until they are either removed or a new style is loaded.
Throws
An error describing why the operation was unsuccessful.
-
Checks whether a given style layer exists.
Runtime style layers are valid until they are either removed or a new style is loaded.
-
The ordered list of the current style layers’ identifiers and types
-
Gets the value of style layer property.
-
Gets the value of style layer property.
-
Sets a JSON value to a style layer property.
Throws
An error describing why the operation was unsuccessful.
-
Gets the default value of style layer property.
-
Gets the properties for a style layer.
Throws
An error describing why the operation was unsuccessful.
-
Sets style layer properties.
This method can be used to perform batch update for a style layer properties. The structure of a provided
properties
value must conform to the format for a corresponding layer type.Modification of a layer identifier and/or layer type is not allowed.
Throws
An error describing why the operation was unsuccessful.
-
Adds a new style source.
See
See Also: https://docs.mapbox.com/mapbox-gl-js/style-spec/#sources
Throws
An error describing why the operation was unsuccessful.
-
Removes an existing style source.
Throws
An error describing why the operation was unsuccessful.
-
Checks whether a given style source exists.
-
The ordered list of the current style sources’ identifiers and types. Identifiers for custom vector sources will not be included
-
Gets the value of style source property.
-
Sets a value to a style source property.
Throws
An error describing why the operation was unsuccessful.
-
Gets style source properties.
Throws
An error describing why the operation was unsuccessful.
-
Sets style source properties.
This method can be used to perform batch update for a style source properties. The structure of a provided
properties
value must conform to the format for a corresponding source type. Modification of a source type is not allowed.Throws
An error describing why the operation was unsuccessful.
-
Gets the default value of style source property.
-
Updates the image of an image style source.
Throws
An error describing why the operation was unsuccessful.
-
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
, andline-pattern
.For more information on how
stretchX
andstretchY
parameters affect image stretching see this Mapbox GL-JS example.Throws
An error describing why the operation was unsuccessful.
-
Adds an image to be used in the style.
If the image has non-zero
UIImage.capInsets
it will be stretched accordingly, regardless of the value inUIImage.resizingMode
.Throws
An error describing why the operation was unsuccessful.
-
Removes an image from the style.
Throws
An error describing why the operation was unsuccessful.
-
Checks whether an image exists.
-
Get an image from the style.
-
Sets a light on the style.
Throws
An error describing why the operation was unsuccessful.
-
Sets the style global light source properties.
See
See Also: https://docs.mapbox.com/mapbox-gl-js/style-spec/#light
Throws
An error describing why the operation was unsuccessful.
-
Sets a value to the style light property.
Throws
An error describing why the operation was unsuccessful.
-
Gets the value of a style light property.
-
Sets a terrain on the style
Throws
An error describing why the operation was unsuccessful.
-
Removes terrain from style if it was set.
-
Sets the style global terrain source properties.
See
See Also: https://docs.mapbox.com/mapbox-gl-js/style-spec/#terrain
Throws
An error describing why the operation was unsuccessful.
-
Sets a value to the named style terrain property.
Throws
An error describing why the operation was unsuccessful.
-
Gets the value of a style terrain property.
-
Set the atmosphere of the style
-
Remove the atmosphere of the style. No fog, space or stars would be rendered.
-
Set an explicit atmosphere properties
See
See Also style-spec/fog
Throws
An error describing why the operation was unsuccessful.
-
Sets the value of a style atmosphere property.
See
See Also style-spec/fog
Throws
An error describing why the operation was unsuccessful.
-
Gets the value of a style atmosphere property.
See
See Also: https://docs.mapbox.com/mapbox-gl-js/style-spec/fog/
-
Adds a custom geometry to be used in the style.
To add the data, implement the fetchTileFunction callback in the options and call
setCustomGeometrySourceTileData
.Throws
An error describing why the operation was unsuccessful.
-
Set tile data of a custom geometry.
Throws
An error describing why the operation was unsuccessful.
-
Invalidate tile for provided custom geometry source.
Throws
An error describing why the operation was unsuccessful.
-
Invalidate region for provided custom geometry source.
Throws
An error describing why the operation was unsuccessful.
-
This function creates an expression that will localize the
textField
property of aSymbolLayer
-
Sets the projection.
Throws
StyleError
if the projection could not be applied. -
The current projection.