TomTom Maps for JavaScript
    Preparing search index...

    Class TrafficAreaAnalyticsModule

    Traffic Area Analytics visualization module.

    Renders area-analytics data on the map in one of five modes:

    • hexgrid-3d — 3D extruded hexagonal cells coloured and raised by the active metric (default)
    • hexgrid-2d — Flat hexagonal cells coloured by the active metric
    • square-3d — 3D extruded square cells coloured and raised by the active metric
    • square-2d — Flat square cells coloured by the active metric
    • heatmap — a MapLibre density-heatmap layer built from tile-centre points

    The actual region boundary is always rendered alongside the analytics cells.

    Quick start:

    import { TrafficAreaAnalyticsModule } from '@tomtom-org/maps-sdk/map';
    import { trafficAreaAnalytics } from '@tomtom-org/maps-sdk/services';

    const module = await TrafficAreaAnalyticsModule.get(map, {
    displayMode: 'hexgrid-3d',
    metric: { active: 'congestionLevel' },
    });
    const analytics = await trafficAreaAnalytics({ ... });
    await module.show(analytics);

    Hierarchy (View Summary)

    Index

    Accessors

    • get sourceAndLayerIDs(): Record<keyof SOURCES_WITH_LAYERS, SourceWithLayerIDs>

      Gets the source and layer identifiers for all sources managed by this module.

      This property provides access to the MapLibre source and layer IDs that were created and are managed by this module. These IDs can be used to interact directly with MapLibre's API or to identify which layers belong to this module.

      Returns Record<keyof SOURCES_WITH_LAYERS, SourceWithLayerIDs>

      A record mapping each source name to its corresponding source ID and layer IDs. Each entry contains the MapLibre source identifier and an array of layer identifiers associated with that source.

      The returned IDs are useful when you need to:

      • Directly manipulate layers using MapLibre's native API
      • Identify which layers on the map belong to this module
      • Set layer ordering or positioning relative to other layers
      • Access source or layer properties through MapLibre methods
      const ids = myModule.sourceAndLayerIDs;
      console.log(ids);
      // {
      // mySource: {
      // sourceID: 'my-source-id',
      // layerIDs: ['layer-1', 'layer-2']
      // }
      // }

      // Use with MapLibre API
      const map = myModule.mapLibreMap;
      ids.mySource.layerIDs.forEach(layerId => {
      map.setLayoutProperty(layerId, 'visibility', 'visible');
      });

    Methods

    • Applies a configuration to this module.

      This method updates the module's behavior and appearance based on the provided configuration. The configuration is stored internally and will be automatically reapplied if the map style changes.

      Parameters

      • config: TrafficAreaAnalyticsConfig | undefined

        The configuration object to apply to the module. Pass undefined to reset the configuration to default values.

      Returns void

      When a configuration is applied, the module updates its visual representation and behavior accordingly. The configuration persists across map style changes, ensuring consistent module behavior even when the map's base style is modified.

      // Apply a new configuration
      myModule.applyConfig({ visible: true, opacity: 0.8 });

      // Reset to default configuration
      myModule.applyConfig(undefined);
      • resetConfig for a convenience method to reset configuration
      • getConfig to retrieve the current configuration
    • Removes all area analytics data from the map.

      Returns Promise<void>

    • Clears any active tile filter for one or more metrics.

      Parameters

      • Optionalmetrics: ("speed" | "freeFlowSpeed" | "congestionLevel" | "travelTime" | "networkLength")[]

        Optional list of metrics to clear. When omitted, clears filters for all metrics.

      Returns void

    • Filters visible tiles by value range for one or more metrics.

      Parameters

      • Optionalfilter: AreaAnalyticsMetricFilter

        Filter config. Pass undefined to clear.

      • Optionalmetrics: ("speed" | "freeFlowSpeed" | "congestionLevel" | "travelTime" | "networkLength")[]

        Optional list of metrics to target. When omitted, the filter is applied to all metrics.

      Returns void

      // Filter all metrics
      module.filter({ min: 20, max: 80 });

      // Filter only a specific metric
      module.filter({ min: 50 }, ['congestionLevel']);

      // Clear filter for all metrics
      module.filter(undefined);
    • Retrieves a copy of the current module configuration.

      This method returns a shallow copy of the configuration object that is currently applied to the module. If no configuration has been applied, it returns undefined.

      Returns NonNullable<TrafficAreaAnalyticsConfig> | undefined

      A shallow copy of the current configuration object, or undefined if no configuration is currently applied. The returned object is a copy to prevent unintended modifications to the internal state.

      The returned configuration object is a shallow copy, which means that while the top-level properties are copied, any nested objects or arrays are still referenced from the original configuration. This is sufficient for most use cases but should be kept in mind when dealing with complex configurations.

      // Apply a configuration
      myModule.applyConfig({ visible: true, opacity: 0.8 });

      // Later, retrieve the current configuration
      const currentConfig = myModule.getConfig();
      console.log(currentConfig); // { visible: true, opacity: 0.8 }

      // When no config is applied
      myModule.resetConfig();
      console.log(myModule.getConfig()); // undefined
    • Whether any area analytics (data) layer is currently visible.

      Returns boolean

    • Repositions analytics layers independently by layer type.

      Only the properties present in layerConfig are repositioned; omitted layer types are left in place.

      Parameters

      Returns void

    • Resets the configuration of this module to its default values.

      This is a convenience method that clears any previously applied configuration and restores the module to its initial state. This is equivalent to calling applyConfig(undefined).

      Returns void

      After calling this method, the module will behave as if no configuration was ever applied. Any custom settings, styling, or behavior modifications will be removed and replaced with default values.

      // Apply some configuration
      myModule.applyConfig({ visible: true, opacity: 0.5 });

      // Later, reset to defaults
      myModule.resetConfig();
      • applyConfig to apply a new configuration
      • getConfig to retrieve the current configuration before resetting
    • Sets the color for one or more metrics.

      Pass a preset theme name or a custom color-stops configuration. Pass undefined to clear the color override for the targeted metrics.

      Parameters

      • color: AreaAnalyticsColorTheme | AreaAnalyticsColorStopsConfig | undefined

        A preset theme, an AreaAnalyticsColorStopsConfig, or undefined to clear.

      • Optionalmetrics: ("speed" | "freeFlowSpeed" | "congestionLevel" | "travelTime" | "networkLength")[]

        Optional list of metrics to target. When omitted, the color is applied to all metrics.

      Returns void

      // Apply a theme to all metrics
      module.setColor('heat');

      // Apply a theme to specific metrics only
      module.setColor('heat', ['speed', 'freeFlowSpeed']);

      // Apply custom stops to a single metric
      module.setColor(
      { valueType: 'raw', stops: [{ value: 0, color: '#2dc653' }, { value: 100, color: '#e03030' }] },
      ['congestionLevel'],
      );

      // Clear color override for all metrics
      module.setColor(undefined);

      // Clear color override for a specific metric
      module.setColor(undefined, ['speed']);
    • Configures extrusion height behaviour for one or more metrics.

      Parameters

      • heightConfig: AreaAnalyticsHeightConfig

        Height configuration.

      • Optionalmetrics: ("speed" | "freeFlowSpeed" | "congestionLevel" | "travelTime" | "networkLength")[]

        Optional list of metrics to target. When omitted, the height config is applied to all metrics.

      Returns void

      // Apply to all metrics
      module.setHeight({ maxHeightMeters: 100, minHeightMeters: 5 });

      // Apply only to specific metrics
      module.setHeight({ scaleMode: 'currentRange', maxHeightMeters: 500 }, ['speed', 'freeFlowSpeed']);
    • Changes the active metric that drives colour and height.

      Updates activeMetric in the config to the given metric key.

      Parameters

      • metric: "speed" | "freeFlowSpeed" | "congestionLevel" | "travelTime" | "networkLength"

        One of 'congestionLevel', 'speed', 'travelTime', 'freeFlowSpeed', or 'networkLength'.

      Returns void

    • Shows or hides all area analytics layers.

      Parameters

      • visible: boolean

      Returns void

    • Displays area analytics data on the map.

      Accepts the raw response from trafficAreaAnalytics(). Tile data is transformed internally to point features (heatmap), hexagonal polygons (hexgrid modes), and square polygons (square modes). The region boundary geometry is also displayed.

      Parameters

      Returns Promise<void>

      const analytics = await trafficAreaAnalytics({ ... });
      await module.show(analytics);
    • Creates and initialises a new Traffic Area Analytics module.

      All configuration properties are optional. When config is omitted (or only partially supplied), built-in defaults are applied for every missing field. After get() resolves, TrafficAreaAnalyticsModule.getConfig always returns a fully-populated configuration — there is no need to reference any default values yourself.

      Parameters

      Returns Promise<TrafficAreaAnalyticsModule>

      A promise that resolves with the initialised module.

      // No config needed — defaults are applied automatically.
      const module = await TrafficAreaAnalyticsModule.get(map);
      await module.show(analytics);

      // Or override specific properties while keeping everything else at default:
      const module = await TrafficAreaAnalyticsModule.get(map, {
      displayMode: 'heatmap',
      metricConfig: {
      congestionLevel: { color: 'heat' },
      },
      });