# DataSourceCollection

#### new Cesium.DataSourceCollection()
engine/Source/DataSources/DataSourceCollection.js 13

A collection of `DataSource` instances.

### Members

#### readonly dataSourceAdded : Event
engine/Source/DataSources/DataSourceCollection.js 40

An event that is raised when a data source is added to the collection. Event handlers are passed the data source that was added.

#### readonly dataSourceMoved : Event
engine/Source/DataSources/DataSourceCollection.js 66

An event that is raised when a data source changes position in the collection. Event handlers are passed the data source that was moved, its new index after the move, and its old index prior to the move.

#### readonly dataSourceRemoved : Event
engine/Source/DataSources/DataSourceCollection.js 53

An event that is raised when a data source is removed from the collection. Event handlers are passed the data source that was removed.

#### readonly length : number
engine/Source/DataSources/DataSourceCollection.js 27

Gets the number of data sources in this collection.

### Methods

#### add(dataSource) → Promise.<DataSource>
engine/Source/DataSources/DataSourceCollection.js 81

Adds a data source to the collection.

Name | Type | Description
--- | --- | ---
`dataSource` | DataSource | Promise.<DataSource> | A data source or a promise to a data source to add to the collection. When passing a promise, the data source will not actually be added to the collection until the promise resolves successfully.

##### Returns:

A Promise that resolves once the data source has been added to the collection.

#### contains(dataSource) → boolean
engine/Source/DataSources/DataSourceCollection.js 153

Checks to see if the collection contains a given data source.

Name | Type | Description
--- | --- | ---
`dataSource` | DataSource | The data source to check for.

##### Returns:

true if the collection contains the data source, false otherwise.

#### destroy()
engine/Source/DataSources/DataSourceCollection.js 332

Destroys the resources held by all data sources in this collection. Explicitly destroying this object allows for deterministic release of WebGL resources, instead of relying on the garbage collector. Once this object is destroyed, it should not be used; calling any function other than `isDestroyed` will result in a `DeveloperError` exception. Therefore, assign the return value (`undefined`) to the object as done in the example.

##### Throws:

- DeveloperError : This object was destroyed, i.e., destroy() was called.

##### Example:

    dataSourceCollection = dataSourceCollection && dataSourceCollection.destroy();

##### See:

- DataSourceCollection#isDestroyed

#### get(index) → DataSource
engine/Source/DataSources/DataSourceCollection.js 173

Gets a data source by index from the collection.

Name | Type | Description
--- | --- | ---
`index` | number | the index to retrieve.

##### Returns:

The data source at the specified index.

#### getByName(name) → Array.<DataSource>
engine/Source/DataSources/DataSourceCollection.js 189

Gets a data source by name from the collection.

Name | Type | Description
--- | --- | ---
`name` | string | The name to retrieve.

##### Returns:

A list of all data sources matching the provided name.

#### indexOf(dataSource) → number
engine/Source/DataSources/DataSourceCollection.js 163

Determines the index of a given data source in the collection.

Name | Type | Description
--- | --- | ---
`dataSource` | DataSource | The data source to find the index of.

##### Returns:

The index of the data source in the collection, or -1 if the data source does not exist in the collection.

#### isDestroyed() → boolean
engine/Source/DataSources/DataSourceCollection.js 313

Returns true if this object was destroyed; otherwise, false. If this object was destroyed, it should not be used; calling any function other than `isDestroyed` will result in a `DeveloperError` exception.

##### Returns:

true if this object was destroyed; otherwise, false.

##### See:

- DataSourceCollection#destroy

#### lower(dataSource)
engine/Source/DataSources/DataSourceCollection.js 257

Lowers a data source down one position in the collection.

Name | Type | Description
--- | --- | ---
`dataSource` | DataSource | The data source to move.

##### Throws:

- DeveloperError : dataSource is not in this collection.
- DeveloperError : This object was destroyed, i.e., destroy() was called.

#### lowerToBottom(dataSource)
engine/Source/DataSources/DataSourceCollection.js 293

Lowers a data source to the bottom of the collection.

Name | Type | Description
--- | --- | ---
`dataSource` | DataSource | The data source to move.

##### Throws:

- DeveloperError : dataSource is not in this collection.
- DeveloperError : This object was destroyed, i.e., destroy() was called.

#### raise(dataSource)
engine/Source/DataSources/DataSourceCollection.js 244

Raises a data source up one position in the collection.

Name | Type | Description
--- | --- | ---
`dataSource` | DataSource | The data source to move.

##### Throws:

- DeveloperError : dataSource is not in this collection.
- DeveloperError : This object was destroyed, i.e., destroy() was called.

#### raiseToTop(dataSource)
engine/Source/DataSources/DataSourceCollection.js 270

Raises a data source to the top of the collection.

Name | Type | Description
--- | --- | ---
`dataSource` | DataSource | The data source to move.

##### Throws:

- DeveloperError : dataSource is not in this collection.
- DeveloperError : This object was destroyed, i.e., destroy() was called.

#### remove(dataSource, destroy) → boolean
engine/Source/DataSources/DataSourceCollection.js 109

Removes a data source from this collection, if present.

Name | Type | Default | Description
--- | --- | --- | ---
`dataSource` | DataSource |  | The data source to remove.
`destroy` | boolean | `false` | optional Whether to destroy the data source in addition to removing it.

##### Returns:

true if the data source was in the collection and was removed, false if the data source was not in the collection.

#### removeAll(destroy)
engine/Source/DataSources/DataSourceCollection.js 132

Removes all data sources from this collection.

Name | Type | Default | Description
--- | --- | --- | ---
`destroy` | boolean | `false` | optional whether to destroy the data sources in addition to removing them.

Need help? The fastest way to get answers is from the community and team on the Cesium Forum.