control.TrafficControl

Extends IControl, ICustomizable.

The traffic control panel on the map.

Constructor | Fields | Events | Methods

Constructor

control.TrafficControl([parameters])

Parameters:

Parameter

Default value

Description

parameters

Type: Object

Control parameters.

parameters.options

Type: Object

Control options.

parameters.options.adjustMapMargin

false

Type: Boolean

Whether the control registers its size in the map margins manager map.margin.Manager.

parameters.options.collapseOnBlur

true

Type: Boolean

This flag enables to collapse the panel when the control loses focus. For example, when a user clicks on the document.

parameters.options.float

"right"

Type: String

The side to which you want to align the control. Can take three values: "left", "right" or "none". If set to "left" or "right", the controls are arranged one by one, starting from the left or right edge of the map, respectively. If set to "none", the controls are positioned according to the values of the left, right, bottom and top options, relative to the boundaries of the map. See also the description of the position option.

parameters.options.floatIndex

100

Type: Number

The priority of the control positioning. The element with highest priority is positioned closer to the map boundary that is specified in the float property. Does not work with float = "none".

parameters.options.layout

Type: Function|String

Control layout. The layout constructor is passed an object containing the fields:

  • control - Reference to the control.
  • options - Control options manager for the control.TrafficControl.options control.
  • data - Control data manager for the control.TrafficControl.data control.
  • state - Control state manager for the control.TrafficControl.state control.
    The layout's outward appearance changes based on the control's data, state and options. The control, in turn, reacts to layout interface events and changes the values of fields for control.TrafficControl.state depending on the commands received. (Type: constructor for an object with the ITrafficControlLayout interface).

parameters.options.maxWidth

[26, 195, 195]

Type: Number|Number[]

The maximum width of the button in different states. If a number is specified, it is assumed that the control has the same maximum dimensions in all states. If an array is specified, it will be interpreted as the maximum width in different states from the lesser to the greater. The number of states is set in the instance of the class control.Manager, which is usually a field of Map.controls, via the "states" option. By default, the controls have three states ['small', 'medium', 'large'].

parameters.options.position

Type: Object

Object describing the position of a control. If the position option is set, the float option value is automatically treated as "none".

parameters.options.position.bottom

'auto'

Type: Number|String

Position relative to the bottom edge of the map.

parameters.options.position.left

'auto'

Type: Number|String

Position relative to the left edge of the map.

parameters.options.position.right

'auto'

Type: Number|String

Position relative to the right edge of the map.

parameters.options.position.top

'auto'

Type: Number|String

Position relative to the top edge of the map.

parameters.options.size

'auto'

Type: String

Defines the appearance of the standard traffic control layout. Takes the following values:

  • 'auto' - The layout is changed automatically depending on the dimensions of the map and the number of added controls.
  • 'small' - The button layout displays the traffic light icon, regardless of the map size.
  • 'large' - The button layout always displays both the traffic light icon and text, regardless of the map size.

parameters.options.visible

true

Type: Boolean

Indicates if the control is displayed.

parameters.state

Type: Object

State of the control.

parameters.state.providerKey

'traffic#actual'

Type: String

Key for the provider of traffic info shown on the map.

  • 'traffic#actual' - Traffic "right now".
  • 'traffic#archive' - Traffic "normally".

parameters.state.trafficShown

false

Type: Boolean

Whether traffic data is shown on the map.

Example:

// Adding the traffic control to the map
// with "current" traffic enabled.
var trafficControl = new ymaps.control.TrafficControl({state: {trafficShown: true}});
map.controls.add(trafficControl, {top: 10, left: 10});

Fields

Name

Type

Description

data

data.Manager

Panel data.

events

IEventManager

Event manager.

Inherited from IEventEmitter.

options

IOptionManager

Options manager.

Inherited from IControl.

state

data.Manager

State of the panel. Names of fields that are available via the data.Manager.get method:

  • trafficShown - Flag for whether the traffic provider is shown on the map.
  • providerKey - Key of the provider that the panel shows. Accepts the values 'traffic#actual' and 'traffic#archive'.
  • expanded - Flag for whether the panel is expanded.

Events

Name

Description

collapse

The traffic panel is collapsed. Instance of the Event class.

expand

The traffic panel is expanded. Instance of the Event class.

hidetraffic

Traffic is hidden. Instance of the Event class.

optionschange

Change to the object options.

Inherited from ICustomizable.

parentchange

The parent object reference changed.

Data fields:

  • oldParent - Old parent.
  • newParent - New parent.

Inherited from IChild.

providerkeychange

The provider key changed. Instance of the Event class. Names of fields that are available via the Event.get method:

  • newProviderKey - New value for the provider key.
  • oldProviderKey - Old key value.

showtraffic

Traffic is shown. Instance of the Event class.

Methods

Name

Returns

Description

collapse()

Collapse the traffic panel.

expand()

Expand the traffic panel.

getMap()

Map

Returns reference to the map.

getParent()

IControlParent|null

Returns link to the parent object, or null if the parent element was not set.

Inherited from IControl.

getProvider([key])

ITrafficProvider

Returns instance of the traffic provider.

hideTraffic()

Hide the traffic provider from the map.

isExpanded()

Boolean

Returns flag for whether the panel is expanded.

isTrafficShown()

Boolean

Returns the flag for whether the panel is shown.

setParent(parent)

IChildOnMap

Sets the parent object. If the null value is passed, the manager element will only be deleted from the current parent object.

Inherited from IControl.

showTraffic()

Show the traffic provider on the map.

Fields details

data

{data.Manager} data

Panel data.

state

{data.Manager} state

State of the panel. Names of fields that are available via the data.Manager.get method:

  • trafficShown - Flag for whether the traffic provider is shown on the map.
  • providerKey - Key of the provider that the panel shows. Accepts the values 'traffic#actual' and 'traffic#archive'.
  • expanded - Flag for whether the panel is expanded.

Events details

collapse

The traffic panel is collapsed. Instance of the Event class.

expand

The traffic panel is expanded. Instance of the Event class.

hidetraffic

Traffic is hidden. Instance of the Event class.

providerkeychange

The provider key changed. Instance of the Event class. Names of fields that are available via the Event.get method:

  • newProviderKey - New value for the provider key.
  • oldProviderKey - Old key value.

showtraffic

Traffic is shown. Instance of the Event class.

Methods details

collapse

{} collapse()

Collapse the traffic panel.

expand

{} expand()

Expand the traffic panel.

getMap

{Map} getMap()

Returns reference to the map.

getProvider

{ITrafficProvider} getProvider([key])

Returns instance of the traffic provider.

Parameters:

Parameter

Default value

Description

key

Type: String

Key of the provider of traffic information. List of available keys:

  • 'traffic#actual' - Provider for traffic "right now".
  • 'traffic#archive' - Provider for "normal" traffic.
    If the parameter is omitted, the current provider is returned.

Example:

// Adding the traffic control to the map.
map.controls.add('trafficControl');
// When opened, the provider for traffic "now" will show the layer of traffic events.
map.controls.get('trafficControl').getProvider('traffic#actual').state.set('infoLayerShown', true);

hidetraffic

{} hideTraffic()

Hide the traffic provider from the map.

isExpanded

{Boolean} isExpanded()

Returns flag for whether the panel is expanded.

isTrafficShown

{Boolean} isTrafficShown()

Returns the flag for whether the panel is shown.

showtraffic

{} showTraffic()

Show the traffic provider on the map.