用于在
Globe 或 Cesium3DTileset 上渲染栅格影像的、有序的影像图层集合。
Scene#imageryLayersfor manipulating imagery layers on the globe.Cesium3DTileset#imageryLayersfor manipulating imagery layers on a 3D tileset.
Demo:
See:
Members
layerAdded : Event
当图层被添加到集合时引发的事件。事件处理程序会接收到被添加的图层以及它被添加时的索引。
-
Default Value:
Event()
layerMoved : Event
当图层在集合中的位置发生变化时引发的事件。事件处理程序会接收到被移动的图层、移动后的新索引,以及移动前的旧索引。
-
Default Value:
Event()
layerRemoved : Event
当图层从集合中被移除时引发的事件。事件处理程序会接收到被移除的图层以及它被移除时的索引。
-
Default Value:
Event()
layerShownOrHidden : Event
当通过设置
ImageryLayer#show 属性来显示或隐藏图层时引发的事件。事件处理程序会接收到该图层的引用、图层在集合中的索引,以及一个标志位——如果图层现在被显示则为 true,如果现在被隐藏则为 false。
-
Default Value:
Event()
获取此集合中的图层数量。
Methods
向集合中添加图层。
| Name | Type | Description |
|---|---|---|
layer |
ImageryLayer | 要添加的图层。 |
index |
number | optional 添加图层的索引位置。如果省略,图层将被添加到所有现有图层的顶部。 |
Throws:
-
DeveloperError :如果提供了索引,则必须大于等于零且小于或等于图层的数量。
Examples:
const imageryLayer = Cesium.ImageryLayer.fromWorldImagery();
scene.imageryLayers.add(imageryLayer);
const imageryLayer = Cesium.ImageryLayer.fromProviderAsync(Cesium.IonImageryProvider.fromAssetId(3812));
scene.imageryLayers.add(imageryLayer);
addImageryProvider(imageryProvider, index) → ImageryLayer
使用给定的 ImageryProvider 创建一个新图层,并将其添加到集合中。
| Name | Type | Description |
|---|---|---|
imageryProvider |
ImageryProvider | 用于创建新图层的影像提供器。 |
index |
number | optional 添加图层的索引位置。如果省略,图层将被添加到所有现有图层的顶部。 |
Returns:
新创建的图层。
Example:
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}`)
}
检查集合是否包含给定的图层。
| Name | Type | Description |
|---|---|---|
layer |
ImageryLayer | 要检查的图层。 |
Returns:
如果集合包含该图层则为 true,否则为 false。
销毁此集合中所有图层所持有的 WebGL 资源。显式销毁该对象可以实现 WebGL 资源的确定性释放,而非依赖垃圾回收器。
一旦该对象被销毁,就不应再使用它;调用除
一旦该对象被销毁,就不应再使用它;调用除
isDestroyed 之外的任何函数都将导致 DeveloperError 异常。因此,请像示例中那样将返回值(undefined)赋给该对象。
Throws:
-
DeveloperError :该对象已被销毁,即已调用 destroy()。
Example:
layerCollection = layerCollection && layerCollection.destroy();
See:
根据索引从集合中获取图层。
| Name | Type | Description |
|---|---|---|
index |
number | 要获取的索引。 |
Returns:
给定索引处的影像图层。
确定给定图层在集合中的索引。
| Name | Type | Description |
|---|---|---|
layer |
ImageryLayer | 要查找其索引的图层。 |
Returns:
图层在集合中的索引;如果图层不存在于集合中,则为 -1。
Returns:
如果此对象已被销毁则为 true;否则为 false。
将图层在集合中向下移动一个位置。
| Name | Type | Description |
|---|---|---|
layer |
ImageryLayer | 要移动的图层。 |
Throws:
-
DeveloperError :图层不在该集合中。
-
DeveloperError :该对象已被销毁,即已调用 destroy()。
将图层降到集合的底部。
| Name | Type | Description |
|---|---|---|
layer |
ImageryLayer | 要移动的图层。 |
Throws:
-
DeveloperError :图层不在该集合中。
-
DeveloperError :该对象已被销毁,即已调用 destroy()。
pickImageryLayerFeatures(ray, scene) → Promise.<Array.<ImageryLayerFeatureInfo>>|undefined
异步确定被拾取射线相交的影像图层要素。通过为拾取射线相交的每个影像图层瓦片调用
ImageryProvider#pickFeatures 来查找相交的影像图层要素。要从屏幕上的某个位置计算拾取射线,请使用 Camera.getPickRay。
| Name | Type | Description |
|---|---|---|
ray |
Ray | 用于测试相交的射线。 |
scene |
Scene | 场景。 |
Returns:
一个 promise,解析为被拾取射线相交的要素数组。
如果可以快速确定没有相交的要素(例如,因为没有活动的影像提供器支持
ImageryProvider#pickFeatures,
或者因为拾取射线没有与表面相交),则此函数将返回 undefined。
Example:
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}`);
}
});
}
pickImageryLayers(ray, scene) → Array.<ImageryLayer>|undefined
确定被拾取射线相交的影像图层。要从屏幕上的某个位置计算拾取射线,请使用
Camera.getPickRay。
| Name | Type | Description |
|---|---|---|
ray |
Ray | 用于测试相交的射线。 |
scene |
Scene | 场景。 |
Returns:
一个数组,包含被给定拾取射线相交的所有图层。如果没有选中任何图层,则为 undefined。
将图层在集合中向上移动一个位置。
| Name | Type | Description |
|---|---|---|
layer |
ImageryLayer | 要移动的图层。 |
Throws:
-
DeveloperError :图层不在该集合中。
-
DeveloperError :该对象已被销毁,即已调用 destroy()。
将图层提升到集合的顶部。
| Name | Type | Description |
|---|---|---|
layer |
ImageryLayer | 要移动的图层。 |
Throws:
-
DeveloperError :图层不在该集合中。
-
DeveloperError :该对象已被销毁,即已调用 destroy()。
如果集合中存在该图层,则将其从集合中移除。
| Name | Type | Default | Description |
|---|---|---|---|
layer |
ImageryLayer | 要移除的图层。 | |
destroy |
boolean |
true
|
optional 除移除图层外是否同时销毁这些图层。 |
Returns:
如果图层原本在集合中且已被移除则为 true;如果图层不在集合中则为 false。
从此集合中移除所有图层。
| Name | Type | Default | Description |
|---|---|---|---|
destroy |
boolean |
true
|
optional 除移除图层外是否同时销毁这些图层。 |
