# ImageryLayerCollection

#### new Cesium.ImageryLayerCollection()
Scene/ImageryLayerCollection.js 23

An ordered collection of imagery layers.

##### Demo:

- Cesium Sandcastle Imagery Adjustment Demo
- Cesium Sandcastle Imagery Manipulation Demo

### Members

#### layerAdded : Event
Scene/ImageryLayerCollection.js 32

An event that is raised when a layer is added to the collection. Event handlers are passed the layer that was added and the index at which it was added.

Default Value: `Event()`

#### layerMoved : Event
Scene/ImageryLayerCollection.js 48

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

Default Value: `Event()`

#### layerRemoved : Event
Scene/ImageryLayerCollection.js 40

An event that is raised when a layer is removed from the collection. Event handlers are passed the layer that was removed and the index from which it was removed.

Default Value: `Event()`

#### layerShownOrHidden : Event
Scene/ImageryLayerCollection.js 59

An event that is raised when a layer is shown or hidden by setting the `ImageryLayer#show` property. Event handlers are passed a reference to this layer, the index of the layer in the collection, and a flag that is true if the layer is now shown or false if it is now hidden.

Default Value: `Event()`

#### length : Number
Scene/ImageryLayerCollection.js 68

Gets the number of layers in this collection.

### Methods

#### add(layer, index)
Scene/ImageryLayerCollection.js 84

Adds a layer to the collection.

Name | Type | Description
--- | --- | ---
`layer` | ImageryLayer | the layer to add.
`index` | Number | optional the index to add the layer at. If omitted, the layer will be added on top of all existing layers.

##### Throws:

- DeveloperError : index, if supplied, must be greater than or equal to zero and less than or equal to the number of the layers.

#### addFeatureProvider(FeatureProvider, index) → Object
Scene/ImageryLayerCollection.js 179

Creates a new layer using the given FeatureProvider and adds it to the collection.

Name | Type | Description
--- | --- | ---
`FeatureProvider` | Object | the Feature provider to create a new layer for.
`index` | Number | optional the index to add the layer at. If omitted, the layer will added on top of all existing layers.

##### Returns:

The newly created layer.

#### addGeojsonProvider(GeojsonProvider, index) → Object
Scene/ImageryLayerCollection.js 200

Creates a new layer using the given GeojsonProvider and adds it to the collection.

Name | Type | Description
--- | --- | ---
`GeojsonProvider` | Object | the Geojson provider to create a new layer for.
`index` | Number | optional the index to add the layer at. If omitted, the layer will added on top of all existing layers.

##### Returns:

The newly created layer.

#### addImageryProvider(imageryProvider, index) → ImageryLayer
Scene/ImageryLayerCollection.js 137

创建一个影像图层用添加到影像图层集合中去

Name | Type | Description
--- | --- | ---
`imageryProvider` | ImageryProvider | 影像图层的imageryProvider
`index` | Number | optional 该影像图层的序号

##### Returns:

影像图层

##### Example:

    //创建provider
    //老版本IGS服务
    var provider = new Cesium.MapGISTileServerImageProvider({
        url: 'http://webclient.smaryun.com:6163/igs/rest/mrms/tile/北京市Tile/{level}/{row}/{col}',
    });
    //新版本IGS服务
    var provider = new Cesium.MapGISTileServerImageProvider({
        url: 'http://192.168.82.89:8089/igs/rest/services/Tile/北京市/TileServer/tileImage/{level}/{row}/{col}?f=image',
    });
    //创建并添加影像图层
    var layer = viewer.imageryLayers.addImageryProvider(provider);
    //获取图层序号
    var layerIndex = layer._layerIndex;
    //获取影像图层
    var layer =  viewer.imageryLayers.get(layerIndex);
    //删除影像图层
    viewer.imageryLayers.remove(layerIndex);

#### addVectorProvider(vectorProvider, index) → Object
Scene/ImageryLayerCollection.js 158

Creates a new layer using the given VectorProvider and adds it to the collection.

Name | Type | Description
--- | --- | ---
`vectorProvider` | Object | the vector provider to create a new layer for.
`index` | Number | optional the index to add the layer at. If omitted, the layer will added on top of all existing layers.

##### Returns:

The newly created layer.

#### contains(layer) → Boolean
Scene/ImageryLayerCollection.js 269

Checks to see if the collection contains a given layer.

