Sorry, you need to enable JavaScript to visit this website.

Traffic layers

Traffic layers

Give your users the ability to see real time traffic in your mobile apps.

With Traffic Flow tiles your users will have information about congestion, the speed of traffic on different road segments, and the difference between that speed and the free-flow speed on the same road segments. You can find more information and details about Traffic Flow tile parameters on Vector Traffic Flow tiles or Raster Traffic Flow tiles.

Traffic Flow tiles

Traffic Flow tiles are available in two formats: vector (.pbf) and raster (.png). Vector tiles provide a possibility for visual customization and a better visual experience by means of a style sheet. Also, the vector tiles contain certain traffic information (e.g., road type, traffic level, etc.). Check Traffic Flow tags in the Vector Flow Tiles documentation for details.

IMPORTANT: In May 2020, the methods used to switch between vector and raster tiles were deprecated and will be removed after one year. From that point, to display raster tiles it will be required to reload the style to one which contains raster layers. Before the deprecation period is over, a map is still going to be initialized with the style that contains raster and vector tiles. However, if your style is obtained from the Style Merger you need to set MapStyleSource to STYLE_MERGER in MapProperties described here. This approach will only load vector tiles.

Vector Traffic Flow tiles are used by default for traffic flow in the Maps SDK.

You can switch to Raster Traffic Flow tiles by reloading the style and then filtering layers using the following code:

_

List<Layer> layers = tomtomMap.getStyleSettings().findLayersById("tomtom-flow-raster-layer");
FuncUtils.forEach(layers, layer -> layer.setVisibility(visibility));
val layers = tomtomMap.styleSettings.findLayersById("tomtom-flow-raster-layer")
layers.forEach { layer ->
    layer.visibility = visibility
}

 

You can display Vector Traffic Flow tiles by using the following method:

_

tomtomMap.getTrafficSettings().turnOnTrafficFlowTiles();
tomtomMap.trafficSettings.turnOnTrafficFlowTiles()

 

When the Maps SDK is launched with a style containing raster sources for Traffic Flow, and appropriately set according to the style definition, you can then switch to Raster Traffic Flow tiles by calling:

_

tomtomMap.getTrafficSettings().turnOnRasterTrafficFlowTiles();
tomtomMap.trafficSettings.turnOnRasterTrafficFlowTiles()

 

You can display Vector Traffic Flow tiles by using the following method:

_

tomtomMap.getTrafficSettings().turnOnVectorTrafficFlowTiles();
tomtomMap.trafficSettings.turnOnRasterTrafficFlowTiles()

Vector Traffic Flow tiles listener

Additionally, you can get details about the specific traffic flow of the road fragment (e.g., current speed, travel times, etc.) from the Flow Segment Data service which is integrated in the Maps SDK. This service is designed to work alongside the Traffic Flow tiles to support clickable flow data visualizations. This is handled for you in the Maps SDK. Set the following listener:

_

tomtomMap.getTrafficSettings().setOnTrafficFlowClickListener(new DefaultOnTrafficFlowClickListener(tomtomMap));
tomtomMap.trafficSettings.setOnTrafficFlowClickListener(DefaultOnTrafficFlowClickListener(this))

 

Then you need to implement the following interface which informs you if any Traffic Flow segment was clicked:

/**
 * A callback executed when traffic flow on the map is clicked.
 */
public interface OnTrafficFlowClickListener {
    /**
     * A callback executed when traffic flow on the map is clicked.
     *
     * @param mapPoint A point on the screen resolved as a location.
     * @param trafficFlows  A list of traffic points displayed under the clicked place on the map.
     */
    boolean onTrafficFlowClick(MapPoint mapPoint, List<TrafficFlow> trafficFlows);
}

which informs the user what place on the map is clicked and what traffic flows are clicked.

By the default implementation, when you click on the specific Traffic Flow segment, a balloon with details is shown:

tomtomMap.getTrafficSettings().showTrafficFlowBalloon(pointOnScreen, new TrafficFlowMapBalloon(flows));

 

The default listener dismisses a traffic balloon when information about traffic is not available:

tomtomMap.getTrafficSettings().dismissTrafficBalloon();

 

To set a custom view for the traffic balloon, the TrafficFlowBalloonViewAdapter should be implemented and set by the TrafficSettings#setTrafficFlowBalloonViewAdapter method. A default implementation is set as follows:

_

