Collection

Extends ICollection, collection.Item.

Basic implementation of an object collection on the map.

Constructor | Fields | Events | Methods

Constructor

Collection([options])

Parameters:

Parameter

Default value

Description

options

Type: Object

Collection options.

Fields

Name

Type

Description

events

IEventManager

Event manager.

Inherited from IEventEmitter.

options

IOptionManager

Options manager.

Inherited from ICustomizable.

Events

Name

Description

add

A child object was added. Instance of the Event class. Names of fields that are available via the Event.get method:

  • child - Child element that was added.

mapchange

Map reference changed. Data fields:

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

Inherited from IParentOnMap.

optionschange

Change to the object options.

Inherited from ICustomizable.

parentchange

The parent object reference changed.

Data fields:

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

Inherited from IChild.

remove

A child object was deleted. Instance of the Event class. Names of fields that are available via the Event.get method:

  • child - Child element that was deleted.

Methods

Name

Returns

Description

add(child)

Collection

Adds an item to the collection.

each(callback[, context])

Collection

Calls a handler function for all the items in the collection.

filter(filterFunction)

Object[]

Calls a filter function for all the items in the collection. When the filter returns a non-zero value, the collection item goes in the final array.

get(index)

Object

Returns a collection item, or null if the number is outside of the range for the collection's numbers.

getAll()

Object[]

Returns an array with all the collection items.

getIterator()

IIterator

Returns an iterator for selecting collection items.

getLength()

Number

Returns the number of items in the collection.

getMap()

Map

Returns the map that the collection item belongs to.

Inherited from collection.Item.

getParent()

IParentOnMap

Returns parent object.

Inherited from collection.Item.

indexOf(childToFind)

Number

Returns the sequential number of the object in the collection, or -1 if the object was not found.

onAddToMap(map)

Function that is called when adding an element to the map. To perform additional actions when adding the object to the map, redefine this function.

Inherited from collection.Item.

onRemoveFromMap(oldMap)

Function that is called when deleting an element from the map. To perform additional actions when deleting the object from the map, redefine this function.

Inherited from collection.Item.

remove(child)

Collection

Deletes an item from a collection.

removeAll()

Collection

Deletes all the items from a collection.

setParent(parent)

collection.Item

Sets the parent for the selected item in a collection.

Inherited from collection.Item.

Events details

add

A child object was added. Instance of the Event class. Names of fields that are available via the Event.get method:

  • child - Child element that was added.

remove

A child object was deleted. Instance of the Event class. Names of fields that are available via the Event.get method:

  • child - Child element that was deleted.

Methods details

add

{Collection} add(child)

Adds an item to the collection.

Returns self-reference.

Parameters:

Parameter

Default value

Description

child*

Type: collection.Item

Element to add.

* Mandatory parameter/option.

each

{Collection} each(callback[, context])

Calls a handler function for all the items in the collection.

Returns self-reference.

Parameters:

Parameter

Default value

Description

callback*

Type: Function

Handler function. Receives a collection item as input. If the function returns the value "false," processing stops.

context

Type: Object

Context of the invoked function.

* Mandatory parameter/option.

filter

{Object[]} filter(filterFunction)

Calls a filter function for all the items in the collection. When the filter returns a non-zero value, the collection item goes in the final array.

Returns an array of items that were selected.

Parameters:

Parameter

Default value

Description

filterFunction*

Type: Function

Function that works as a filter for the collection's objects. It takes an item from the collection as the first parameter. It should return a boolean value.

* Mandatory parameter/option.

get

{Object} get(index)

Returns a collection item, or null if the number is outside of the range for the collection's numbers.

Parameters:

Parameter

Default value

Description

index*

Type: Number

The sequential number of the item in the collection.

* Mandatory parameter/option.

getAll

{Object[]} getAll()

Returns an array with all the collection items.

getIterator

{IIterator} getIterator()

Returns an iterator for selecting collection items.

getLength

{Number} getLength()

Returns the number of items in the collection.

indexOf

{Number} indexOf(childToFind)

Returns the sequential number of the object in the collection, or -1 if the object was not found.

Parameters:

Parameter

Default value

Description

childToFind*

Type: Object

The required object.

* Mandatory parameter/option.

remove

{Collection} remove(child)

Deletes an item from a collection.

Returns self-reference.

Parameters:

Parameter

Default value

Description

child*

Type: collection.Item

Item to delete.

* Mandatory parameter/option.

removeAll

{Collection} removeAll()

Deletes all the items from a collection.

Returns self-reference.