Documentation
Reference
2.1.38 (current version)
collection
interactivityModel
Interfaces

collection.Item

Extends IChildOnMap, ICustomizable, IEventEmitter, IParentOnMap.

Base class for an item in a collection of map objects.

Constructor | Fields | Events | Methods

Constructor

collection.Item([options])

Parameters:

ParameterDefault valueDescription
options

Type: Object

Object options.

Example:

// Example of implementing a custom control based on inheritance from collection.Item.
// The control displays the name of the object that is located in the center of the map.
var map = new ymaps.Map('map', {
        center: [55.819543, 37.611619],
        zoom: 6
        }),
// Creating a custom class.
    CustomControl = function (options) {
        CustomControl.superclass.constructor.call(this, options);
    };
// And inheriting it from collection.Item.
ymaps.util.augment(CustomControl, ymaps.collection.Item, {
    onAddToMap: function (map) {
        CustomControl.superclass.onAddToMap.call(this, map);
        // Creating an HTML element with text.
        this.getParent().getChildElement(this).then(this._onChildElementGet, this);
    },

    onRemoveFromMap: function (oldMap) {
        CustomControl.superclass.onRemoveFromMap.call(this, oldMap);
    },

    _onChildElementGet: function(parentElementContainer) {
        // Creating the DOM representation for the control
        // and adding it to parentElementContaner as a child element.
        ...
    }
});

var customControl = new CustomControl();
map.controls.add(customControl, {top: 10, left: 10});

Fields

NameTypeDescription
eventsIEventManager

Event manager.

Inherited from IEventEmitter.

optionsIOptionManager

Options manager.

Inherited from ICustomizable.

Events

NameDescription
mapchange

Map reference changed. Data fields:

  • oldMap - Old map.
  • newMap - New map.

Inherited from IParentOnMap.

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.

Methods

NameReturnsDescription
getMap()Map

Returns the map that the collection item belongs to.

getParent()IParentOnMap

Returns the parent object.

onAddToMap(map)

Function that is called when adding an element to the map. To perform additional actions when adding the object to the map, redefine this function.

onRemoveFromMap(oldMap)

Function that is called when deleting an element from the map. To perform additional actions when deleting the object from the map, redefine this function.

setParent(parent)collection.Item

Sets the parent for the selected item in a collection.

Methods details

getMap

{Map} getMap()

Returns the map that the collection item belongs to.

getParent

{IParentOnMap} getParent()

Returns the parent object.

onAddToMap

onAddToMap(map)

Function that is called when adding an element to the map. To perform additional actions when adding the object to the map, redefine this function.

Parameters:

ParameterDefault valueDescription
map*
[no-highlight[

* Mandatory parameter/option.

]no-highlight]

Type: Map

The map that the object has been added to.

* Mandatory parameter/option.

onRemoveFromMap

onRemoveFromMap(oldMap)

Function that is called when deleting an element from the map. To perform additional actions when deleting the object from the map, redefine this function.

Parameters:

ParameterDefault valueDescription
oldMap*
[no-highlight[

* Mandatory parameter/option.

]no-highlight]

Type: Map

The map that the object has been deleted from.

* Mandatory parameter/option.

setParent

{collection.Item} setParent(parent)

Sets the parent for the selected item in a collection.

Returns a self-reference.

Parameters:

ParameterDefault valueDescription
parent*
[no-highlight[

* Mandatory parameter/option.

]no-highlight]

Type: IParentOnMap

Parent object.

* Mandatory parameter/option.