Documentation
Reference
2.1.53 (current version)
collection
interactivityModel
Interfaces

objectManager.ObjectCollection

Extends ICollection, ICustomizable.

Collection of objects added to the layer.

Constructor | Fields | Events | Methods

Constructor

objectManager.ObjectCollection()

Fields

NameTypeDescription
balloonobjectManager.Balloon

Object balloon in the manager.

eventsIEventManager

Event manager.

Inherited from IEventEmitter.

hintobjectManager.Hint

Object hint in the ObjectManager.

optionsoption.Manager

Options manager. Names of fields that are available via the option.Manager#get method:

  • hasBalloon - Indicates whether the collection has the .balloon field. If a balloon doesn't need to be opened when clicking the object, we recommend setting this option to the "false" value to avoid unnecessary initializations.
  • hasHint - Indicates whether the collection has the .hint field. If a popup hint doesn't need to be displayed when the object is pointed at, we recommend setting this option to the "false" value to avoid unnecessary initializations.
  • hideIconOnBalloonOpen - Hide the icon when opening the balloon. Default value: true.
  • openBalloonOnClick - Show the balloon when clicking the object. Default value: true.

overlaysobjectManager.OverlayCollection

Collection of overlays of singular objects. All events, with the exception of "add" and "remove" events, propagate from the collection of overlays to the collection of objects.

Events

NameDescription
add

Adds an object to the collection. Instance of the Event class. Names of fields that are available via the Event#get method:

  • objectId - ID of the added object.
  • child - The added object.

objectoptionschange

Modification of object options via the objectManager.ObjectCollection#setObjectOptions method. Instance of the Event class. Names of fields that are available via the Event#get method:

  • objectId - ID of the object that had options modified.

optionschange

Change to the object options.

Inherited from ICustomizable.

remove

Removes an object from the collection. Instance of the Event class. Names of fields that are available via the Event#get method:

  • objectId - ID of the deleted object.
  • child - The deleted object.

Methods

NameReturnsDescription
add(data)

objectManager.ObjectCollection

This method completely duplicates the logic of ObjectManager#add.

each(callback, context)

A method that calls the passed handler function for all the items in the collection.

getAll()

Object[]

Returns array of objects contained in the collection.

getById(id)

Object|null

Returns the object, or null if an object with the passed ID does not exist.

getIterator()

IIterator

Returns iterator for the collection.

Inherited from ICollection.

getLength()

Number

Returns the number of objects in the collection.

getObjectManager()

ObjectManager

Returns the parent layer of objects in the collection.

remove(data)

objectManager.ObjectCollection

This method completely duplicates the logic of ObjectManager#remove.

removeAll()

objectManager.ObjectCollection

Deletes all the items from a collection.

setObjectOptions(objectId, options)

objectManager.ObjectCollection

A method that allows to dynamically update object options. This method should be used when you want new options to be immediately applied to the object representation on the map.

Fields details

balloon

Object balloon in the manager.

hint

Object hint in the ObjectManager.

options

{option.Manager} options

Options manager. Names of fields that are available via the option.Manager#get method:

  • hasBalloon - Indicates whether the collection has the .balloon field. If a balloon doesn't need to be opened when clicking the object, we recommend setting this option to the "false" value to avoid unnecessary initializations.
  • hasHint - Indicates whether the collection has the .hint field. If a popup hint doesn't need to be displayed when the object is pointed at, we recommend setting this option to the "false" value to avoid unnecessary initializations.
  • hideIconOnBalloonOpen - Hide the icon when opening the balloon. Default value: true.
  • openBalloonOnClick - Show the balloon when clicking the object. Default value: true.

Example:

// Creating styles for individual objects within the collection.
objectManager.objects.options.set({
    preset: 'islands#redIcon',
    hasBalloon: false,
    zIndex: 500
});

overlays

Collection of overlays of singular objects. All events, with the exception of "add" and "remove" events, propagate from the collection of overlays to the collection of objects.

Example:

objectManager.objects.overlays.events.add('add', function (e) {
    alert('The object ' + e.get('objectId') + ' is shown on the map.');
});

Events details

add

Adds an object to the collection. Instance of the Event class. Names of fields that are available via the Event#get method:

  • objectId - ID of the added object.
  • child - The added object.

objectoptionschange

