This is the documentation of version 1.0.0-rc.0. Go to the latest version, 1.0.0-rc.5.
TomTom Maps for JavaScript
    Preparing search index...

    Class CombinedEvents<T, CFG, TShown, WHERE_SCOPE>

    A module's user interaction and lifecycle events under a single on / off surface.

    User event types (click, contextmenu, hover, long-hover) are handled by the underlying UserEvents instance and removed with off.

    Module lifecycle event types (config-change, shown-features) are handled by the underlying ModuleEvents instance. Each on call returns an unsubscribe function. off also removes both user and module event types in bulk.

    Named scopes, where a module has them, hang off this object as properties. Each is a UserEventsWithStates, with user events and event states only, since lifecycle events stay here. where narrows ad hoc instead, and returns a plain UserEvents.

    // User interaction
    const unsub = places.events.on('click', (feature, lngLat) => {
    console.log('Clicked place:', feature.properties.title);
    });

    // Module lifecycle
    const unsubConfig = places.events.on('config-change', (config) => {
    console.log('Config updated:', config);
    });

    const unsubShown = places.events.on('shown-features', (features) => {
    console.log('Shown:', features);
    });

    // Cleanup
    unsub();
    unsubConfig();
    unsubShown();
    places.events.off('click'); // also valid for user events

    Type Parameters

    • T

      Feature type that user interaction handlers receive.

    • CFG

      Module configuration type passed to config-change handlers.

    • TShown = never

      Data type passed to shown-features handlers. Use never for modules that have no show method.

    • WHERE_SCOPE = never

      The module-specific scope object where accepts besides a feature predicate, or never for modules that only support predicates. It is unrelated to a module's named scopes, which are properties on this object rather than an argument to it.

    Index
    • Removes all handlers for the given event type at once.

      It accepts both user interaction types (click, contextmenu, hover, long-hover) and module lifecycle types (config-change, shown-features).

      To remove a single handler, call the unsubscribe function that on returns instead. Use off for bulk teardown, for example when unmounting a component that registered several handlers of the same type.

      Parameters

      • type: EventType | "config-change" | "shown-features"

        The event type whose handlers should all be cleared.

      Returns void

      places.events.off('click');          // clear all click handlers
      places.events.off('config-change'); // clear all config-change handlers
    • Subscribes to a user interaction event (click, contextmenu, hover, long-hover).

      Parameters

      • type: EventType

        The user event type.

      • handler: UserEventHandler<T>

        Called with the feature, click/hover coordinates, all features at the point, and the source configuration.

      Returns () => void

      An unsubscribe function. Call it to remove only this handler.

      const unsub = places.events.on('click', (feature, lngLat) => {
      showPlaceDetails(feature.properties);
      });
      unsub(); // remove only this handler
    • Subscribes to config-change events.

      It fires after applyConfig, setVisible or any module-specific setter changes the configuration. The handler receives the module's full updated configuration.

      Parameters

      • type: "config-change"

        'config-change'

      • handler: (config: CFG | undefined) => void

        Receives the module's config, or undefined when the config is cleared.

      Returns () => void

      An unsubscribe function. Call it to remove only this handler.

      const unsub = trafficFlow.events.on('config-change', (config) => {
      toggle.checked = config?.visible ?? false;
      });
      unsub();
    • Subscribes to shown-features events.

      It fires right after the module's show() method, or its equivalent, renders new data on the map. Only modules that have a show method offer it.

      Parameters

      Returns () => void

      An unsubscribe function. Call it to remove only this handler.

      const unsub = places.events.on('shown-features', (features) => {
      fitMapToResults(features);
      });
      unsub();
    • Narrows these events to part of what they cover, as UserEvents.where does.

      Parameters

      • scope: EventScope<T, WHERE_SCOPE>

        A predicate over this module's feature type or, where the module supports one, a scope object such as { layerGroups } on BaseMapModule. See EventScope.

      • Optionalconfig: EventHandlerConfig

        Event configuration for handlers registered through the returned instance, so each scope can have its own hover cursor.

      Returns UserEvents<T, WHERE_SCOPE>

      A UserEvents covering only the narrowed set. Lifecycle events stay on the module (or named scope) they belong to.

      trafficIncidents.events.where((incident) => incident.properties.magnitudeOfDelay === 'major')
      .on('click', showIncidentDetails);