OptionalonCalled immediately before a style change begins.
What kind of switch is happening. See StyleChangeContext.
void or a Promise that resolves when preparation is complete
Use it to clean up or save state before the current style is removed. It can be synchronous or asynchronous. The SDK awaits it before handing the new style to MapLibre, so nothing of the old style is torn down while it runs. A TomTomMap.setStyle called while it still runs calls it again, before the first call settles.
OptionalonCalled after a new style has fully loaded.
What kind of switch is happening. See StyleChangeContext.
void or a Promise that resolves when reinitialization is complete
Use it to restore state, reinitialize layers or do other setup that depends on the new style being ready. It can be synchronous or asynchronous. Handlers run one after the other, by StyleChangeHandler.priority, and the promise TomTomMap.setStyle returns resolves only once the last one has finished.
A switch whose style fails to load runs none for its own style, and the map keeps the style it
had: undo what onStyleAboutToChange did from a TomTomMap.addErrorHandler handler. When
that style had loaded for a switch the failed one superseded, they run for it instead, with its
context.
OptionalpriorityWhere this handler runs relative to the others. Lower values run first, and equal values run in
registration order. The default 0 is also what the SDK's data and visibility modules use.
The custom layers of TomTomMap.addCustomLayer go back at -1, before the modules. The
SDK's style knobs land at 90 and the StylingFoundationsModule's raw layer edits at
100, so semantic styling always lands on top of whatever the modules restored.
Callbacks that respond to map style changes.
Remarks
The SDK calls them when the map style changes through TomTomMap.setStyle. Use them to clean up or reinitialize custom map features when the style switches. For example, save and restore custom layers or sources, update UI components for the new style, or clean up resources tied to the previous style. The SDK modules restore or reset themselves in handlers of their own.
The lifecycle is:
onStyleAboutToChangeruns before the new style is applied.onStyleChangedruns after the new style has fully loaded.Example
See