Displaying the Current Traffic Situation

This integration sample shows how to display the current traffic situation by using the Feature Layer themes PTV_SpeedPatterns and PTV_TrafficIncidents.


By considering the Feature Layer themes PTV_SpeedPatterns and PTV_TrafficIncidents it is possible to display the traffic situation for the current or any other time on the map. The traffic situation is displayed by differently colored road segments. A green segment means that it is possible to drive with normal speed (reduced traffic), while an orange colored segment can only be passed with reduced speed (more traffic). A red color signals heavy traffic and thus a strongly reduced speed.


Check if the following prerequisites are fulfilled before you start with the use case:

  • Installed and licensed PTV xMap service.
  • Installed map with the Feature Layer themes PTV_SpeedPatterns and PTV_TrafficIncidents.
  • Properly set up PTV Content Update Service to obtain the current traffic situation.


The Feature Layer PTV_SpeedPatterns defines average speeds on roads at different times of a day.
The Feature layer PTV_TrafficIncidents defines the speed on roads where some incidents are ongoing.
With the request option timeConsideration it is then possible to define a point in time for which the speed information should be displayed. For details see the technical concept about time consideration.

Programming Guide

The sample below displays a map with the Feature Layers PTV_SpeedPatterns and PTV_TrafficIncidents using the time consideration scenario SnapshotTimeConsideration. The implementation uses the L.tileLayer.xserver class, which simplifies the settings for time consideration and provides the tool tips handling for the textual feature information. This layer class is part of the leaflet-xserver.js library.

Besides the tile images, detailed information such as traffic messages can be requested in parallel. These messages may be available for multiple languages. To get the message in a specific language, please use the request option userLanguage. Depending on the requested language and those actually available in the Feature Layer data, the following behaviors could happen:
In this example, the Feature Layer contains messages in English (en) and German (de). The default language of the layer is English(en).

Requested language Response language
en en
en-US en-US if available, en otherwise
de de
fr en (default language)

Tile requests with an empty reference time may be cached by the browser so that the map image will not change even though the traffic situation changes. To make sure that this will not happen, set the reference time explicitly to the current time.

Related Topics

The following topics might be relevant for this use case.