English中文

BillboardCollection

new Cesium.BillboardCollection(options)

可渲染的广告牌集合。广告牌是位于 3D 场景中的视口对齐图像。 A renderable collection of billboards. Billboards are viewport-aligned images positioned in the 3D scene.


广告牌示例 Example billboards


使用以下方法在集合中添加和删除广告牌 Billboards are added and removed from the collection using BillboardCollection#add and BillboardCollection#remove。集合中的广告牌会自动共享具有相同标识符的图像的纹理。 . Billboards in a collection automatically share textures for images with the same identifier.
性能: Performance:

为了获得最佳性能,最好选择几个集合,每个集合都有许多广告牌,而不是多个集合,每个集合只有几个广告牌。整理集合,使更新频率相同的广告牌在同一个集合中,即不发生变化的广告牌应在一个集合中;每帧都改变的广告牌应该在另一个集合中;等等。 For best performance, prefer a few collections, each with many billboards, to many collections with only a few billboards each. Organize collections so that billboards with the same update frequency are in the same collection, i.e., billboards that do not change should be in one collection; billboards that change every frame should be in another collection; and so on.

名称 Name 类型 Type 说明 Description
options object 可选 optional 具有以下属性的对象: Object with the following properties:
名称 Name 类型 Type 默认值 Default 说明 Description
modelMatrix Matrix4 Matrix4.IDENTITY 可选 optional 将每个广告牌从模型转换到世界坐标的 4x4 转换矩阵。 The 4x4 transformation matrix that transforms each billboard from model to world coordinates.
debugShowBoundingVolume boolean false 可选 optional 仅用于调试。确定是否显示该图元的命令的边界球体。 For debugging only. Determines if this primitive's commands' bounding spheres are shown.
scene Scene 可选 optional 必须传入使用高度参考属性的广告牌或将针对地球进行深度测试。 Must be passed in for billboards that use the height reference property or will be depth tested against the globe.
blendOption BlendOption BlendOption.OPAQUE_AND_TRANSLUCENT 可选 optional 广告牌混合选项。默认值用于渲染不透明和半透明的广告牌。但是,如果所有广告牌都完全不透明或完全半透明,则将技术设置为 BlendOption.OPAQUE 或 BlendOption.TRANSLUCENT 可以将性能提高多达 2 倍。 The billboard blending option. The default is used for rendering both opaque and translucent billboards. However, if either all of the billboards are completely opaque or all are completely translucent, setting the technique to BlendOption.OPAQUE or BlendOption.TRANSLUCENT can improve performance by up to 2x.
show boolean true 可选 optional 确定是否显示集合中的广告牌。 Determines if the billboards in the collection will be shown.
coarseDepthTestDistance number 可选 optional 距相机的距离,超过该距离,广告牌将根据地球椭球体的近似值而不是完整的地球深度缓冲区进行深度测试。如果未指定,则默认值是相对于以下值确定的 The distance from the camera, beyond which, billboards are depth-tested against an approximation of the globe ellipsoid rather than against the full globe depth buffer. If unspecified, the default value is determined relative to the value of Ellipsoid.default.
threePointDepthTestDistance number 可选 optional 距摄像机的距离,在该距离内,广告牌上有 The distance from the camera, within which, billboards with a Billboard#heightReference 的价值 value of HeightReference.CLAMP_TO_GROUND or HeightReference.CLAMP_TO_TERRAIN 针对三个关键点进行深度测试。这确保了如果广告牌的任何关键点可见,则整个广告牌都将可见。如果未指定,则默认值是相对于以下值确定的 are depth tested against three key points. This ensures that if any key point of the billboard is visible, the whole billboard will be visible. If unspecified, the default value is determined relative to the value of Ellipsoid.default.
示例: 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.OPAQUE 或 BlendOption.TRANSLUCENT 可以将性能提高多达 2 倍。 The billboard blending option. The default is used for rendering both opaque and translucent billboards. However, if either all of the billboards are completely opaque or all are completely translucent, setting the technique to BlendOption.OPAQUE or BlendOption.TRANSLUCENT can improve performance by up to 2x.
默认值: Default Value: BlendOption.OPAQUE_AND_TRANSLUCENT

coarseDepthTestDistance : number

