可渲染的广告牌集合。广告牌是视口对齐的
图像,定位于 3D 场景中。

示例广告牌
广告牌通过

示例广告牌
广告牌通过
BillboardCollection#add
和 BillboardCollection#remove 从集合中添加和移除。集合中的广告牌自动共享
具有相同标识符的图像纹理。
Performance:
为了获得最佳性能,建议使用少量集合,每个集合中包含多个广告牌,而不是许多集合中仅包含少量广告牌。组织集合,以便具有相同更新频率的广告牌位于同一集合中,即不变化的广告牌应在一个集合中;每帧变化的广告牌应在另一个集合中;依此类推。
| Name | Type | Description | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
optional
具有以下属性的对象:
|
Example:
// Create a billboard collection with two billboards
const billboards = scene.primitives.add(new Cesium.BillboardCollection());
billboards.add({
position : new Cesium.Cartesian3(1.0, 2.0, 3.0),
image : 'url/to/image'
});
billboards.add({
position : new Cesium.Cartesian3(4.0, 5.0, 6.0),
image : 'url/to/another/image'
});
Demo:
See:
Members
blendOption : BlendOption
广告牌混合选项。默认情况下用于渲染不透明和半透明的广告牌。
然而,如果所有广告牌都是完全不透明或完全半透明,
将技术设置为 BlendOption.OPAQUE 或 BlendOption.TRANSLUCENT 可以提高
性能最多 2 倍。
-
Default Value:
BlendOption.OPAQUE_AND_TRANSLUCENT
此属性仅用于调试;不适用于生产环境,也未进行优化。
绘制基元中每个绘制命令的包围球。
-
Default Value:
false
此属性仅用于调试;不适用于生产环境,也未进行优化。
将此 BillboardCollection 的纹理图集绘制为全屏四边形。
-
Default Value:
false
返回此集合中广告牌的数量。这通常与
BillboardCollection#get 一起使用,以遍历集合中的所有广告牌。
modelMatrix : Matrix4
将此集合中每个广告牌从模型坐标转换为世界坐标的 4x4 变换矩阵。
当这是单位矩阵时,广告牌在世界坐标中绘制,即地球的 WGS84 坐标。
通过提供不同的变换矩阵(如
Transforms.eastNorthUpToFixedFrame 返回的矩阵)可以使用局部参考框架。
-
Default Value:
Matrix4.IDENTITY
Example:
const center = Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883);
billboards.modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(center);
billboards.add({
image : 'url/to/image',
position : new Cesium.Cartesian3(0.0, 0.0, 0.0) // center
});
billboards.add({
image : 'url/to/image',
position : new Cesium.Cartesian3(1000000.0, 0.0, 0.0) // east
});
billboards.add({
image : 'url/to/image',
position : new Cesium.Cartesian3(0.0, 1000000.0, 0.0) // north
});
billboards.add({
image : 'url/to/image',
position : new Cesium.Cartesian3(0.0, 0.0, 1000000.0) // up
});
See:
确定此集合中的广告牌是否会被显示。
-
Default Value:
true
Methods
add(options) → Billboard
创建并将具有指定初始属性的广告牌添加到集合中。
添加的广告牌将被返回,以便可以在稍后修改或从集合中移除。
Performance:
调用 add 预期为常数时间。然而,集合的顶点缓冲区
需要重写 - 这是一个 O(n) 操作,同时会产生 CPU 到 GPU 的开销。
为了获得最佳性能,请在调用 update 之前尽可能添加多个广告牌。
| Name | Type | Description |
|---|---|---|
options |
Billboard.ConstructorOptions | optional 描述广告牌属性的模板,如示例 1 所示。 |
Returns:
添加到集合中的广告牌。
Throws:
-
DeveloperError : 此对象已销毁,即调用了 destroy()。
Examples:
// Example 1: Add a billboard, specifying all the default values.
const b = billboards.add({
show : true,
position : Cesium.Cartesian3.ZERO,
pixelOffset : Cesium.Cartesian2.ZERO,
eyeOffset : Cesium.Cartesian3.ZERO,
heightReference : Cesium.HeightReference.NONE,
horizontalOrigin : Cesium.HorizontalOrigin.CENTER,
verticalOrigin : Cesium.VerticalOrigin.CENTER,
scale : 1.0,
image : 'url/to/image',
imageSubRegion : undefined,
color : Cesium.Color.WHITE,
id : undefined,
rotation : 0.0,
alignedAxis : Cesium.Cartesian3.ZERO,
width : undefined,
height : undefined,
scaleByDistance : undefined,
translucencyByDistance : undefined,
pixelOffsetScaleByDistance : undefined,
sizeInMeters : false,
distanceDisplayCondition : undefined
});
// Example 2: Specify only the billboard's cartographic position.
const b = billboards.add({
position : Cesium.Cartesian3.fromDegrees(longitude, latitude, height)
});
See:
检查此集合是否包含给定的广告牌。
| Name | Type | Description |
|---|---|---|
billboard |
Billboard | optional 要检查的广告牌。 |
Returns:
如果此集合包含广告牌则返回 true,否则返回 false。
销毁此对象持有的 WebGL 资源。销毁对象允许确定性地
释放 WebGL 资源,而不是依赖垃圾收集器销毁此对象。
一旦对象被销毁,则不应使用;调用除
一旦对象被销毁,则不应使用;调用除
isDestroyed 以外的任何函数将导致 DeveloperError 异常。因此,
将返回值 (undefined) 赋值给对象,如示例中所示。
Throws:
-
DeveloperError : 此对象已被销毁,即调用了 destroy()。
Example:
billboards = billboards && billboards.destroy();
See:
get(index) → Billboard
返回集合中指定索引的广告牌。索引是零基础的
随着广告牌的添加而增加。移除一个广告牌将把其后的所有广告牌向左移动,从而改变它们的索引。
此函数通常与
BillboardCollection#length 一起使用,以遍历集合中的所有广告牌。
Performance:
预期为常数时间。如果从集合中移除广告牌而没有调用
BillboardCollection#update,则执行隐式的 O(n)
操作。
| Name | Type | Description |
|---|---|---|
index |
number | 广告牌的零基础索引。 |
Returns:
指定索引处的广告牌。
Throws:
-
DeveloperError : 此对象已被销毁,即调用了 destroy()。
Example:
// Toggle the show property of every billboard in the collection
const len = billboards.length;
for (let i = 0; i < len; ++i) {
const b = billboards.get(i);
b.show = !b.show;
}
See:
Returns:
如果此对象已被销毁则返回
true;否则返回 false。
从集合中移除一个广告牌。
Performance:
调用 remove 预期为常数时间。然而,集合的顶点缓冲区
需要重写 - 这是一个 O(n) 操作,同时会产生 CPU 到 GPU 的开销。
为了获得最佳性能,请在调用 update 之前尽可能移除多个广告牌。
如果您打算暂时隐藏广告牌,通常更有效的方法是调用
Billboard#show,而不是移除并重新添加广告牌。
| Name | Type | Description |
|---|---|---|
billboard |
Billboard | 要移除的广告牌。 |
Returns:
如果广告牌被移除则返回
true;如果在集合中未找到广告牌,则返回 false。
Throws:
-
DeveloperError : 此对象已被销毁,即调用了 destroy()。
Example:
const b = billboards.add(...);
billboards.remove(b); // Returns true
See:
从集合中移除所有广告牌。
Performance:
O(n)。从集合中移除所有广告牌
然后再添加新的广告牌,比完全创建一个新集合更有效。
Throws:
-
DeveloperError : 此对象已被销毁,即调用了 destroy()。
Example:
billboards.add(...);
billboards.add(...);
billboards.removeAll();
See:
Throws:
-
RuntimeError : 具有 id 的图像必须在图集中。
