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:

Parameter Default value Description
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.
var CustomControl = function (options) {
    CustomControl.superclass.constructor.call(this, options);
};
// And inheriting from collection.Item.
ymaps.util.defineClass(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) {
        // You can create a DOM representation for the control here
        // and add it as a child element in parentElementContaner.
        // ...
    }
});

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

Fields

Name Type Description
events IEventManager

Event manager.

Inherited from IEventEmitter.

options IOptionManager

Options manager.

Inherited from ICustomizable.

Events

Name Description
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

Name Returns Description
getMap()

Map

Returns the map that the collection item belongs to.

getParent()

IParentOnMap

Returns 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 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:

Parameter Default value Description
map *

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:

Parameter Default value Description
oldMap *

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 self-reference.

Parameters:

Parameter Default value Description
parent *

Type: IParentOnMap

Parent object.

* Mandatory parameter/option.