距相机的距离,超过该距离,广告牌将根据地球椭球体的近似值而不是完整的地球深度缓冲区进行深度测试。当设置为 The distance from the camera, beyond which, billboards are depth-tested against an approximation of the globe ellipsoid rather than against the full globe depth buffer. When set to 0,始终应用近似深度测试。当设置为 , the approximate depth test is always applied. When set to Number.POSITIVE_INFINITY,从不应用近似深度测试。 , the approximate depth test is never applied.

此设置仅适用于广告牌 This setting only applies when a billboard's Billboard#disableDepthTestDistance 否则,该值将允许深度测试,即从相机到广告牌的距离小于广告牌的距离 value would otherwise allow depth testing—i.e., distance from the camera to the billboard is less than a billboard's Billboard#disableDepthTestDistance value.

debugShowBoundingVolume : boolean

该属性仅用于调试;它不适合生产用途,也没有经过优化。 This property is for debugging only; it is not for production use nor is it optimized.

Draws the bounding sphere for each draw command in the primitive.

默认值: Default Value: false

debugShowTextureAtlas : boolean

该属性仅用于调试;它不适合生产用途,也没有经过优化。 This property is for debugging only; it is not for production use nor is it optimized.

将此 BillboardCollection 的纹理图集绘制为全屏四边形。 Draws the texture atlas for this BillboardCollection as a fullscreen quad.

默认值: Default Value: false
返回此集合中的广告牌数量。这通常与 Returns the number of billboards in this collection. This is commonly used with BillboardCollection#get 迭代集合中的所有广告牌。 to iterate over all the billboards in the collection.
4x4 转换矩阵,用于将该集合中的每个广告牌从模型转换为世界坐标。当这是单位矩阵时,广告牌是在世界坐标(即地球的 WGS84 坐标)中绘制的。可以通过提供不同的变换矩阵来使用局部参考系,例如返回的矩阵 The 4x4 transformation matrix that transforms each billboard in this collection from model to world coordinates. When this is the identity matrix, the billboards are drawn in world coordinates, i.e., Earth's WGS84 coordinates. Local reference frames can be used by providing a different transformation matrix, like that returned by 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:
确定是否显示此集合中的广告牌。 Determines if billboards in this collection will be shown.
默认值: Default Value: true

threePointDepthTestDistance : number

距摄像机的距离,在该距离内,广告牌上有 The distance from the camera, within which, billboards with a Billboard#heightReference 的价值 value of HeightReference.CLAMP_TO_GROUND or HeightReference.CLAMP_TO_TERRAIN 针对三个关键点进行深度测试。这确保了如果广告牌的任何关键点可见,则整个广告牌都将可见。当设置为 are depth tested against three key points. This ensures that if any key point of the billboard is visible, the whole billboard will be visible. When set to 0,此功能被禁用,并且地形后面的广告牌部分被剪掉。 , this feature is disabled and portions of a billboards behind terrain be clipped.

此设置仅适用于广告牌 This setting only applies when a billboard's Billboard#disableDepthTestDistance 否则,该值将允许深度测试,即从相机到广告牌的距离小于广告牌的距离 value would otherwise allow depth testing—i.e., distance from the camera to the billboard is less than a billboard's Billboard#disableDepthTestDistance value.
另见: See:

方法 Methods

创建具有指定初始属性的广告牌并将其添加到集合中。返回添加的广告牌,以便稍后对其进行修改或从集合中删除。 Creates and adds a billboard with the specified initial properties to the collection. The added billboard is returned so it can be modified or removed from the collection later.
性能: Performance:

Calling add 是预期的常数时间。然而,集合的顶点缓冲区被重写 is expected constant time. However, the collection's vertex buffer is rewritten - an O(n) 操作也会产生 CPU 到 GPU 的开销。为了获得最佳性能,请在调用之前添加尽可能多的广告牌 operation that also incurs CPU to GPU overhead. For best performance, add as many billboards as possible before calling update.

名称 Name 类型 Type 说明 Description
options Billboard.ConstructorOptions 可选 optional 描述广告牌属性的模板,如示例 1 所示。 A template describing the billboard's properties as shown in Example 1.
返回: Returns:
添加到集合中的广告牌。 The billboard that was added to the collection.
抛出: Throws:
  • DeveloperError : This object was destroyed, i.e., destroy() was called.
