Traffic Flow Module

The Traffic Flow Module controls the map layers that display real-time traffic speed conditions across the entire road network using color-coded road segments. Green indicates free-flowing traffic, yellow/orange represents moderate speeds, and red shows congestion. Dark gray indicates road closures.

import { TomTomConfig } from '@tomtom-org/maps-sdk/core';
import { TomTomMap, TrafficFlowModule } from '@tomtom-org/maps-sdk/map';
import './style.css';
import { API_KEY } from './config';

// (Set your own API key when working in your own environment)
TomTomConfig.instance.put({ apiKey: API_KEY, language: 'en-US' });

(async () => {
    const map = new TomTomMap({
        mapLibre: {
            container: 'sdk-map',
            center: [2.34281, 48.85639],
            zoom: 12,
        },
    });
    await TrafficFlowModule.get(map, { visible: true });
})();

Looking for something else?

Initialization

import { TomTomMap, TrafficFlowModule } from '@tomtom-org/maps-sdk/map';
const map = new TomTomMap( { mapLibre: { container: 'map' } });
const trafficFlowModule = await TrafficFlowModule.get(map);

Visibility

Traffic flow is hidden by default. This helps you control better when you want it to appear on the map.

You can make it visible during initialization:

const trafficFlowModule = await TrafficFlowModule.get(map, { visible: true });

You can change visibility later using the setVisible method.

trafficFlowModule.setVisible(true);

Filtering

A filter can be applied either during module initialization or later using the filter method.

// Initialize with filter
const trafficFlowModule = await TrafficFlowModule.get(map, {
filters: ...,
});
// Apply or update filter later
trafficFlowModule.filter(...);

Road Category

Display traffic flow only for specific road types:

// Show only major highways
trafficFlowModule.filter({
any: [{
roadCategories: {
show: 'only',
values: ['motorway', 'trunk']
}
}]
});
// Hide local streets
trafficFlow.filter({
any: [{
roadCategories: {
show: 'all_except',
values: ['street']
}
}]
});
// Show only major local roads within tertiary category
trafficFlow.filter({
any: [{
roadCategories: {
show: 'only',
values: ['tertiary']
},
roadSubCategories: {
show: 'only',
values: ['major_local']
}
}]
});

Available Road Categories:

  • motorway - Major highways
  • trunk - Major roads
  • primary - Primary roads
  • secondary - Secondary roads
  • tertiary - Tertiary roads
  • street - Local streets

Available Road Subcategories:

  • tertiary
    • connecting - Roads connecting different areas
    • major_local - Major roads within local areas
  • street
    • local - Standard local streets
    • minor_local - Minor residential streets

Road Closures

Display or exclude road closures:

// Show only road closures
trafficFlow.filter({
any: [{ showRoadClosures: 'only' }]
});
// Exclude road closures
trafficFlow.filter({
any: [{ showRoadClosures: 'all_except' }]
});

Multiple Filters

Combine multiple filter criteria using “any” logic:

// Show motorways OR road closures
trafficFlow.filter({
any: [
{ roadCategories: { show: 'only', values: ['motorway'] } },
{ showRoadClosures: 'only' }
]
});

Reset Filters

Remove all filters and show all traffic flow:

trafficFlow.filter(undefined);

Events

Handle user interactions with traffic flow segments:

// Click events
trafficFlow.events.on('click', (feature) => {
...
});
// Hover events
trafficFlow.events.on('hover', (feature) => {
...
});
// Long hover events
trafficFlow.events.on('long-hover', (feature) => {
...
});
// Remove event listeners
trafficFlow.events.off('click', handler);

API Reference

For complete documentation of all Traffic Flow Module properties, methods, and types, see the TrafficFlowModule API Reference .

Traffic Overview

  • Traffic Overview - Overview of all traffic visualization options including flow, incidents, and route-specific traffic