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.
参数名称 | 类型 | 描述信息 | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
可选
Object with the following properties:
|
使用示例:
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
成员(属性)
Determines if primitives in the collection are destroyed when they are removed by
PrimitiveCollection#destroy
or PrimitiveCollection#remove
or implicitly
by PrimitiveCollection#removeAll
.
-
默认值:
true
使用示例s:
// 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.
Note: Depending on the destroyPrimitives constructor option, the primitive may already be destroyed.
Determines if primitives in this collection will be shown.
-
默认值:
true
方法
Adds a primitive to the collection.
参数名称 | 类型 | 描述信息 |
---|---|---|
primitive |
object | The primitive to add. |
index |
number | 可选 The index to add the layer at. If omitted, the primitive will be added at the bottom of all existing primitives. |
返回值:
The primitive added to the collection.
Throws:
-
DeveloperError : This object was destroyed, i.e., destroy() was called.
使用示例:
const billboards = scene.primitives.add(new Cesium.BillboardCollection());
Determines if this collection contains a primitive.
参数名称 | 类型 | 描述信息 |
---|---|---|
primitive |
object | 可选 The primitive to check for. |
返回值:
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.
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.
使用示例:
primitives = primitives && primitives.destroy();
参考:
Returns the primitive in the collection at the specified index.
参数名称 | 类型 | 描述信息 |
---|---|---|
index |
number | The zero-based index of the primitive to return. |
返回值:
The primitive at the
index
.
Throws:
-
DeveloperError : This object was destroyed, i.e., destroy() was called.
使用示例:
// 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;
}
参考:
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.
返回值:
True if this object was destroyed; otherwise, false.
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.
参数名称 | 类型 | 描述信息 |
---|---|---|
primitive |
object | 可选 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.
参数名称 | 类型 | 描述信息 |
---|---|---|
primitive |
object | 可选 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.
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.
参数名称 | 类型 | 描述信息 |
---|---|---|
primitive |
object | 可选 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.
参数名称 | 类型 | 描述信息 |
---|---|---|
primitive |
object | 可选 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.
参数名称 | 类型 | 描述信息 |
---|---|---|
primitive |
object | 可选 The primitive to remove. |
返回值:
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.
使用示例:
const billboards = scene.primitives.add(new Cesium.BillboardCollection());
scene.primitives.remove(billboards); // Returns true
参考:
Removes all primitives in the collection.
Throws:
-
DeveloperError : This object was destroyed, i.e., destroy() was called.