示例: 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:

contains(billboard)boolean

检查此集合是否包含给定的广告牌。 Check whether this collection contains a given billboard.
名称 Name 类型 Type 说明 Description
billboard Billboard 可选 optional 要检查的广告牌。 The billboard to check for.
返回: Returns:
如果此集合包含广告牌,则为 true,否则为 false。 true if this collection contains the billboard, false otherwise.
另见: See:
销毁该对象持有的 WebGL 资源。销毁对象可以确定性地释放 WebGL 资源,而不是依赖垃圾收集器来销毁该对象。 Destroys the WebGL resources held by this object. Destroying an object allows for deterministic release of WebGL resources, instead of relying on the garbage collector to destroy this object.

一旦对象被销毁,就不应再使用;调用除 Once an 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:
billboards = billboards && billboards.destroy();
另见: See:
返回集合中指定索引处的广告牌。指数从零开始,并随着广告牌的添加而增加。删除广告牌会将其后面的所有广告牌向左移动,从而更改其索引。此功能通常与 Returns the billboard in the collection at the specified index. Indices are zero-based and increase as billboards are added. Removing a billboard shifts all billboards after it to the left, changing their indices. This function is commonly used with BillboardCollection#length 迭代集合中的所有广告牌。 to iterate over all the billboards in the collection.
性能: Performance:

预期时间恒定。如果广告牌被从集合中移除并且 Expected constant time. If billboards were removed from the collection and BillboardCollection#update 没有被调用,隐式的 was not called, an implicit O(n) 执行操作。 operation is performed.

名称 Name 类型 Type 说明 Description
index number 广告牌的从零开始的索引。 The zero-based index of the billboard.
返回: Returns:
指定索引处的广告牌。 The billboard at the specified index.
抛出: Throws:
  • DeveloperError : This object was destroyed, i.e., destroy() was called.
示例: 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:
如果该对象被销毁则返回 true;否则为假。 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:

remove(billboard)boolean

从集合中删除广告牌。 Removes a billboard from the collection.
性能: Performance:

Calling remove 是预期的常数时间。然而,集合的顶点缓冲区被重写 is expected constant time. However, the collection's vertex buffer is rewritten - an O(n) 操作也会产生 CPU 到 GPU 的开销。为了获得最佳性能,请在调用之前删除尽可能多的广告牌 operation that also incurs CPU to GPU overhead. For best performance, remove as many billboards as possible before calling update。如果您打算暂时隐藏广告牌,通常拨打电话会更有效 . If you intend to temporarily hide a billboard, it is usually more efficient to call Billboard#show 而不是删除并重新添加广告牌。 instead of removing and re-adding the billboard.

名称 Name 类型 Type 说明 Description
billboard Billboard 要移除的广告牌。 The billboard to remove.
返回: Returns:
true 广告牌是否被拆除; if the billboard was removed; false 如果在集合中未找到广告牌。 if the billboard was not found in the collection.
抛出: Throws:
  • DeveloperError : This object was destroyed, i.e., destroy() was called.
示例: Example:
const b = billboards.add(...);
billboards.remove(b);  // Returns true
另见: See:
从集合中删除所有广告牌。 Removes all billboards from the collection.
性能: Performance:

O(n)。从集合中删除所有广告牌然后添加新广告牌比完全创建新集合更有效。 . It is more efficient to remove all the billboards from a collection and then add new ones than to create a new collection entirely.

抛出: Throws:
  • DeveloperError : This object was destroyed, i.e., destroy() was called.
示例: Example:
billboards.add(...);
billboards.add(...);
billboards.removeAll();
另见: See:
调用时间 Called when Viewer or CesiumWidget 渲染场景以获取渲染此图元所需的绘制命令。 render the scene to get the draw commands needed to render this primitive.

不要直接调用该函数。记录此内容只是为了列出渲染场景时可能传播的异常: Do not call this function directly. This is documented just to list the exceptions that may be propagated when the scene is rendered:

抛出: Throws:
  • RuntimeError : 带有id的图片必须在图集中。 : image with id must be in the atlas.
需要帮助吗?获得答案的最快方法是从社区和团队那里获得答案 Need help? The fastest way to get answers is from the community and team on the Cesium Forum.