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 |
— |
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 |
Event manager. Inherited from IEventEmitter. |
||
Options manager. Inherited from ICustomizable. |
Events
Name |
Description |
Map reference changed. Data fields:
Inherited from IParentOnMap. |
|
Change to the object options. Inherited from ICustomizable. |
|
The parent object reference changed. Data fields:
Inherited from IChild. |
Methods
Name |
Returns |
Description |
getMap() |
Returns the map that the collection item belongs to. |
|
Returns parent object. |
||
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. |
||
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. |
||
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 |
|
— |
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 |
— |
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 |
— |
Type: IParentOnMap Parent object. |
* Mandatory parameter/option.
Mandatory parameter/option.