---
metadata:
  - name: generator
    content: Diplodoc Platform v5.64.2
alternate:
  - https://yandex.com/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/collection.Item.md
  - https://yandex.com/dev/jsapi-v2-1/doc/ru/v2-1/ref/reference/collection.Item.md
  - href: https://yandex.com/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/collection.Item.md
    type: text/markdown
    title: Markdown version
  - href: https://yandex.com/dev/jsapi-v2-1/doc/en/llms.txt?revision=r21950234
    rel: describedby
---
> **Documentation Index:** Fetch the complete configuration index at https://yandex.com/dev/jsapi-v2-1/doc/en/llms.txt?revision=r21950234

# collection.Item

Extends [IChildOnMap](https://yandex.com/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IChildOnMap.md), [ICustomizable](https://yandex.com/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/ICustomizable.md), [IEventEmitter](https://yandex.com/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IEventEmitter.md), [IParentOnMap](https://yandex.com/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IParentOnMap.md).

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

[Constructor](#constructor-summary) | [Fields](#properties-summary) | [Events](#events-summary) | [Methods](#methods-summary)

## Constructor {#constructor-summary}

```javascript
collection.Item([options])
```

**Parameters:**

#|
|| **Parameter** | **Default value** | **Description**  ||
|| [`options`](#param-options) | — | Type: Object

Object options. ||
|#


**Example:**

```javascript
// 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 {#properties-summary}

#|
|| **Name** | **Type** | **Description** ||
|| [events](https://yandex.com/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IEventEmitter.md#events) | [IEventManager](https://yandex.com/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IEventManager.md)| Event manager.

Inherited from [IEventEmitter](https://yandex.com/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IEventEmitter.md#events). ||
|| [options](https://yandex.com/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/ICustomizable.md#options) | [IOptionManager](https://yandex.com/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IOptionManager.md)| Options manager.

Inherited from [ICustomizable](https://yandex.com/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/ICustomizable.md#options). ||
|#

## Events {#events-summary}

#|
|| **Name** | **Description** ||
|| [mapchange](https://yandex.com/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IParentOnMap.md#event-mapchange)| Map reference changed. Data fields: 
- oldMap - Old map.
- newMap - New map.

Inherited from [IParentOnMap](https://yandex.com/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IParentOnMap.md#event-mapchange). ||
|| [optionschange](https://yandex.com/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/ICustomizable.md#event-optionschange)| Change to the object options.

Inherited from [ICustomizable](https://yandex.com/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/ICustomizable.md#event-optionschange). ||
|| [parentchange](https://yandex.com/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IChild.md#event-parentchange)| The parent object reference changed.

Data fields:

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

Inherited from [IChild](https://yandex.com/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IChild.md#event-parentchange). ||
|#

## Methods {#methods-summary}

#|
|| **Name** | **Returns** | **Description** ||
|| [getMap](https://yandex.com/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/collection.Item.md#getMap)() | [Map](https://yandex.com/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/Map.md)
| Returns the map that the collection item belongs to. ||
|| [getParent](https://yandex.com/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/collection.Item.md#getParent)() | [IParentOnMap](https://yandex.com/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IParentOnMap.md)
| Returns parent object. ||
|| [onAddToMap](https://yandex.com/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/collection.Item.md#onAddToMap)([map](https://yandex.com/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/collection.Item.md#onAddToMap-param-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](https://yandex.com/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/collection.Item.md#onRemoveFromMap)([oldMap](https://yandex.com/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/collection.Item.md#onRemoveFromMap-param-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](https://yandex.com/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/collection.Item.md#setParent)([parent](https://yandex.com/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/collection.Item.md#setParent-param-parent)) | [collection.Item](https://yandex.com/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/collection.Item.md)
| Sets the parent for the selected item in a collection. ||
|#

## Methods details {#method_detail}

### getMap {#getMap}

```javascript
{Map} getMap()
```

**Returns** the map that the collection item belongs to.

### getParent {#getParent}

```javascript
{IParentOnMap} getParent()
```

**Returns** parent object.

### onAddToMap  {#onAddToMap}

```javascript
{} 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`](#onAddToMap-param-map)[*](*star) | — | Type: [Map](https://yandex.com/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/Map.md)

The map that the object has been added to. ||
|#

\* Mandatory parameter/option.

### onRemoveFromMap {#onRemoveFromMap}

```javascript
{} 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`](#onRemoveFromMap-param-oldMap)[*](*star) | — | Type: [Map](https://yandex.com/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/Map.md)

The map that the object has been deleted from. ||
|#

\* Mandatory parameter/option.

### setParent  {#setParent}

```javascript
{collection.Item} setParent(parent)
```

Sets the parent for the selected item in a collection.

**Returns** self-reference.

**Parameters:**

#|
|| **Parameter** | **Default value** | **Description**  ||
|| [`parent`](#setParent-param-parent)[*](*star) | — | Type: [IParentOnMap](https://yandex.com/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/IParentOnMap.md)

Parent object. ||
|#

\* Mandatory parameter/option.

[*star]: Mandatory parameter/option.