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
    }
    };

    map.addStyleChangeHandler(styleHandler);
    type StyleChangeHandler = {
        onStyleAboutToChange?: () => void | Promise<void>;
        onStyleChanged?: () => void | Promise<void>;
    }
    Index

    Properties

    onStyleAboutToChange?: () => void | Promise<void>

    Callback invoked immediately before a style change begins.

    Type Declaration

      • (): void | Promise<void>
      • Returns void | Promise<void>

        void or a Promise that resolves when preparation is complete

    Use this to perform cleanup or save state before the current style is removed. This method can be synchronous or asynchronous.

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

    Callback invoked after a new style has been fully loaded.

    Type Declaration

      • (): void | Promise<void>
      • Returns void | Promise<void>

        void or a Promise that resolves when reinitialization is complete

    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.