tomtomMap.getTrafficSettings().setTrafficFlowBalloonViewAdapter(new TrafficFlowBalloonViewAdapter.Default());
tomtomMap.trafficSettings.setTrafficFlowBalloonViewAdapter(TrafficFlowBalloonViewAdapter.Default())

 

Vector Traffic Incidents Tiles listener

You can get details about the specific traffic incidents flow and traffic incidents POIs (e.g., current speed, travel times, etc.) from the Vector Flow Tiles service which is integrated in the Maps SDK. This service is designed to work alongside the traffic tiles to support clickable incident data visualizations. This is handled for you in the Maps SDK. Set the following listener:

_

tomtomMap.getTrafficSettings().setOnTrafficIncidentsClickListener(new DefaultOnTrafficIncidentClickListener(tomtomMap));
tomtomMap.trafficSettings.setOnTrafficIncidentsClickListener(DefaultOnTrafficIncidentClickListener(this))

 

Next you need to implement the following interface which informs you if any traffic incident (POI, cluster, flow) was clicked:

/**
 * A callback executed when traffic flow on the map is clicked.
 */
public interface OnTrafficFlowClickListener {
    /**
     * A callback executed when traffic flow on the map is clicked.
     *
     * @param mapPoint A point on the screen resolved as a location.
     * @param trafficFlows  A list of traffic points displayed under the clicked place on the map.
     */
    boolean onTrafficFlowClick(MapPoint mapPoint, List<TrafficFlow> trafficFlows);
}

and informs the user what place on the map is clicked and what traffic flows are clicked.

By the default implementation, when you click on the specific traffic incident, a balloon with details is shown for incident flows:

tomtomMap.getTrafficSettings().showTrafficIncidentBalloon(mapPoint, TrafficIncidentsMapBalloon.ofFlows(incidentsFlows));

and for incident POIs

tomtomMap.getTrafficSettings().showTrafficIncidentBalloon(mapPoint, TrafficIncidentsMapBalloon.ofPois(incidentsPois));

 

For the default implementation of incident, click listener and zoom the map when a traffic cluster is clicked:

tomtomMap.getUiSettings().setCameraPosition(
        CameraPosition.builder()
                .focusPosition(mapPoint.getPosition())
                .zoom(countNewZoom(incidentsCluster))
                .build()
);

 

To set a custom view for the traffic incident balloon, the TrafficIncidentsBalloonViewAdapter should be implemented and set by the TrafficSettings#setTrafficIncidentsBalloonViewAdapter method. A default implementation is set as follows:

_

tomtomMap.getTrafficSettings().setTrafficIncidentsBalloonViewAdapter(new TrafficIncidentsBalloonViewAdapter.Default());
tomtomMap.trafficSettings.setTrafficIncidentsBalloonViewAdapter(TrafficIncidentsBalloonViewAdapter.Default())

 

Traffic type and styles

Methods in this section related to adjusting Traffic Flow styles can only be used when the Maps SDK is not launched with merged style mode.

Traffic tile styles are represented in the SDK as Java data classes. Traffic flow tile style types are represented in the SDK as data classes.

The available vector traffic flow styles listed below can be set by the following method:

_

tomtomMap.getTrafficSettings().turnOnVectorTrafficFlowTiles(new TrafficFlowType.RelativeTrafficFlowStyle()); //default
tomtomMap.getTrafficSettings().turnOnVectorTrafficFlowTiles(new TrafficFlowType.AbsoluteTrafficFlowStyle());
tomtomMap.getTrafficSettings().turnOnVectorTrafficFlowTiles(new TrafficFlowType.RelativeDelayTrafficFlowStyle());
tomtomMap.trafficSettings.turnOnVectorTrafficFlowTiles(TrafficFlowType.RelativeTrafficFlowStyle()) //default
tomtomMap.trafficSettings.turnOnVectorTrafficFlowTiles(TrafficFlowType.AbsoluteTrafficFlowStyle())
tomtomMap.trafficSettings.turnOnVectorTrafficFlowTiles(TrafficFlowType.RelativeDelayTrafficFlowStyle())

 

The available raster traffic flow styles listed below can be set by the following method:

_

