objectManager.ObjectCollection
Extends ICollection, ICustomizable.
Collection of objects added to the layer.
Constructor | Fields | Events | Methods
Constructor
objectManager.ObjectCollection()
Fields
Name |
Type |
Description |
Object balloon in the manager. |
||
Event manager. Inherited from IEventEmitter. |
||
Object hint in the ObjectManager. |
||
Options manager. Names of fields that are available via the option.Manager#get method:
|
||
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 |
Adds an object to the collection. Instance of the Event class. Names of fields that are available via the Event.get method:
|
|
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:
|
|
Change to the object options. Inherited from ICustomizable. |
|
Removes an object from the collection. Instance of the Event class. Names of fields that are available via the Event.get method:
|
Methods
Name |
Returns |
Description |
This method completely duplicates the logic of ObjectManager.add. |
||
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. |
Object|null |
Returns the object, or null if an object with the passed ID does not exist. |
|
Returns iterator for the collection. Inherited from ICollection. |
||
Number |
Returns the number of objects in the collection. |
|
Returns the parent layer of objects in the collection. |
||
This method completely duplicates the logic of ObjectManager.remove. |
||
Deletes all the items from a collection. |
||
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 |
|
|
— |
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 |
— |
Type: Function Handler function that the collection objects are passed to. |
|
— |
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 |
|
— |
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 |
|
|
— |
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 |
— |
Type: Number ID of the object to set options for. |
|
— |
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'
});
}
Mandatory parameter/option.