traffic.provider.Actual

Extends ITrafficProvider.

Provider of real-time traffic data. Accessible in the provider storage by the key 'traffic#actual'.

Constructor | Fields | Events | Methods

Constructor

traffic.provider.Actual([options[, state]])

Creates a provider of real-time traffic data.

Parameters:

Parameter Default value Description
options

Type: Object

Provider options. Options for provider layers are set via the options for the global collection of layers, Map.layers.
  • Options for the image layer Layer are defined with the 'trafficImage' prefix.
  • Options for the hotspot layer hotspot.Layer are defined with the 'trafficJam' prefix.
  • Options for the infopoint layer are defined with the 'trafficInfo' prefix. The infopoint layer is an instance of the hotspot.Layer class.
options.autoUpdate true

Type: Boolean

Flag that enables automatically updating traffic data. Automatic updates occur only when the "mousemove" event occurs every 4 minutes on the map. If this event does not occur, traffic stops being updated until there is a new event.

state

Type: Object

Provider state.

state.infoLayerShown false

Type: Boolean

Flag that enables displaying the traffic events layer.

Example:

// Creating a provider for current traffic with the traffic events layer enabled
// and putting it on the map.
var actualProvider = new ymaps.traffic.provider.Actual({}, {infoLayerShown: true});
actualProvider.setMap(myMap);

// Forbidding showing balloons for clicks on the infopoint layer.
myMap.layers.options.set({
    // The option name is formed by adding the 'trafficInfo' prefix
    // to the hotspot layer option 'openBalloonOnClick'.
    trafficInfoOpenBalloonOnClick: false
});

// ...
// Deleting the provider from the map.
actualProvider.setMap(null);

Fields

Name Type Description
events IEventManager

Event manager.

Inherited from IEventEmitter.

options IOptionManager

Options manager.

Inherited from ICustomizable.

state data.Manager
Provider state. Names of fields that are available via the data.Manager.get method:
  • isInited - Flag for whether the provider is ready to provide data.
  • infoLayerShown - Flag for whether the traffic events layer is shown.
  • timestamp - Current time in the UTC+0 time zone, in seconds.
  • localtime - Local time that the server is currently sending data for, in the format HH:MM.
  • level - Traffic level in points from 0 to 10.
  • isotime - String containing the current date in the format "YYYY-MM-DDThh:mm:ss±hhmm".

Events

Name Description
optionschange

Change to the object options.

Inherited from ICustomizable.

Methods

Name Returns Description
getMap()

Map|null

Returns reference to the map.

Inherited from ITrafficProvider.

setMap(Reference)
update()

Sends a request to update traffic.

Fields details

state

{data.Manager} state
Provider state. Names of fields that are available via the data.Manager.get method:
  • isInited - Flag for whether the provider is ready to provide data.
  • infoLayerShown - Flag for whether the traffic events layer is shown.
  • timestamp - Current time in the UTC+0 time zone, in seconds.
  • localtime - Local time that the server is currently sending data for, in the format HH:MM.
  • level - Traffic level in points from 0 to 10.
  • isotime - String containing the current date in the format "YYYY-MM-DDThh:mm:ss±hhmm".

Example:

var actualProvider = new ymaps.traffic.provider.Actual();
actualProvider.setMap(myMap);
actualProvider.state.events.add('change', function () {
    if (actualProvider.state.get('isInited')) {
        alert('The provider is ready to provide data.');
    }
});

Methods details

update

{} update()

Sends a request to update traffic.

Example:

var trafficControl = new ymaps.control.TrafficControl({shown: true});
map.controls.add(trafficControl);
function updateProvider () {
     trafficControl.getProvider('traffic#actual').update();
}
// Sending a request to update data every 4 minutes.
window.setInterval(updateProvider, 4 * 60 * 1000);