Skip to content

KBE3D / KBCore / Cesium / ImageryLayerCollection

类: ImageryLayerCollection

An ordered collection of imagery layers for rendering raster imagery on a Globe or Cesium3DTileset.

属性

layerAdded

layerAdded: Event

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.


layerRemoved

layerRemoved: Event

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.


layerMoved

layerMoved: Event

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.


layerShownOrHidden

layerShownOrHidden: Event

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.


length

length: number

Gets the number of layers in this collection.

方法

add()

add(layer: ImageryLayer, index?: number): void

Adds a layer to the collection.

参数

layer

ImageryLayer

the layer to add.

index?

number

the index to add the layer at. If omitted, the layer will be added on top of all existing layers.

返回

void

Examples

ts
const imageryLayer = Cesium.ImageryLayer.fromWorldImagery();
scene.imageryLayers.add(imageryLayer);
ts
const imageryLayer = Cesium.ImageryLayer.fromProviderAsync(Cesium.IonImageryProvider.fromAssetId(3812));
scene.imageryLayers.add(imageryLayer);

addImageryProvider()

addImageryProvider(imageryProvider: ImageryProvider, index?: number): ImageryLayer

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

参数

imageryProvider

ImageryProvider

the imagery provider to create a new layer for.

index?

number

the index to add the layer at. If omitted, the layer will added on top of all existing layers.

返回

ImageryLayer

The newly created layer.

示例

ts
try {
   const provider = await Cesium.IonImageryProvider.fromAssetId(3812);
   scene.imageryLayers.addImageryProvider(provider);
} catch (error) {
  console.log(`There was an error creating the imagery layer. ${error}`)
}

remove()

remove(layer: ImageryLayer, destroy?: boolean): boolean

Removes a layer from this collection, if present.

参数

layer

ImageryLayer

The layer to remove.

destroy?

boolean

whether to destroy the layers in addition to removing them.

返回

boolean

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


removeAll()

removeAll(destroy?: boolean): void

Removes all layers from this collection.

参数

destroy?

boolean

whether to destroy the layers in addition to removing them.

返回

void


contains()

contains(layer: ImageryLayer): boolean

Checks to see if the collection contains a given layer.

参数

layer

ImageryLayer

the layer to check for.

返回

boolean

true if the collection contains the layer, false otherwise.


indexOf()

indexOf(layer: ImageryLayer): number

Determines the index of a given layer in the collection.

参数

layer

ImageryLayer

The layer to find the index of.

返回

number

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


get()

get(index: number): ImageryLayer

Gets a layer by index from the collection.

参数

index

number

the index to retrieve.

返回

ImageryLayer

The imagery layer at the given index.


raise()

raise(layer: ImageryLayer): void

Raises a layer up one position in the collection.

参数

layer

ImageryLayer

the layer to move.

返回

void


lower()

lower(layer: ImageryLayer): void

Lowers a layer down one position in the collection.

参数

layer

ImageryLayer

the layer to move.

返回

void


raiseToTop()

raiseToTop(layer: ImageryLayer): void

Raises a layer to the top of the collection.

参数

layer

ImageryLayer

the layer to move.

返回

void


lowerToBottom()

lowerToBottom(layer: ImageryLayer): void

Lowers a layer to the bottom of the collection.

参数

layer

ImageryLayer

the layer to move.

返回

void


pickImageryLayers()

pickImageryLayers(ray: Ray, scene: Scene): ImageryLayer[] | undefined

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.

参数

ray

Ray

The ray to test for intersection.

scene

Scene

The scene.

返回

ImageryLayer[] | undefined

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


pickImageryLayerFeatures()

pickImageryLayerFeatures(ray: Ray, scene: Scene): Promise<ImageryLayerFeatureInfo[]> | undefined

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.

参数

ray

Ray

The ray to test for intersection.

scene

Scene

The scene.

返回

Promise<ImageryLayerFeatureInfo[]> | undefined

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.

示例

ts
const pickRay = viewer.camera.getPickRay(windowPosition);
const featuresPromise = viewer.imageryLayers.pickImageryLayerFeatures(pickRay, viewer.scene);
if (!Cesium.defined(featuresPromise)) {
    console.log('No features picked.');
} else {
    Promise.resolve(featuresPromise).then(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}`);
        }
    });
}

isDestroyed()

isDestroyed(): boolean

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

返回

boolean

true if this object was destroyed; otherwise, false.


destroy()

destroy(): void

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. <br /><br /> Once this object is destroyed, it should not be used; calling any function other than <code>isDestroyed</code> will result in a DeveloperError exception. Therefore, assign the return value (<code>undefined</code>) to the object as done in the example.

返回

void

示例

ts
layerCollection = layerCollection && layerCollection.destroy();

构造函数

构造函数

new ImageryLayerCollection(): ImageryLayerCollection

返回

ImageryLayerCollection

KBE3D @3.0.0 Copyright © 2024-present KBE3D