control.TypeSelector

Extends control.ListBox.

The "Map types" control. For this control, you can add list items that describe map types, as well as additional elements. The key of the control in the storage. control.storage — "typeSelector".

Constructor | Fields | Events | Methods

Constructor

control.TypeSelector([parameters])

Parameters:

Parameter

Default value

Description

parameters

Type: String[]|MapType[]|Object

Object with descriptions of control parameters. If an array is passed, it is interpreted as an array of map types.

parameters.mapTypes

Type: String[]|MapType[]

Array of constructors for map types or keys. If the parameter is omitted, the item is added to the standard set of map types. List of available map types:

  • 'yandex#map' - "Roadmap" map type.
  • 'yandex#satellite' - "Satellite" map type.
  • 'yandex#hybrid' - "Hybrid" map type.

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 list when the button loses focus. For example, when a user clicks on the document.

parameters.options.collapseTimeout

3000

Type: Number

Time delay, after which the open list closes automatically.

parameters.options.expandOnClick

true

Type: Boolean

Flag that allows automatically expanding/collapsing the list when clicked.

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

200

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

Constructor of the control layout which implements the ISelectableControlLayout and IGroupControlLayout interfaces or the layout key in the layout.storage. The layout constructor is passed an object containing the fields:

  • control - Reference to the control.
  • options - Control options manager control.ListBox.options.
  • data - Control data manager control.ListBox.data.
  • state - Control state manager control.ListBox.state.
    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.ListBox.state depending on the commands received.

parameters.options.maxWidth

[30, 65, 85]

Type: Number|Number[]

The maximum width of the listbox in different states. If a number is specified, it is assumed that the button has the same maximum dimensions in all states. If an array is specified, it will be interpreted as the maximum width of the button in different states, from the lesser to the greater.

parameters.options.panoramasItemMode

'ifMercator'

Type: String

Shows or hides the "Panoramas" element. Possible values:

  • 'on' - The "Panorama" element is always shown.
  • 'ifMercator' - the 'Panorama' element is only shown if the map projection is the Mercator projection.
  • 'off' - The "Panorama" element is never shown.
    The "Panoramas" element is available only when using the standard layout.

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

true

Type: Boolean

Indicates if the control is displayed.

parameters.state

Type: Object

State of the control.

parameters.state.expanded

false

Type: Boolean

Flags if the list is expanded.

Example:

map.controls.add(new ymaps.control.TypeSelector(['yandex#map', 'yandex#hybrid']));

Fields

Name

Type

Description

data

data.Manager

Control data.

events

IEventManager

Event manager.

Inherited from IEventEmitter.

options

IOptionManager

Options manager.

Inherited from IControl.

state

data.Manager

State of the drop-down list. Names of fields that are available via the data.Manager.get method:

  • expanded - Flag for whether the list is expanded.
  • size - The size that is currently set for the list.

Inherited from control.ListBox.

Events

Name

Description

add

A child object was added.

Inherited from ICollection.

click

Clicking the list title. Instance of the Event class.

Inherited from control.ListBox.

collapse

The list is closed. Instance of the Event class.

Inherited from control.ListBox.

expand

The list is open. Instance of the Event class.

Inherited from control.ListBox.

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.

press

The event indicating that the button has been pressed. Unlike the click event, it is generated only if the state isEnabled == true. Instance of the Event class.

Inherited from control.ListBox.

remove

A child object was deleted.

Inherited from ICollection.

Methods

Name

Returns

Description

add(object)

ICollection

Adds a child object to the collection.

Inherited from ICollection.

addMapType(mapType[, positionIndex])

control.TypeSelector

Adds a map type to the list.

collapse()

control.ListBox

Collapses the list.

Inherited from control.ListBox.

expand()

control.ListBox

Expands the list.

Inherited from control.ListBox.

getIterator()

IIterator

Returns iterator for the collection.

Inherited from ICollection.

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.

isExpanded()

Boolean

Returns a flag for whether the control is in the expanded state.

Inherited from control.ListBox.

remove(object)

ICollection

Removes a child object from the collection.

Inherited from ICollection.

removeAllMapTypes()

control.TypeSelector

Deletes all map types from the control.

removeMapType(mapType)

control.TypeSelector

Deletes the map type.

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.

Fields details

data

{data.Manager} data

Control data.

Methods details

addMapType

{control.TypeSelector} addMapType(mapType[, positionIndex])

Adds a map type to the list.

Returns self-reference.

Parameters:

Parameter

Default value

Description

mapType*

Type: String|MapType

Map type.

positionIndex

Type: Integer

Position in the list (if omitted, the new map type is added to the end of the list). The list of default positionIndex values for standard map types:

  • 'yandex#map' - 5;
  • 'yandex#satellite' - 10;
  • 'yandex#hybrid' - 15.

* Mandatory parameter/option.

Examples:

1.

var typeSelector = new ymaps.control.TypeSelector([]);
typeSelector.addMapType('yandex#map', 1);
typeSelector.addMapType('yandex#hybrid', 0);

2.

// If a standard set of map types is being used,
// and we want to add our own set from mapType.storage // and insert it between "satellite" and "map".
var typeSelector = myMap.controls.get('typeSelector');
typeSelector.addMapType('my#mapType', 6);

getMap

{Map} getMap()

Returns reference to the map.

removeAllMapTypes

{control.TypeSelector} removeAllMapTypes()

Deletes all map types from the control.

Returns self-reference.

removeMapType

{control.TypeSelector} removeMapType(mapType)

Deletes the map type.

Returns self-reference.

Parameters:

Parameter

Default value

Description

mapType*

Type: String|MapType

Map type.

* Mandatory parameter/option.