TomTom Maps for JavaScript
    Preparing search index...

    Type Alias StyleChangeHandler

    Handler interface for responding to map style changes.

    This interface defines callbacks that are invoked when the map style changes via TomTomMap.setStyle. Use this to perform cleanup or reinitialization of custom map features when styles are switched.

    Lifecycle:

    1. onStyleAboutToChange - Called before the new style is applied
    2. Style change occurs
    3. onStyleChanged - Called after the new style has been fully loaded

    Common Use Cases:

    • Saving and restoring custom layers or sources
    • Reinitializing map modules after style changes
    • Updating UI components based on the new style
    • Cleaning up resources tied to the previous style
    const styleHandler: StyleChangeHandler = {
    onStyleAboutToChange: () => {
    console.log('Style changing - saving state...');
    // Save custom layer data
    },
    onStyleChanged: () => {
    console.log('Style changed - restoring state...');
    // Restore custom layers
    }
    };

    const unsubscribe = map.addStyleChangeHandler(styleHandler);
    // Call unsubscribe() when the handler's owner is torn down.
    type StyleChangeHandler = {
        onStyleAboutToChange?: (
            context: StyleChangeContext,
        ) => void | Promise<void>;
        onStyleChanged?: (context: StyleChangeContext) => void | Promise<void>;
    }
    Index
    onStyleAboutToChange?: (context: StyleChangeContext) => void | Promise<void>

    Callback invoked immediately before a style change begins.

    Type Declaration

    Use this to perform cleanup or save state before the current style is removed. This method 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.

    onStyleChanged?: (context: StyleChangeContext) => void | Promise<void>

    Callback invoked after a new style has been fully loaded.

    Type Declaration

    Use this to restore state, reinitialize layers, or perform other setup that depends on the new style being ready. This method can be synchronous or asynchronous: handlers run one after the other, in registration order, and the promise returned by TomTomMap.setStyle resolves only once the last one has finished.