PrimitiveCollection

new Cesium.PrimitiveCollection(options)

图元的集合。它最常与 Scene#primitives 一起使用, 但 PrimitiveCollection 本身也是一个图元,因此可以将集合 添加到集合中,从而形成层级结构。
Name Type Description
options object optional Object with the following properties:
Name Type Default Description
show boolean true optional 确定集合中的图元是否显示。
destroyPrimitives boolean true optional 确定集合中的图元在被移除时是否被销毁。
Example:
const billboards = new Cesium.BillboardCollection();
const labels = new Cesium.LabelCollection();

const collection = new Cesium.PrimitiveCollection();
collection.add(billboards);

scene.primitives.add(collection);  // Add collection
scene.primitives.add(labels);      // Add regular primitive

Members

destroyPrimitives : boolean

确定集合中的图元在被以下操作移除时是否被销毁: PrimitiveCollection#destroyPrimitiveCollection#remove, 或通过 PrimitiveCollection#removeAll 隐式地移除。
Default Value: true
Examples:
// Example 1. Primitives are destroyed by default.
const primitives = new Cesium.PrimitiveCollection();
const labels = primitives.add(new Cesium.LabelCollection());
primitives = primitives.destroy();
const b = labels.isDestroyed(); // true
// Example 2. Do not destroy primitives in a collection.
const primitives = new Cesium.PrimitiveCollection();
primitives.destroyPrimitives = false;
const labels = primitives.add(new Cesium.LabelCollection());
primitives = primitives.destroy();
const b = labels.isDestroyed(); // false
labels = labels.destroy();    // explicitly destroy
获取集合中的图元数量。
当向集合中添加图元时触发的事件。 事件处理程序会接收到被添加的图元。
当从集合中移除图元时触发的事件。 事件处理程序会接收到被移除的图元。

注意:取决于 destroyPrimitives 构造函数选项,该图元可能已经被销毁。

确定此集合中的图元是否显示。
Default Value: true

Methods

add(primitive, index)object

向集合中添加图元。
Name Type Description
primitive object 要添加的图元。
index number optional 添加图层所在的索引。如果省略,图元将被添加到所有现有图元的底部。
Returns:
已添加到集合中的图元。
Throws:
Example:
const billboards = scene.primitives.add(new Cesium.BillboardCollection());

contains(primitive)boolean

确定此集合是否包含某个图元。
Name Type Description
primitive object optional 要检查的图元。
Returns:
如果图元在集合中则为 true;如果图元为 undefined 或在集合中未找到则为 false
Throws:
See:
销毁此集合中每个图元持有的 WebGL 资源。显式销毁此 集合可以实现 WebGL 资源的确定性释放,而不是依赖垃圾回收器 来销毁此集合。

由于销毁集合会销毁所有包含的图元,因此只有在确定没有其他代码 仍在使用任何包含的图元时,才应销毁集合。

此集合一旦被销毁就不应再使用;除 isDestroyed 之外的任何函数调用都将导致 DeveloperError 异常。因此, 应将返回值(undefined)赋给该对象,如示例所示。
Throws:
Example:
primitives = primitives && primitives.destroy();
See:
返回集合中指定索引处的图元。
Name Type Description
index number 要返回的图元的从零开始的索引。
Returns:
index 处的图元。
Throws:
Example:
// Toggle the show property of every primitive in the collection.
const primitives = scene.primitives;
const length = primitives.length;
for (let i = 0; i < length; ++i) {
  const p = primitives.get(i);
  p.show = !p.show;
}
See:
如果此对象已被销毁则返回 true;否则返回 false。

如果此对象已被销毁,就不应再使用;除 isDestroyed 之外的任何函数调用都将导致 DeveloperError 异常。
Returns:
如果此对象已被销毁则为 true;否则为 false。
See:
将集合中的图元“下移一层”。如果集合中的所有图元都绘制在 地球表面,这会将该图元在视觉上向下移动一层。
Name Type Description
primitive object optional 要下移的图元。
Throws:
See:
将图元下移至此集合的“底部”。如果集合中的所有图元都绘制在 地球表面,这会将该图元在视觉上移动到最底部。
Name Type Description
primitive object optional 要下移到底部的图元。
Throws:
See:
将集合中的图元“上移一层”。如果集合中的所有图元都绘制在 地球表面,这会将该图元在视觉上向上移动一层。
Name Type Description
primitive object optional 要上移的图元。
Throws:
See:
将图元上移至此集合的“顶部”。如果集合中的所有图元都绘制在 地球表面,这会将该图元在视觉上移动到最顶部。
Name Type Description
primitive object optional 要上移到顶部的图元。
Throws:
See:

remove(primitive)boolean

从集合中移除图元。
Name Type Description
primitive object optional 要移除的图元。
Returns:
如果图元被移除则为 true;如果图元为 undefined 或在集合中未找到则为 false
Throws:
Example:
const billboards = scene.primitives.add(new Cesium.BillboardCollection());
scene.primitives.remove(billboards);  // Returns true
See:
移除集合中的所有图元。
Throws:
See:
需要帮助?获取答案的最快方式是在 Cesium 论坛 上向社区和团队提问。