traffic.provider.Archive

Extends ITrafficProvider.

Provider for the traffic archive. This lets us show the normal state of traffic for a given region on a particular day of the week and at a particular time.

Constructor | Fields | Events | Methods

Constructor

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

Creates an instance of the traffic archive provider.

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.showCurrentTimeFirst

true

Type: Boolean

When archived data is first shown, set a time near the current time.

state

Type: Object

Provider state.

state.timestamp

Type: Number

The time that "normal" traffic is being shown for. This is the time from Monday at 00:00 to the desired time, in seconds. It must be a multiple of 60 * 15 = 900, since data on the server is available for times with a difference of 15 minutes. The time is set for the universal time zone (UTC+0).

Example:

// Creating a provider for "normal" traffic and giving it a timestamp of 17:47 on Wednesday
// in the universal time zone. Note that the local time depends on
// the location of the map center.
// For example, 17:47 in the universal time zone is 21:47 in Moscow.

// Calculating the value of the timestamp parameter for the desired time.
var timestamp = 2 * 24 * 60 * 60 + // twice every 24 hours - this is the time for Monday and Tuesday
        17 * 60 * 60 + // 17 hours have passed since 00:00 Wednesday
        45 * 60; // since the time must be in 15-minute increments, use 45 instead of 47.
var archiveProvider = new ymaps.traffic.provider.Archive({
    // Don't display a time near the current time on the first opening
    showCurrentTimeFirst: false
}, {
   // Setting the starting time independently.
   timestamp: timestamp
});
archiveProvider.setMap(map);

// Don't show popup hints for the traffic layer.
myMap.layers.options.set({
    // The option name is formed by adding the 'trafficJam' prefix
    // to the hotspot layer option 'openHintOnHover'.
    trafficJamOpenHintOnHover: false
});

// ...
// Removing the provider from the map.
archiveProvider.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.
  • timeZone - Time offset for the current time zone relative to UTC+0. Measured in seconds.
  • dst - Flag for switching to winter/summer time (daylight saving time). When dst='dst' it is summer time.
  • timestamp - Current time in the UTC+0 time zone, in seconds.
  • localtime - The local time that the server returns in the response.
  • level - Traffic level in points from 0 to 10.

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.

getTime()

Object|null

Returns the day of the week, hour, and minutes for the provider's status with consideration of the time zone and adjustments for daylight saving time. In other words, this is the time the user sees in the traffic control.

setMap(Reference)

setTime(time[, callback])

Allows to set the time for an archive provider in minutes, hours and days. Sets the local time only after the provider initializes the "timeZone" and "dst" fields.

  • timeZone - Field that displays which time zone the map center is currently located in. When the map center is moved from one time zone to another, the local time may change.
  • dst - Flag for switching to summer/winter time (daylight saving time). When dst='dst' it indicates summer time.
    The "timestamp" field serves as a permanent part of the time for providers of "normal" traffic, and reflects the current time in the zero time zone (UTC+0). When changing from one time zone to another, "timestamp" does not change. You can get the values of the "timestamp", "dst", and "timeZone" fields from the traffic.provider.Archive.state field.

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.
  • timeZone - Time offset for the current time zone relative to UTC+0. Measured in seconds.
  • dst - Flag for switching to winter/summer time (daylight saving time). When dst='dst' it is summer time.
  • timestamp - Current time in the UTC+0 time zone, in seconds.
  • localtime - The local time that the server returns in the response.
  • level - Traffic level in points from 0 to 10.

Example:

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

Methods details

getTime

{Object|null} getTime()

Returns the day of the week, hour, and minutes for the provider's status with consideration of the time zone and adjustments for daylight saving time. In other words, this is the time the user sees in the traffic control.

Returns object with fields

  • dayOfWeek - Abbreviations of days of the week. 'mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun'.
  • hours - Hours.
  • minutes - Minutes.
    If the map center is located at a point that we cannot determine the time zone for, the function returns null; if we don't know which time zone we are in, we can't find out the local time.

setTime

{} setTime(time[, callback])

Allows to set the time for an archive provider in minutes, hours and days. Sets the local time only after the provider initializes the "timeZone" and "dst" fields.

  • timeZone - Field that displays which time zone the map center is currently located in. When the map center is moved from one time zone to another, the local time may change.
  • dst - Flag for switching to summer/winter time (daylight saving time). When dst='dst' it indicates summer time.
    The "timestamp" field serves as a permanent part of the time for providers of "normal" traffic, and reflects the current time in the zero time zone (UTC+0). When changing from one time zone to another, "timestamp" does not change. You can get the values of the "timestamp", "dst", and "timeZone" fields from the traffic.provider.Archive.state field.

Parameters:

Parameter

Default value

Description

time*

Type: Object

Object with the set parameters.

time.dayOfWeek

Type: String

Abbreviated name of a day of the week. 'mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun'.

time.hours

Type: Number

Hour.

time.minutes

Type: Number

Minutes.

callback

Type: Function

A function that is called after the time was set. Accepts a hash with the set data as input.

* Mandatory parameter/option.

Example:

// Creating a control that immediately shows the
// provider of "normal" traffic on the map.
var trafficControl = new ymaps.control.TrafficControl({
    shown: true,
    providerKey: 'traffic#archive'
});
map.controls.add(trafficControl);
// The local time will be set as soon as the provider
// gets data on the current time zone.
trafficControl.getProvider('traffic#archive').setTime({
    dayOfWeek: 'fri',
    hours: 9,
    minutes: 15
}, function (time) {
    alert('Local time ' + time.hours + ':' + time.minutes + ' set!');
});