This is the documentation of version 0.64.0. Go to the latest version, 1.0.0-rc.5.

Traffic

@tomtom-org/maps-sdk/core exports the traffic types the services, the map modules and routing share, so an incident reads the same whichever API it came from.

Where traffic types are used

Context Type Description
Incident Details service TrafficIncident / TrafficIncidentDetails The parsed incidents of a trafficIncidentDetails call
Traffic Incidents map module TrafficIncidentsModuleFeature (map) A live incident tile feature, over TrafficIncidentBaseProperties
Route sections TrafficSectionProps A stretch of route affected by a traffic incident
Traffic Area Analytics service TrafficAreaAnalytics, AreaAnalyticsMetricKey A region's historical traffic report, and its metric names (areaAnalyticsMetricKeys)

Shared types

TrafficIncidentCategory

What an incident is, on the Incident Details service, the incident tiles and route sections alike:

import type { TrafficIncidentCategory } from '@tomtom-org/maps-sdk/core';

// 'accident' | 'animals-on-road' | 'broken-down-vehicle' | 'danger' |
// 'flooding' | 'fog' | 'frost' | 'jam' | 'lane-closed' | 'narrow-lanes' |
// 'other' | 'rain' | 'road-closed' | 'roadworks' | 'wind'
const category: TrafficIncidentCategory = incident.properties.category;
import { fullTrafficIncidentCategories } from '@tomtom-org/maps-sdk/core';

// ['accident', 'broken-down-vehicle', 'danger', 'flooding', ..., 'animals-on-road', 'narrow-lanes']
console.log(fullTrafficIncidentCategories);

DelayMagnitude

How severe a delay is: TrafficIncidentProperties.magnitudeOfDelay, TrafficSectionProps.magnitudeOfDelay, and the values of the incidents module's magnitudes filter:

import type { DelayMagnitude } from '@tomtom-org/maps-sdk/core';

// 'unknown' | 'minor' | 'moderate' | 'major' | 'indefinite'
const severity: DelayMagnitude = incident.properties.magnitudeOfDelay;
Value Meaning
unknown Severity cannot be determined
minor Small delay (a few minutes)
moderate Noticeable delay (several minutes)
major Significant delay (10+ minutes)
indefinite Unknown or extremely long delay (e.g. road closure)

indexedMagnitudes lists every magnitude in the order above, which is the order of the Traffic API's numeric magnitudeOfDelay codes: index 2 is moderate. The SDK's results already carry the names; the list builds a magnitude filter or tells when all of them are picked:

import { indexedMagnitudes } from '@tomtom-org/maps-sdk/core';

const allSelected = selectedMagnitudes.length === indexedMagnitudes.length;

TrafficIncidentTimeValidity

Whether an incident is active now or planned, on the Incident Details service and the incident tiles:

import type { TrafficIncidentTimeValidity } from '@tomtom-org/maps-sdk/core';

// 'present' | 'future'
const validity: TrafficIncidentTimeValidity = incident.properties.timeValidity;

Incident types

TrafficIncidentBaseProperties

The nine properties the Incident Details response and the incident tile features share:

import type { TrafficIncidentBaseProperties } from '@tomtom-org/maps-sdk/core';

type TrafficIncidentBaseProperties = {
    id: string;
    category: TrafficIncidentCategory;
    magnitudeOfDelay: DelayMagnitude;
    delayInSeconds?: number;
    startTime?: Date;
    endTime?: Date;
    probabilityOfOccurrence?: TrafficIncidentProbability; // 'certain' | 'probable' | 'risk_of' | 'improbable'
    numberOfReports?: number;
    lastReportTime?: Date;
};

TrafficIncidentProperties

TrafficIncidentBaseProperties plus what only the Incident Details response carries:

import type { TrafficIncidentProperties } from '@tomtom-org/maps-sdk/core';
Field Type Description
events TrafficIncidentEvent[] One or more event descriptions, each with its description, code and category
from string? Start of the affected road stretch
to string? End of the affected road stretch
lengthInMeters number? Length of the affected road section
roadNumbers string[]? Road numbers (e.g. ['A10'])
timeValidity TrafficIncidentTimeValidity Always present in the service response

TrafficIncident and TrafficIncidentDetails

import type { TrafficIncident, TrafficIncidentDetails } from '@tomtom-org/maps-sdk/core';

// TrafficIncident — a GeoJSON Feature<Point | LineString, TrafficIncidentProperties>
// TrafficIncidentDetails — a GeoJSON FeatureCollection of them, what trafficIncidentDetails returns

Routing traffic types

TrafficSectionProps

A route's traffic sections share TrafficIncidentCategory and DelayMagnitude with the incident types above:

import type { TrafficSectionProps } from '@tomtom-org/maps-sdk/core';

const trafficSections: TrafficSectionProps[] = route.properties.sections.traffic ?? [];

for (const section of trafficSections) {
    console.log(section.categories);          // e.g. ['jam']
    console.log(section.magnitudeOfDelay);    // e.g. 'moderate'
    console.log(section.delayInSeconds);      // e.g. 420
    console.log(section.effectiveSpeedInKmh); // e.g. 18
}

Related