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 |
— |
Type: Object Provider options. Options for provider layers are set via the options for the global collection of layers, Map.layers.
|
|
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. |
|
— |
Type: Object Provider state. |
|
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 |
Event manager. Inherited from IEventEmitter. |
||
Options manager. Inherited from ICustomizable. |
||
Provider state. Names of fields that are available via the data.Manager.get method:
|
Events
Name |
Description |
Change to the object options. Inherited from ICustomizable. |
Methods
Name |
Returns |
Description |
getMap() |
Map|null |
Returns reference to the map. Inherited from ITrafficProvider. |
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);