map.GeoObjects

Extends IGeoObjectCollection.

Collection of map geo objects. Each map already has its own geo objects collection, available as map.geoObjects. Don't instantiate new instances of this class unless necessary.

See Map.geoObjects

Constructor | Fields | Events | Methods

Constructor

map.GeoObjects(map[, options])

Parameters:

Parameter

Default value

Description

map*

Type: Map

Map.

options

Type: Object

Options of a collection of geo objects. The map.geoObjects options can be used to make settings for geo objects that have been added to the map:

  • Options for clusterers with the clusterer prefix.
  • Options for clusters with the cluster prefix.

* Mandatory parameter/option.

Fields

Name

Type

Description

events

IEventManager

Event manager.

Inherited from IEventEmitter.

options

IOptionManager

Options manager.

Inherited from ICustomizable.

Events

Name

Description

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 spans the collection and its child geo objects. Instance of the Event class.

Inherited from IGeoObjectCollection.

mapchange

Map reference changed. Data fields:

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

Inherited from IParentOnMap.

optionschange

Change to the object options.

Inherited from ICustomizable.

pixelboundschange

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

Inherited from IGeoObjectCollection.

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.

Methods

Name

Returns

Description

add(child[, index])

map.GeoObjects

Adds (inserts) a child geo object to the collection.

each(callback[, context])

Calls a handler function for each child geo object.

get(index)

IGeoObject

Returns a child geo object with the specified index.

getBounds()

Number[][]|null

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

getIterator()

IIterator

Returns iterator for the collection.

getLength()

Integer

Returns length of the collection.

getMap()

Map

Returns reference to the map.

Inherited from IParentOnMap.

getPixelBounds()

Number[][]|null

Returns global pixel coordinates of the area that spans the collection and 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.

remove(child)

map.GeoObjects

Removes a child geo object from the collection.

removeAll()

map.GeoObjects

Clears the collection.

set(index, child)

map.GeoObjects

Adds a new child geo object to the collection.

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

Methods details

add

{map.GeoObjects} add(child[, index])

Adds (inserts) a child geo object to the collection.

Returns self-reference.

Parameters:

Parameter

Default value

Description

child*

Type: IGeoObject

Child object.

index

Type: Integer

The index where the new object is added. By default, the object is added to the end of the collection.

* Mandatory parameter/option.

each

{} each(callback[, context])

Calls a handler function for each child geo object.

Parameters:

Parameter

Default value

Description

callback*

Type: Function

Handler function.

context

Type: Object

Context for the handler function.

* Mandatory parameter/option.

Example:

// Displaying a geo object's index in a collection for its icon contents.
myGeoObjects.events.add(["add", "remove", "set"], function () {
    this.each(function (el, i) {
        el.properties.set("iconContent", i);
    })
}, myGeoObjects);

get

{IGeoObject} get(index)

Returns a child geo object with the specified index.

Parameters:

Parameter

Default value

Description

index*

Type: Integer

Index.

* Mandatory parameter/option.

getBounds

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

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

getIterator

{IIterator} getIterator()

Returns iterator for the collection.

getLength

{Integer} getLength()

Returns length of the collection.

getPixelBounds

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

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

indexOf

{Integer} indexOf(object)

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

Parameters:

Parameter

Default value

Description

object*

Type: Object

Child object.

* Mandatory parameter/option.

remove

{map.GeoObjects} remove(child)

Removes a child geo object from the collection.

Returns self-reference.

Parameters:

Parameter

Default value

Description

child*

Type: IGeoObject

Geo object being removed.

* Mandatory parameter/option.

Example:

// When a geo object is clicked, we remove it from the collection.
myGeoObjects.events.add("click", function (e) {
    if (e.get("target").getParent() == this) {
        this.remove(e.get("target"));
    }
}, myGeoObjects);

removeAll

{map.GeoObjects} removeAll()

Clears the collection.

Returns self-reference.

set

{map.GeoObjects} set(index, child)

Adds a new child geo object to the collection.

Returns self-reference.

Parameters:

Parameter

Default value

Description

index*

Type: Integer

Index.

child*

Type: IGeoObject

Child object.

* Mandatory parameter/option.

splice

{GeoObjectCollection} splice(index, number)

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:

Parameter

Default value

Description

index*

Type: Integer

Index of the geo object to start deletion from.

number*

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);