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

    Function trafficIncidentDetails

    • Fetches detailed information about traffic incidents.

      It queries incidents by a geographic bounding box, by a polygon, or by a list of incident IDs. Results are GeoJSON Features whose geometry is a Point (localised incidents) or a LineString (incidents spanning a stretch of road).

      Parameters

      Returns Promise<TrafficIncidentDetails>

      Promise resolving to a TrafficIncidentDetails object containing the matching incidents

      The query modes are:

      • Bounding box (bbox) returns all incidents within the given area, of at most 10,000 km².
      • Polygon (polygon) returns the incidents that intersect a polygon, such as a city boundary. The request covers the polygon's bounding box, and the response is trimmed to the polygon.
      • By IDs (ids) returns the specified incidents directly. GET is used automatically for up to 5 IDs, and POST for up to 100.

      Each incident provides:

      • Category (category): type of incident (accident, roadworks, jam, etc.)
      • Delay magnitude: severity of the delay (minor, moderate, major, …)
      • Geometry: exact location or extent of the incident on the road network
      • Time information: start/end times and whether the incident is present or future
      • Events: one or more detailed event descriptions
      // Query by bounding box (Amsterdam area)
      const result = await trafficIncidentDetails({
      bbox: [4.728, 52.278, 5.080, 52.479]
      });

      result.features.forEach(incident => {
      console.log(incident.properties.category); // 'accident' | 'jam' | …
      console.log(incident.properties.magnitudeOfDelay); // 'minor' | 'major' | …
      console.log(incident.geometry); // Point or LineString
      });
      // Query within a city boundary rather than its bounding box
      const place = await geocodeOne('Amsterdam');
      const result = await trafficIncidentDetails({
      polygon: await geometryData({ geometries: [place] })
      });
      // Query up to 5 specific incidents by ID (GET)
      const result = await trafficIncidentDetails({
      ids: ['incident-id-1', 'incident-id-2']
      });
      // Query many incident IDs — POST is used automatically when ids.length > 5
      const result = await trafficIncidentDetails({
      ids: largeIdArray
      });
      // Filter by category and include future incidents
      const result = await trafficIncidentDetails({
      bbox: [4.728, 52.278, 5.080, 52.479],
      categoryFilter: ['accident', 'road-closed'],
      timeValidityFilter: ['present', 'future']
      });