Documentation
Reference
2.1.50 (current version)
collection
interactivityModel
Interfaces

GeoObjectCollection

Extends IGeoObject, IGeoObjectCollection.

Collection of geo objects. Allows you to group geo objects for adding them to the map, setting options, etc. Collections are geo objects too.

Constructor | Fields | Events | Methods

Constructor

GeoObjectCollection([feature[, options]])

Creates a collection of geo objects.

Parameters:

ParameterDefault valueDescription
feature

Type: Object

Collection description. For all purposes, corresponds to the geo object description. See GeoObject object.

feature.children

Type: IGeoObject[]

Array of child geoobjects.

feature.geometry

Type: IGeometry|Object

Geometry of a collection.

feature.properties

Type: IDataManager|Object

Collection data.

options

Type: Object

Collection options. You can set all the options described in the GeoObject object. Option values will be applied both to the collection itself and to its child objects, if these options are not set for them.

Example:

// Creating a collection of geo objects and setting options.
var myGeoObjects = new ymaps.GeoObjectCollection({}, {
    preset: "islands#redCircleIcon",
    strokeWidth: 4,
    geodesic: true
});

// Adding placemarks and a polyline to the collection.
myGeoObjects.add(new ymaps.Placemark([13.38, 52.51]));
myGeoObjects.add(new ymaps.Placemark([30.30, 50.27]));
myGeoObjects.add(new ymaps.Polyline([[13.38, 52.51], [30.30, 50.27]]));

// Adding the collection to the map.
myMap.geoObjects.add(myGeoObjects);
// Setting the map center and scale so that the whole collection is visible.
myMap.setBounds(myGeoObjects.getBounds());

Fields

NameTypeDescription
eventsIEventManager

Event manager.

Inherited from IDomEventEmitter.

geometryIGeometry|null

Geo object geometry.

Inherited from IGeoObject.

optionsIOptionManager

Options manager.

Inherited from ICustomizable.

propertiesIDataManager

Geo object data.

Inherited from IGeoObject.

stateIDataManager

State of the geo object.

Inherited from IGeoObject.

Events

NameDescription
add

A child geo object has been added (inserted). Instance of the Event class. Names of fields that are available via the Event.get method:

  • index: Integer - Index of the added geo object.
  • child: IGeoObject - Reference to the added geo object.

Inherited from IGeoObjectCollection.

boundschange

Change to coordinates of the geographical area that includes the collection and all its child geo objects. Instance of the Event class.

click

Single left-click on the object. When using, keep in mind that mouse events are emulated when a touch screen is used. More information is available in domEvent.manager.

Inherited from IDomEventEmitter.

contextmenu

Calls the element's context menu. When using, keep in mind that mouse events are emulated when a touch screen is used. More information is available in domEvent.manager.

Inherited from IDomEventEmitter.

dblclick

Double left-click on the object. When using, keep in mind that mouse events are emulated when a touch screen is used. More information is available in domEvent.manager.

Inherited from IDomEventEmitter.

geometrychange

Change to the geo object geometry. Instance of the Event class. Names of fields that are available via the Event.get method:

  • originalEvent: IEvent - Original event of the geometry.

Inherited from IGeoObject.

mapchange

Map reference changed. Data fields:

  • oldMap - Old map.
  • newMap - New map.

Inherited from IParentOnMap.

mousedown

Pressing the mouse button over the object. When using, keep in mind that mouse events are emulated when a touch screen is used. More information is available in domEvent.manager.

Inherited from IDomEventEmitter.

mouseenter

Pointing the cursor at the object. When using, keep in mind that mouse events are emulated when a touch screen is used. More information is available in domEvent.manager.

Inherited from IDomEventEmitter.

mouseleave

Moving the cursor off of the object. When using, keep in mind that mouse events are emulated when a touch screen is used. More information is available in domEvent.manager.

Inherited from IDomEventEmitter.

mousemove

Moving the cursor over the object. When using, keep in mind that mouse events are emulated when a touch screen is used. More information is available in domEvent.manager.

Inherited from IDomEventEmitter.

mouseup

