原语的集合。这最常与 A collection of primitives. This is most often used with
Scene#primitives,但是 , but PrimitiveCollection 本身也是一个基元,因此可以将集合添加到形成层次结构的集合中。 is also a primitive itself so collections can be added to collections forming a hierarchy.
| 名称 Name | 类型 Type | 说明 Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
可选 optional
具有以下属性的对象: Object with the following properties:
|
示例: 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
确定集合中的基元在被删除时是否被销毁 Determines if primitives in the collection are destroyed when they are removed by
PrimitiveCollection#destroy or PrimitiveCollection#remove 或隐式地通过 or implicitly by 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
获取集合中基元的数量。 Gets the number of primitives in the collection.
readonly primitiveAdded : Event
将基元添加到集合时引发的事件。事件处理程序将传递添加的原语。 An event that is raised when a primitive is added to the collection. Event handlers are passed the primitive that was added.
readonly primitiveRemoved : Event
从集合中删除基元时引发的事件。事件处理程序将传递已删除的原语。 An event that is raised when a primitive is removed from the collection. Event handlers are passed the primitive that was removed.
注意:根据 destroyPrimitives 构造函数选项,基元可能已经被销毁。 Note: Depending on the destroyPrimitives constructor option, the primitive may already be destroyed.
确定是否显示该集合中的基元。 Determines if primitives in this collection will be shown.
-
默认值: Default Value:
true
方法 Methods
将原语添加到集合中。 Adds a primitive to the collection.
| 名称 Name | 类型 Type | 说明 Description |
|---|---|---|
primitive |
object | 要添加的原语。 The primitive to add. |
index |
number | 可选 optional 添加图层的索引。如果省略,该基元将添加到所有现有基元的底部。 The index to add the layer at. If omitted, the primitive will be added at the bottom of all existing primitives. |
返回: Returns:
添加到集合中的原语。 The primitive added to the collection.
抛出: Throws:
-
DeveloperError : This object was destroyed, i.e., destroy() was called.
示例: Example:
const billboards = scene.primitives.add(new Cesium.BillboardCollection());
确定此集合是否包含基元。 Determines if this collection contains a primitive.
| 名称 Name | 类型 Type | 说明 Description |
|---|---|---|
primitive |
object | 可选 optional 要检查的原语。 The primitive to check for. |
返回: Returns:
true 如果原语在集合中; if the primitive is in the collection; false 如果原语是 if the primitive is undefined 或者在集合中没有找到。 or was not found in the collection.
抛出: Throws:
-
DeveloperError : This object was destroyed, i.e., destroy() was called.
另见: See:
销毁该集合中每个图元所持有的 WebGL 资源。显式销毁此集合可以确定性地释放 WebGL 资源,而不是依赖垃圾收集器来销毁此集合。 Destroys the WebGL resources held by each primitive in this collection. Explicitly destroying this collection allows for deterministic release of WebGL resources, instead of relying on the garbage collector to destroy this collection.
由于销毁集合会销毁所有包含的基元,因此只有在确定没有其他代码仍在使用任何包含的基元时才销毁集合。 Since destroying a collection destroys all the contained primitives, only destroy a collection when you are sure no other code is still using any of the contained primitives.
一旦该集合被销毁,则不应再使用;调用除 Once this collection is destroyed, it should not be used; calling any function other than
由于销毁集合会销毁所有包含的基元,因此只有在确定没有其他代码仍在使用任何包含的基元时才销毁集合。 Since destroying a collection destroys all the contained primitives, only destroy a collection when you are sure no other code is still using any of the contained primitives.
一旦该集合被销毁,则不应再使用;调用除 Once this collection 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:
primitives = primitives && primitives.destroy();
另见: See:
返回集合中指定索引处的基元。 Returns the primitive in the collection at the specified index.
| 名称 Name | 类型 Type | 说明 Description |
|---|---|---|
index |
number | 要返回的基元的从零开始的索引。 The zero-based index of the primitive to return. |
返回: Returns:
原始的在 The primitive at the
index.
抛出: Throws:
-
DeveloperError : This object was destroyed, i.e., destroy() was called.
示例: 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;否则为假。 Returns true if this object was destroyed; otherwise, false.
如果该对象被破坏,则不应使用它;调用除 If this object was destroyed, it should not be used; calling any function other than
如果该对象被破坏,则不应使用它;调用除 If this object was destroyed, it should not be used; calling any function other than
isDestroyed 将导致 will result in a DeveloperError exception.
返回: Returns:
如果该对象被销毁,则为 True;否则为假。 True if this object was destroyed; otherwise, false.
另见: See:
降低集合中的原始“下一个”。如果集合中的所有图元都绘制在地球表面上,则这会在视觉上将图元向下移动一位。 Lowers a primitive "down one" in the collection. If all primitives in the collection are drawn on the globe surface, this visually moves the primitive down one.
| 名称 Name | 类型 Type | 说明 Description |
|---|---|---|
primitive |
object | 可选 optional 原始地降低。 The primitive to lower. |
抛出: Throws:
-
DeveloperError : 原始类型不在此集合中。 : primitive is not in this collection.
-
DeveloperError : This object was destroyed, i.e., destroy() was called.
将基元降低到集合的“底部”。如果集合中的所有图元都绘制在地球表面上,则这会在视觉上将图元移动到底部。 Lowers a primitive to the "bottom" of the collection. If all primitives in the collection are drawn on the globe surface, this visually moves the primitive to the bottom.
| 名称 Name | 类型 Type | 说明 Description |
|---|---|---|
primitive |
object | 可选 optional 降低到底部的原语。 The primitive to lower to the bottom. |
抛出: Throws:
-
DeveloperError : 原始类型不在此集合中。 : primitive is not in this collection.
-
DeveloperError : This object was destroyed, i.e., destroy() was called.
在集合中提出一个原始的“up one”。如果集合中的所有图元都绘制在地球表面上,则这会在视觉上将图元向上移动一位。 Raises a primitive "up one" in the collection. If all primitives in the collection are drawn on the globe surface, this visually moves the primitive up one.
| 名称 Name | 类型 Type | 说明 Description |
|---|---|---|
primitive |
object | 可选 optional 原始养育。 The primitive to raise. |
抛出: Throws:
-
DeveloperError : 原始类型不在此集合中。 : primitive is not in this collection.
-
DeveloperError : This object was destroyed, i.e., destroy() was called.
将原语提升到集合的“顶部”。如果集合中的所有图元都绘制在地球表面上,则这会在视觉上将图元移动到顶部。 Raises a primitive to the "top" of the collection. If all primitives in the collection are drawn on the globe surface, this visually moves the primitive to the top.
| 名称 Name | 类型 Type | 说明 Description |
|---|---|---|
primitive |
object | 可选 optional 原始的抬高顶部。 The primitive to raise the top. |
抛出: Throws:
-
DeveloperError : 原始类型不在此集合中。 : primitive is not in this collection.
-
DeveloperError : This object was destroyed, i.e., destroy() was called.
从集合中删除一个基元。 Removes a primitive from the collection.
| 名称 Name | 类型 Type | 说明 Description |
|---|---|---|
primitive |
object | 可选 optional 要删除的原语。 The primitive to remove. |
返回: Returns:
true 如果原语被删除; if the primitive was removed; false 如果原语是 if the primitive is undefined 或者在集合中没有找到。 or was not found in the collection.
抛出: Throws:
-
DeveloperError : This object was destroyed, i.e., destroy() was called.
示例: Example:
const billboards = scene.primitives.add(new Cesium.BillboardCollection());
scene.primitives.remove(billboards); // Returns true
另见: See:
删除集合中的所有基元。 Removes all primitives in the collection.
抛出: Throws:
-
DeveloperError : This object was destroyed, i.e., destroy() was called.
