loadStyle

fun loadStyle(style: String, onStyleLoaded: Style.OnStyleLoaded? = null)

Loads the new map style either from a specified URI or from a JSON both represented as String.

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.

If style is not the valid URI - it will be treated as style JSON string.

** Important notes comparing to Maps v10 **:

  1. Parameter onMapLoadErrorListener was removed as it was not covering all the map / style loading errors. Now if you need to listen to those errors you have to register specific listener in advance, e.g. OnMapLoadErrorListener should now be registered with subscribeMapLoadingError; you could also subscribe to other events like subscribeStyleImageMissing or subscribeStyleImageRemoveUnused.

  2. Parameter styleTransitionOptions was removed from this overloaded method. In order to apply it you should use more granular overloaded loadStyle taking StyleContract.StyleExtension and add transition options in DSL block:

mapboxMap.loadStyle(style(Style.DARK) { +transition { duration(100L) enablePlacementTransitions(false) } // other runtime styling }

Parameters

style

specified URI or from JSON both represented as String.

onStyleLoaded

callback triggered when the style is successfully loaded.


fun loadStyle(styleExtension: StyleContract.StyleExtension, onStyleLoaded: Style.OnStyleLoaded? = null)

Loads the new map style built from the specified style DSL block. For example:

mapboxMap.loadStyle(style(Style.DARK) { +geoJsonSource(SOURCE_ID) { featureCollection(collection) } +symbolLayer(LAYER_ID, SOURCE_ID) { iconImage(IMAGE_ID) } }

** Important notes comparing to Maps v10 **:

  1. Parameter onMapLoadErrorListener was removed as it was not covering all the map / style loading errors. Now if you need to listen to those errors you have to register specific listener in advance, e.g. OnMapLoadErrorListener should now be registered with subscribeMapLoadingError; you could also subscribe to other events like subscribeStyleImageMissing or subscribeStyleImageRemoveUnused.

  2. Parameter styleTransitionOptions was removed from this overloaded method. Instead you have to add transition options in the DSL block:

mapboxMap.loadStyle(style(Style.DARK) { +transition { duration(100L) enablePlacementTransitions(false) } // other runtime styling }

Parameters

styleExtension

The style DSL block used to describe the style with runtime styling on top of it.

onStyleLoaded

callback triggered when the style is successfully loaded.


fun loadStyle(styleExtension: StyleContract.StyleExtension, styleTransitionOptions: TransitionOptions? = null, onStyleLoaded: Style.OnStyleLoaded? = null, onMapLoadErrorListener: OnMapLoadErrorListener? = null)

Deprecated

Loading style was revisited in v11, this method is deprecated. IMPORTANT: onMapLoadErrorListener and styleTransitionOptions will not be applied anymore, please refer to documentation for new method to understand how to apply them properly.

Replace with

loadStyle(styleExtension, onStyleLoaded)

Legacy method to load style, please refer to deprecation message for more details.


fun loadStyle(styleExtension: StyleContract.StyleExtension, onStyleLoaded: Style.OnStyleLoaded? = null, onMapLoadErrorListener: OnMapLoadErrorListener? = null)

Deprecated

Loading style was revisited in v11, this method is deprecated. IMPORTANT: onMapLoadErrorListener will not be triggered anymore, please refer to documentation for new method to understand how to handle errors.

Replace with

loadStyle(styleExtension, onStyleLoaded)

Legacy method to load style, please refer to deprecation message for more details.