Letting go of the mouse button over an object. When using, keep in mind that mouse events are emulated when a touch screen is used. More information is available in domEvent.manager.

Inherited from IDomEventEmitter.

multitouchend

End of multitouch. This event is only available on devices that support multitouch. Returns an implementation of the IMultiTouchEvent interface.

Inherited from IDomEventEmitter.

multitouchmove

Repeating event during multitouch. This event is only available on devices that support multitouch. Returns an implementation of the IMultiTouchEvent interface with information about touches. Defines the touches property, which contains a list of touches. Every touch is described by an object that contains the following fields:

  • clientX - X coordinate of the touch relative to the viewable area of the browser.
  • clientY - Y coordinate of the touch relative to the viewable area of the browser.
  • pageX - X coordinate of the touch relative to the beginning of the document.
  • pageY - Y coordinate of the touch relative to the beginning of the document.

Inherited from IDomEventEmitter.

multitouchstart

Start of multitouch. This event is only available on devices that support multitouch. Returns an implementation of the IMultiTouchEvent interface with information about touches. Defines the touches property, which contains a list of touches. Every touch is described by an object that contains the following fields:

  • clientX - X coordinate of the touch relative to the viewable area of the browser.
  • clientY - Y coordinate of the touch relative to the viewable area of the browser.
  • pageX - X coordinate of the touch relative to the beginning of the document.
  • pageY - Y coordinate of the touch relative to the beginning of the document.

Inherited from IDomEventEmitter.

optionschange

Change to the object options.

Inherited from ICustomizable.

overlaychange

Change to the geo object overlay. Instance of the Event class. Names of fields that are available via the Event.get method:

  • overlay: IOverlay|null - Reference to the overlay.
  • oldOverlay: IOverlay|null - Previous overlay of the geo object.

Inherited from IGeoObject.

parentchange

The parent object reference changed.

Data fields:

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

Inherited from IChild.

pixelboundschange

Change to pixel coordinates of the area that includes the collection and all its child geo objects. Instance of the Event class.

propertieschange

Change to the geo object data. Instance of the Event class. Names of fields that are available via the Event.get method:

  • originalEvent: IEvent - Original event of the data manager.

Inherited from IGeoObject.

remove

A child geo object has been removed. Instance of the Event class. Names of fields that are available via the Event.get method:

  • index: Integer - Index of the deleted geo object.
  • child: IGeoObject - Reference to the deleted geo object.

Inherited from IGeoObjectCollection.

set

A new child geo object has been added to the collection. Instance of the Event class. Names of fields that are available via the Event.get method:

  • index: Integer - Index of the geo object.
  • child: IGeoObject - Reference to the new geo object.
  • prevChild: IGeoObject - Reference to the previous value for this index.

Inherited from IGeoObjectCollection.

wheel

Mouse wheel scrolling. When using, keep in mind that mouse events are emulated when a touch screen is used. More information is available in domEvent.manager.

Inherited from IDomEventEmitter.

Methods

NameReturnsDescription
add(child)

GeoObjectCollection

Adds a geo object to the collection.

each(callback[, context])

Iterates through all the items in the collection and calls a handler function for each of them.

get(index)

IGeoObject

Returns a child geo object with the specified index.

Inherited from IGeoObjectCollection.

getBounds()

Number[][]|null

Returns geographical coordinates of the area that covers the collection and all its child geo objects.

getIterator()

IIterator

Returns iterator for the collection.

getLength()

Integer

Returns the number of geo objects in the collection.

getMap()

Map

Returns reference to the map.

Inherited from IParentOnMap.

getOverlay()

vow.Promise

Returns the promise object, which is confirmed by the overlay object at the time it is actually created, or is rejected with an appropriate error message.

Inherited from IGeoObject.

getOverlaySync()

IOverlay|null

The method provides synchronous access to the overlay.

Inherited from IGeoObject.

getParent()

IControlParent|null

Returns link to the parent object, or null if the parent element was not set.

Inherited from IChildOnMap.

getPixelBounds()

Number[][]|null

Returns global pixel coordinates of the area that spans the collection and all its child geo objects.

indexOf(object)

Integer