Name | Type | Description
--- | --- | ---
`layer` | ImageryLayer | the layer to check for.

##### Returns:

true if the collection contains the layer, false otherwise.

#### destroy()
Scene/ImageryLayerCollection.js 621

Destroys the WebGL resources held by all layers 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:

    layerCollection = layerCollection && layerCollection.destroy();

##### See:

- ImageryLayerCollection#isDestroyed

#### get(index) → ImageryLayer
Scene/ImageryLayerCollection.js 291

Gets a layer by index from the collection.

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

##### Returns:

The imagery layer at the given index.

#### indexOf(layer) → Number
Scene/ImageryLayerCollection.js 280

Determines the index of a given layer in the collection.

Name | Type | Description
--- | --- | ---
`layer` | ImageryLayer | The layer to find the index of.

##### Returns:

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

#### isDestroyed() → Boolean
Scene/ImageryLayerCollection.js 600

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:

- ImageryLayerCollection#destroy

#### lower(layer)
Scene/ImageryLayerCollection.js 358

Lowers a layer down one position in the collection.

Name | Type | Description
--- | --- | ---
`layer` | ImageryLayer | the layer to move.

##### Throws:

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

#### lowerToBottom(layer)
Scene/ImageryLayerCollection.js 392

Lowers a layer to the bottom of the collection.

Name | Type | Description
--- | --- | ---
`layer` | ImageryLayer | the layer to move.

##### Throws:

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

#### pickImageryLayerFeatures(ray, scene) → Promise.<Array.<ImageryLayerFeatureInfo>>|undefined
Scene/ImageryLayerCollection.js 519

Asynchronously determines the imagery layer features that are intersected by a pick ray. The intersected imagery layer features are found by invoking `ImageryProvider#pickFeatures` for each imagery layer tile intersected by the pick ray. To compute a pick ray from a location on the screen, use `Camera.getPickRay`.

Name | Type | Description
--- | --- | ---
`ray` | Ray | The ray to test for intersection.
`scene` | Scene | The scene.

##### Returns:

A promise that resolves to an array of features intersected by the pick ray. If it can be quickly determined that no features are intersected (for example, because no active imagery providers support `ImageryProvider#pickFeatures` or because the pick ray does not intersect the surface), this function will return undefined.

##### Example:

    var pickRay = viewer.camera.getPickRay(windowPosition);
    var featuresPromise = viewer.imageryLayers.pickImageryLayerFeatures(pickRay, viewer.scene);
    if (!Cesium.defined(featuresPromise)) {
        console.log('No features picked.');
    } else {
        Cesium.when(featuresPromise, function(features) {
            // This function is called asynchronously when the list if picked features is available.
            console.log('Number of features: ' + features.length);
            if (features.length > 0) {
                console.log('First feature name: ' + features[0].name);
            }
        });
    }

#### pickImageryLayers(ray, scene) → Array.<ImageryLayer>|undefined
Scene/ImageryLayerCollection.js 469

Determines the imagery layers that are intersected by a pick ray. To compute a pick ray from a location on the screen, use `Camera.getPickRay`.

Name | Type | Description
--- | --- | ---
`ray` | Ray | The ray to test for intersection.
`scene` | Scene | The scene.

##### Returns:

An array that includes all of the layers that are intersected by a given pick ray. Undefined if no layers are selected.

#### raise(layer)
Scene/ImageryLayerCollection.js 345

Raises a layer up one position in the collection.

Name | Type | Description
--- | --- | ---
`layer` | ImageryLayer | the layer to move.

##### Throws:

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

#### raiseToTop(layer)
Scene/ImageryLayerCollection.js 371

Raises a layer to the top of the collection.

Name | Type | Description
--- | --- | ---
`layer` | ImageryLayer | the layer to move.

##### Throws:

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

#### remove(layer, destroy) → Boolean
Scene/ImageryLayerCollection.js 220

Removes a layer from this collection, if present.

Name | Type | Default | Description
--- | --- | --- | ---
`layer` | ImageryLayer |  | The layer to remove.
`destroy` | Boolean | `true` | optional whether to destroy the layers in addition to removing them.

##### Returns:

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

#### removeAll(destroy)
Scene/ImageryLayerCollection.js 246

Removes all layers from this collection.

Name | Type | Default | Description
--- | --- | --- | ---
`destroy` | Boolean | `true` | optional whether to destroy the layers in addition to removing them.