用于在
Globe 或 Cesium3DTileset 上渲染栅格影像的有序影像图层集合。
Scene#imageryLayers用于操作地球上的影像图层。Cesium3DTileset#imageryLayers用于操作 3D 瓦片集上的影像图层。
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 : index(如果提供)必须大于或等于零且小于或等于图层数量。
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(`创建影像图层时出错。${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 : layer 不在此集合中。
-
DeveloperError : 此对象已被销毁,即已调用 destroy()。
将图层降低到集合的底部。
| Name | Type | Description |
|---|---|---|
layer |
ImageryLayer | 要移动的图层。 |
Throws:
-
DeveloperError : layer 不在此集合中。
-
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('未拾取到要素。');
} else {
Promise.resolve(featuresPromise).then(function(features) {
// 此函数在拾取要素列表可用时异步调用。
console.log(`要素数量:${features.length}`);
if (features.length > 0) {
console.log(`第一个要素名称:${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 : layer 不在此集合中。
-
DeveloperError : 此对象已被销毁,即已调用 destroy()。
将图层提升到集合的顶部。
| Name | Type | Description |
|---|---|---|
layer |
ImageryLayer | 要移动的图层。 |
Throws:
-
DeveloperError : layer 不在此集合中。
-
DeveloperError : 此对象已被销毁,即已调用 destroy()。
从集合中移除图层(如果存在)。
| Name | Type | Default | Description |
|---|---|---|---|
layer |
ImageryLayer | 要移除的图层。 | |
destroy |
boolean |
true
|
optional 是否除了移除图层外还销毁它们。 |
Returns:
如果图层在集合中并被移除则为 true,
如果图层不在集合中则为 false。
从集合中移除所有图层。
| Name | Type | Default | Description |
|---|---|---|---|
destroy |
boolean |
true
|
optional 是否除了移除图层外还销毁它们。 |