Returns index of the child geo object. If the geo object cannot be found in the collection, -1 is returned.

Inherited from IGeoObjectCollection.

remove(child)

GeoObjectCollection

Removes a geo object from the collection.

removeAll()

GeoObjectCollection

Removes all the geo objects from the collection.

set(index, child)

GeoObjectCollection

Adds a new child geo object to the collection.

setParent(parent)

IChildOnMap

Sets the parent object. If the null value is passed, the manager element will only be deleted from the current parent object.

Inherited from IChildOnMap.

splice(index, number)

GeoObjectCollection

Removes geo objects from the collection. If necessary, puts other objects in their place. Objects that will be added in place of the deleted ones are passed as additional parameters (after the "number" parameter).

toArray()

IGeoObject[]

Returns an array containing all the collection's geo objects at the time of the method call.

Events details

boundschange

Change to coordinates of the geographical area that includes the collection and all its child geo objects. Instance of the Event class.

pixelboundschange

Change to pixel coordinates of the area that includes the collection and all its child geo objects. Instance of the Event class.

Methods details

add

Adds a geo object to the collection.

Returns a reference to the collection.

Parameters:

ParameterDefault valueDescription
child*
[no-highlight[

* Mandatory parameter/option.

]no-highlight]

Type: IGeoObject

Child object.

* Mandatory parameter/option.

each

{} each(callback[, context])

Iterates through all the items in the collection and calls a handler function for each of them.

Parameters:

ParameterDefault valueDescription
callback*
[no-highlight[

* Mandatory parameter/option.

]no-highlight]

Type: Function

Handler function.

context

Type: Object

Context for the function.

* Mandatory parameter/option.

getBounds

{Number[][]|null} getBounds()

Returns geographical coordinates of the area that covers the collection and all its child geo objects.

Example:

// Setting the map center and zoom so that the entire collection is displayed.
myMap.setBounds(myCollection.getBounds());

getIterator

{IIterator} getIterator()

Returns iterator for the collection.

Example:

// Searching the collection for a geo object with the "Polyline" geometry.
var iterator = myGroup.getIterator(),
    object;
while ((object = iterator.getNext()) != iterator.STOP_ITERATION) {
    if (object.geometry.getType() == "LineString") {
        break;
    }
}

getLength

{Integer} getLength()

Returns the number of geo objects in the collection.

getPixelBounds

{Number[][]|null} getPixelBounds()

Returns global pixel coordinates of the area that spans the collection and all its child geo objects.

remove

Removes a geo object from the collection.

Returns a reference to the collection.

Parameters:

ParameterDefault valueDescription
child*
[no-highlight[

* Mandatory parameter/option.

]no-highlight]

Type: IGeoObject

Child object.

* Mandatory parameter/option.

removeAll

{GeoObjectCollection} removeAll()

Removes all the geo objects from the collection.

Returns a reference to the collection.

set

Adds a new child geo object to the collection.

Returns self-reference.

Parameters:

ParameterDefault valueDescription
index*
[no-highlight[

* Mandatory parameter/option.

]no-highlight]

Type: Integer

Index.

child*
[no-highlight[

* Mandatory parameter/option.

]no-highlight]

Type: IGeoObject

Child object.

* Mandatory parameter/option.

splice

Removes geo objects from the collection. If necessary, puts other objects in their place. Objects that will be added in place of the deleted ones are passed as additional parameters (after the "number" parameter).

Returns collection of deleted geo objects.

Parameters:

ParameterDefault valueDescription
index*
[no-highlight[

* Mandatory parameter/option.

]no-highlight]

Type: Integer

Index of the geo object to start deletion from.

number*
[no-highlight[

* Mandatory parameter/option.

]no-highlight]

Type: Integer

The number of geo objects to be deleted.

* Mandatory parameter/option.

Example:

// Removes the second object.
myGeoObjects.splice(1, 1);
// Puts a new "obj" object in the second position.
myGeoObjects.splice(1, 0, obj);
// Replaces the second object with the new "obj" object.
myGeoObjects.splice(1, 1, obj);

toArray

{IGeoObject[]} toArray()

Returns an array containing all the collection's geo objects at the time of the method call.