tomtomMap.getTrafficSettings().turnOnRasterTrafficFlowTiles(new TrafficFlowType.RelativeTrafficFlowStyle()); //default
tomtomMap.getTrafficSettings().turnOnRasterTrafficFlowTiles(new TrafficFlowType.AbsoluteTrafficFlowStyle());
tomtomMap.getTrafficSettings().turnOnRasterTrafficFlowTiles(new TrafficFlowType.RelativeDelayTrafficFlowStyle());
//default
tomtomMap.trafficSettings.turnOnRasterTrafficFlowTiles(TrafficFlowType.RelativeTrafficFlowStyle())
tomtomMap.trafficSettings.turnOnRasterTrafficFlowTiles(TrafficFlowType.AbsoluteTrafficFlowStyle())
tomtomMap.trafficSettings.turnOnRasterTrafficFlowTiles(TrafficFlowType.RelativeDelayTrafficFlowStyle())
tomtomMap.trafficSettings.turnOnRasterTrafficFlowTiles(TrafficFlowType.ReducedSensitivityTrafficFlowStyle())

 

Sample use case: You want to visualize traffic information in your app so your users can adjust their commute based on traffic information.

Use the following code snippets in your app to enable and visualize the vector traffic flow layer on the map:

_

tomtomMap.getTrafficSettings().turnOnTrafficFlowTiles();
tomtomMap.trafficSettings.turnOnTrafficFlowTiles()

 

You can turn off traffic flow by using the following method:

_

tomtomMap.getTrafficSettings().turnOffTraffic();
tomtomMap.getTrafficSettings().turnOffTrafficFlowTiles();
tomtomMap.trafficSettings.turnOffTraffic()

 

Information about set style:

_

VectorTrafficFlowType style = tomtomMap.getTrafficSettings().getTrafficVectorFlowStyle();
val style = tomtomMap.trafficSettings.trafficVectorFlowStyle

 

Traffic incidents

IMPORTANT: In May 2020, the methods used to switch between vector and raster tiles were deprecated and will be removed after one year. From that point, to display raster tiles it will be required to reload the style to one which contains raster layers. Before the deprecation period is over, a map is still going to be initialized with the style that contains raster and vector tiles. However, if your style is obtained from the Style Merger you need to set MapStyleSource to STYLE_MERGER in MapProperties described here.

In Merged Styles mode you can switch to Raster Traffic Incidents by reloading the style and then filtering layers using the following code:

  • Raster incident tiles:

_

List<Layer> layers = tomtomMap.getStyleSettings().findLayersById("tomtom-incidents-layer");
FuncUtils.forEach(layers, layer -> layer.setVisibility(visibility));
val layers = tomtomMap.styleSettings.findLayersById("tomtom-incidents-layer")
layers.forEach { layer ->
    layer.visibility = visibility
}

 

  • Vector incident tiles and POIs:

_

tomtomMap.getTrafficSettings().turnOnTrafficIncidents();
tomtomMap.trafficSettings.turnOnTrafficIncidents()

 

You can turn off traffic incidents by using the following method:

  • Vector incidents

_

tomtomMap.getTrafficSettings().turnOffTrafficIncidents();
tomtomMap.trafficSettings.turnOffTrafficIncidents()

 

  • Raster incidents, where Visibility is equal to Visibility.None

_

List<Layer> layers = tomtomMap.getStyleSettings().findLayersById("tomtom-incidents-layer");
FuncUtils.forEach(layers, layer -> layer.setVisibility(visibility));
val layers = tomtomMap.styleSettings.findLayersById("tomtom-incidents-layer")
layers.forEach { layer ->
    layer.visibility = visibility
}

 

When the Maps SDK is launched with a style containing raster sources for Traffic Incident, and appropriately set according to the style definition, then you can switch to Raster Traffic Incident tiles by calling:

To enable Traffic Incident tiles:

  • Vector incident tiles and POIs:

_

tomtomMap.getTrafficSettings().turnOnVectorTrafficIncidents();
tomtomMap.trafficSettings.turnOnVectorTrafficIncidents()

 

  • Raster incident tiles:

_

tomtomMap.getTrafficSettings().turnOnRasterTrafficIncidents();
tomtomMap.trafficSettings.turnOnRasterTrafficIncidents()

 

You can turn off traffic incidents by using the following method:

_

tomtomMap.getTrafficSettings().turnOffTrafficIncidents();
tomtomMap.trafficSettings.turnOffTrafficIncidents()

 

image

Traffic vector flow layer shown on a vector map.

image

Traffic raster flow shown on a raster map.

image

Traffic vector incidents layer with the S1 file style.

image

Traffic raster incidents layer in the sample app.

image

Traffic vector incidents and raster flow layer on a raster map.

image

Traffic raster incidents and raster flow layer on a raster map.

image

No vector traffic in the sample app.

image

No raster traffic in the sample app.