objectManager.ObjectCollection

Extends ICollection, ICustomizable.

Collection of objects added to the layer.

Constructor | Fields | Events | Methods

Constructor

objectManager.ObjectCollection()

Fields

Name

Type

Description

balloon

objectManager.Balloon

Object balloon in the manager.

events

IEventManager

Event manager.

Inherited from IEventEmitter.

hint

objectManager.Hint

Object hint in the ObjectManager.

options

option.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.

overlays

objectManager.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

Name

Description

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

Name

Returns

Description

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. Note that the manager ignores the 'visible' option.

Fields details

balloon

{objectManager.Balloon} balloon

Object balloon in the manager.

hint

{objectManager.Hint} 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

{objectManager.OverlayCollection} 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

{objectManager.ObjectCollection} add(data)

This method completely duplicates the logic of ObjectManager.add.

Returns self-reference.

Parameters:

Parameter

Default value

Description

data*

—

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:

Parameter

Default value

Description

callback*

—

Type: Function

Handler function that the collection objects are passed to.

context*

—

Type: Object

Context for the handler function.

* Mandatory parameter/option.

Example:

var singleCounter = 0;
var 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:

Parameter

Default value

Description

id*

—

Type: Number

Object ID.

* Mandatory parameter/option.

Example:

objectManager.objects.add('click', function (e) {
    var objectId = e.get('objectId');
    var 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

{objectManager.ObjectCollection} remove(data)

This method completely duplicates the logic of ObjectManager.remove.

Returns self-reference.

Parameters:

Parameter

Default value

Description

data*

—

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

{objectManager.ObjectCollection} removeAll()

Deletes all the items from a collection.

Returns self-reference.

Example:

objectManager.objects.removeAll();

setObjectOptions

{objectManager.ObjectCollection} setObjectOptions(objectId, options)

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. Note that the manager ignores the 'visible' option.

Returns self-reference.

Parameters:

Parameter

Default value

Description

objectId*

—

Type: Number

ID of the object to set options for.

options*

—

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');
    var 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');
    var 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'
    });
}