原始对象的集合。通常与
Scene#primitives 一起使用,
但 PrimitiveCollection 本身也是一个原始对象,因此可以将集合
添加到集合中,形成层次结构。
| Name | Type | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
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
确定集合中的原始对象在通过
PrimitiveCollection#destroy、PrimitiveCollection#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
获取集合中原始对象的数量。
readonly primitiveAdded : Event
当原始对象被添加到集合时引发的事件。
事件处理程序会接收到被添加的原始对象。
readonly primitiveRemoved : Event
当原始对象从集合中移除时引发的事件。
事件处理程序会接收到被移除的原始对象。
注意:根据 destroyPrimitives 构造函数选项,该原始对象可能已经被销毁。
确定此集合中的原始对象是否会被显示。
-
Default Value:
true
Methods
将一个原始对象添加到集合中。
| Name | Type | Description |
|---|---|---|
primitive |
object | 要添加的原始对象。 |
index |
number | optional 要添加层的索引。如果省略,则原始对象将添加到所有现有原始对象的底部。 |
Returns:
添加到集合中的原始对象。
Throws:
-
DeveloperError : 此对象已被销毁,即调用了 destroy()。
Example:
const billboards = scene.primitives.add(new Cesium.BillboardCollection());
确定此集合是否包含一个原始对象。
| Name | Type | Description |
|---|---|---|
primitive |
object | optional 要检查的原始对象。 |
Returns:
如果原始对象在集合中,则返回
true;如果原始对象是 undefined 或未在集合中找到,则返回 false。
Throws:
-
DeveloperError : 此对象已被销毁,即调用了 destroy()。
销毁此集合中每个原始对象持有的 WebGL 资源。显式销毁此
集合允许确定性地释放 WebGL 资源,而不是依赖于垃圾收集器销毁此集合。
由于销毁集合会销毁所有包含的原始对象,因此仅在确定没有其他代码仍在使用 任何包含的原始对象时才销毁集合。
一旦销毁此集合,就不应使用;调用除
由于销毁集合会销毁所有包含的原始对象,因此仅在确定没有其他代码仍在使用 任何包含的原始对象时才销毁集合。
一旦销毁此集合,就不应使用;调用除
isDestroyed 之外的任何功能将导致
DeveloperError 异常。因此,将返回值 (undefined) 赋给对象,如示例中所示。
Throws:
-
DeveloperError : 此对象已被销毁,即调用了 destroy()。
Example:
primitives = primitives && primitives.destroy();
See:
返回集合中指定索引处的原始对象。
| Name | Type | Description |
|---|---|---|
index |
number | 要返回的原始对象的零基索引。 |
Returns:
位于
index 处的原始对象。
Throws:
-
DeveloperError : 此对象已被销毁,即调用了 destroy()。
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:
Returns:
如果此对象已被销毁,则返回 true;否则返回 false。
将原始对象在集合中“向下移动一位”。如果集合中的所有原始对象都绘制在地球表面上,
这将视觉上将原始对象向下移动一位。
| Name | Type | Description |
|---|---|---|
primitive |
object | optional 要降低的原始对象。 |
Throws:
-
DeveloperError : 原始对象不在此集合中。
-
DeveloperError : 此对象已被销毁,即调用了 destroy()。
将原始对象降低到集合的“底部”。如果集合中的所有原始对象都绘制在地球表面上,
这将视觉上将原始对象移动到底部。
| Name | Type | Description |
|---|---|---|
primitive |
object | optional 要降低到底部的原始对象。 |
Throws:
-
DeveloperError : 原始对象不在此集合中。
-
DeveloperError : 此对象已被销毁,即调用了 destroy()。
将原始对象在集合中“向上移动一位”。如果集合中的所有原始对象都绘制在地球表面上,
这将视觉上将原始对象向上移动一位。
| Name | Type | Description |
|---|---|---|
primitive |
object | optional 要提升的原始对象。 |
Throws:
-
DeveloperError : 原始对象不在此集合中。
-
DeveloperError : 此对象已被销毁,即调用了 destroy()。
将原始对象提升到集合的“顶部”。如果集合中的所有原始对象都绘制在地球表面上,
这将视觉上将原始对象移动到顶部。
| Name | Type | Description |
|---|---|---|
primitive |
object | optional 要提升到顶部的原始对象。 |
Throws:
-
DeveloperError : 原始对象不在此集合中。
-
DeveloperError : 此对象已被销毁,即调用了 destroy()。
从集合中移除一个原始对象。
| Name | Type | Description |
|---|---|---|
primitive |
object | optional 要移除的原始对象。 |
Returns:
如果原始对象被移除,则返回
true;如果原始对象是 undefined 或未在集合中找到,则返回 false。
Throws:
-
DeveloperError : 此对象已被销毁,即调用了 destroy()。
Example:
const billboards = scene.primitives.add(new Cesium.BillboardCollection());
scene.primitives.remove(billboards); // Returns true
See:
移除集合中的所有原始对象。
Throws:
-
DeveloperError : 此对象已被销毁,即调用了 destroy()。