Modification of object options via the objectManager.ObjectCollection#setObjectOptions method. Instance of the Event class. Names of fields that are available via the Event#get method:

  • objectId - ID of the object that had options modified.

remove

Removes an object from the collection. Instance of the Event class. Names of fields that are available via the Event#get method:

  • objectId - ID of the deleted object.
  • child - The deleted object.

Methods details

add

This method completely duplicates the logic of ObjectManager#add.

Returns self-reference.

Parameters:

ParameterDefault valueDescription
data*
[no-highlight[

* Mandatory parameter/option.

]no-highlight]

Type: Object[][]|Object[]|String

Objects to add to the layer.

* Mandatory parameter/option.

Example:

objectManager.objects.add({
    type: 'Feature',
    geometry: {
        type: 'Point',
        coordinates: [55.33, 36.64]
    }
});

each

{} each(callback, context)

A method that calls the passed handler function for all the items in the collection.

Parameters:

ParameterDefault valueDescription
callback*
[no-highlight[

* Mandatory parameter/option.

]no-highlight]

Type: Function

Handler function that the collection objects are passed to.

context*
[no-highlight[

* Mandatory parameter/option.

]no-highlight]

Type: Object

Context for the handler function.

* Mandatory parameter/option.

Example:

var singleCounter = 0,
    clusterCounter = 0;
objectManager.objects.each(function (object) {
    var objectState = objectManager.getObjectState(object.id);
    if (objectState.isClustered) {
        clusterCounter++;
    } else {
        if (objectState.isShown) {
            singleCounter++;
        }
    }
});
alert('Number of single placemarks shown: ' + singleCounter);
alert('Number of placemarks shown in clusters: ' + clusterCounter);

getAll

{Object[]} getAll()

Returns array of objects contained in the collection.

getById

{Object|null} getById(id)

Returns the object, or null if an object with the passed ID does not exist.

Parameters:

ParameterDefault valueDescription
id*
[no-highlight[

* Mandatory parameter/option.

]no-highlight]

Type: Number

Object ID.

* Mandatory parameter/option.

Example:

objectManager.objects.add('click', function (e) {
    var objectId = e.get('objectId'),
        object = objectManager.objects.getById(objectId);
});

getLength

{Number} getLength()

Returns the number of objects in the collection.

Example:

alert('Number of objects in the layer: ' + objectManager.objects.getLength());

getObjectManager

{ObjectManager} getObjectManager()

Returns the parent layer of objects in the collection.

remove

This method completely duplicates the logic of ObjectManager#remove.

Returns self-reference.

Parameters:

ParameterDefault valueDescription
data*
[no-highlight[

* Mandatory parameter/option.

]no-highlight]

Type: Object[][]|Object[]|String

The objects to delete.

* Mandatory parameter/option.

Example:

// Removing the objects with the IDs 34 and 25.
objectManager.objects.remove([34, 25]);

removeAll

Deletes all the items from a collection.

Returns self-reference.

Example:

objectManager.objects.removeAll();

setObjectOptions

A method that allows to dynamically update object options. This method should be used when you want new options to be immediately applied to the object representation on the map.

Returns self-reference.

Parameters:

ParameterDefault valueDescription
objectId*
[no-highlight[

* Mandatory parameter/option.

]no-highlight]

Type: Object

ID of the object to set options for.

options*
[no-highlight[

* Mandatory parameter/option.

]no-highlight]

Type: Object

New object options.

* Mandatory parameter/option.

Example:

// Changing the icon color when moused over.
objectManager.objects.events.add('mouseenter', function (e) {
    var objectId = e.get('objectId'),
        overlay = objectManager.objects.overlays.getById(objectId);
    setRedColor(objectId);
    overlay.events.add('mapchange', setGreenColor);
});

objectManager.objects.events.add('mouseleave', function (e) {
    var objectId = e.get('objectId'),
        overlay = objectManager.objects.overlays.getById(objectId);
    setGreenColor(objectId);
    overlay.events.remove('mapchange', setGreenColor);
});

function setGreenColor (objectId) {
    objectManager.objects.setObjectOptions(objectId, {
        preset: 'islands#greenIcon'
    });
}

function setRedColor (objectId) {
    objectManager.objects.setClusterOptions(objectId, {
        preset: 'islands#redIcon'
    });
}