Traffic Incidents Module
The Traffic Incidents Module controls the map layers that display real-time traffic events, such as accidents, road closures, construction, and weather disruptions. Events are displayed across the entire map area and each incident shows its type, severity, affected road segments, and expected delay impact.
Looking for something else?
- For traffic speed conditions (color-coded congestion) across the map, see Traffic Flow Module
- For traffic incidents along a specific route, see Routing Module
Initialization
import { TomTomMap, TrafficIncidentsModule } from '@tomtom-org/maps-sdk/map';
const map = new TomTomMap( { mapLibre: { container: 'map' } } );const trafficIncidentsModule = await TrafficIncidentsModule.get(map);Visibility
Traffic incidents are hidden by default. This helps you control better when you want them to appear on the map.
You can make them visible during initialization:
const trafficIncidentsModule = await TrafficIncidentsModule.get(map, { visible: true });You can change visibility later using the setVisible method.
trafficIncidentsModule.setVisible(true);Icon Visibility
Icons can be controlled separately from incident areas. This allows you to show only the icons, or only the lines, at any time.
// Initialize with visibility set in the configurationconst trafficIncidentsModule = await TrafficIncidentsModule.get(map, { icons: { visible: false, },});
// Show/hide incident icons but keep incident areas visibletrafficIncidentsModule.setIconsVisible(true);trafficIncidentsModule.setIconsVisible(false);
// Check icon visibilityif (trafficIncidentsModule.anyIconLayersVisible()) { console.log('Incident icons are visible');}Filtering
A filter can be applied either during module initialization or later using the filter method.
// Initialize with filterconst trafficIncidentsModule = await TrafficIncidentsModule.get(map, { filters: ...,});
// Apply or update filter latertrafficIncidentsModule.filter(...);Incident Category
Display only specific types of incidents:
// Show only accidents and road closurestrafficIncidentsModule.filter({ any: [{ incidentCategories: { show: 'only', values: ['accident', 'road_closed'] } }]});
// Hide weather-related incidentsincidents.filter({ any: [{ incidentCategories: { show: 'all_except', values: ['rain', 'fog', 'ice', 'wind'] } }]});Available Incident Categories:
accident- Traffic accidentsroad_closed- Complete road closureslane_closed- Lane closuresroad_works- Construction and maintenancejam- Traffic jamsfog,rain,ice,wind,flooding- Weather conditionsdangerous_conditions- Hazardous road conditionsbroken_down_vehicle- Vehicle breakdownsunknown- Incidents with unknown type
Severity
Filter incidents based on their delay magnitude:
// Show moderate and major delaysincidents.filter({ any: [{ magnitudes: { show: 'only', values: ['major', 'moderate'] } }]});Available Magnitudes:
minor- Small delaysmoderate- Moderate delaysmajor- Significant delaysindefinite- Road closures with no estimated delayunknown- Unknown or no delay information
Delay Duration
Filter incidents by minimum delay:
// Show incidents with at least 5 minutes delayincidents.filter({ any: [{ delays: { mustHaveDelay: true, minDelayMinutes: 5 } }]});Road Category
Display incidents only on specific road types:
// Show incidents only on highwaysincidents.filter({ any: [{ roadCategories: { show: 'only', values: ['motorway', 'trunk'] } }]});
// Show incidents only on major local roads within tertiary categoryincidents.filter({ any: [{ roadCategories: { show: 'only', values: ['tertiary'] }, roadSubCategories: { show: 'only', values: ['major_local'] } }]});Available Road Categories:
motorway- Major highwaystrunk- Major roadsprimary- Primary roadssecondary- Secondary roadstertiary- Tertiary roadsstreet- Local streets
Available Road Subcategories:
tertiaryconnecting- Roads connecting different areasmajor_local- Major roads within local areas
streetlocal- Standard local streetsminor_local- Minor residential streets
Multiple Filters
Combine multiple filter criteria:
// Show major accidents OR road closuresincidents.filter({ any: [ { incidentCategories: { show: 'only', values: ['accident'] }, magnitudes: { show: 'only', values: ['major'] } }, ]});Separate Icon and Area Filters
Apply different filters to icons and incident areas:
// Show all incidents on highwaysconst incidentFilter = { any: [{ roadCategories: { show: 'only', values: ['motorway', 'trunk'] } }]};
// But only show icons for major incidentsconst iconFilter = { any: [{ magnitudes: { show: 'only', values: ['major'] } }]};
incidents.filter(incidentFilter, iconFilter);Reset Filters
Remove all filters and show all incidents:
incidents.filter(undefined);Events
Handle user interactions with traffic incidents:
// Click eventsincidents.events.on('click', (feature) => { ...});
// Hover eventsincidents.events.on('hover', (feature) => { ...});
// Long hover eventsincidents.events.on('long-hover', (feature) => { ...});
// Remove event listenersincidents.events.off('click', handler);API Reference
For complete documentation of all Traffic Incidents Module properties, methods, and types, see the TrafficIncidentsModule API Reference .
Related Guides and Examples
Traffic Overview
- Traffic Overview - Overview of all traffic visualization options including flow, incidents, and route-specific traffic
Related Traffic Modules
- Traffic Flow Module - Display real-time traffic speed conditions
- Routing Module - Display routes with traffic incidents along the path
Related Examples
- Traffic Incidents - Interactive traffic incidents visualization with filtering
- Traffic Config Playground - Explore traffic configuration options