基元的集合。 这最常与
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
,如果原语在集合中;如果
基元未定义
或在集合中找不到,则为 false。
Throws:
-
DeveloperError : 这个物体被摧毁了,destroy().
销毁此集合中每个基元所持有的 WebGL 资源。 显式销毁此
collection 允许确定性地释放 WebGL 资源,而不是依赖垃圾
collector 销毁此集合。
由于销毁集合会销毁所有包含的原语,因此只销毁集合 当您确定没有其他代码仍在使用任何包含的基元时。
此集合一旦销毁,就不应使用;调用
由于销毁集合会销毁所有包含的原语,因此只销毁集合 当您确定没有其他代码仍在使用任何包含的基元时。
此集合一旦销毁,就不应使用;调用
isDestroyed
将导致 DeveloperError
异常。 因此
将返回值 (undefined
) 分配给对象,如示例中所示。
Throws:
-
DeveloperError : 这个物体被摧毁了,destroy().
Example:
primitives = primitives && primitives.destroy();
See:
返回集合中指定索引处的基元。
Name | Type | Description |
---|---|---|
index |
number | 要返回的基元的从零开始的索引。 |
Returns:
索引
处的原语。
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。
降低集合中的基元 “down one”。 如果集合中的所有基元都已绘制
在地球表面上,这会在视觉上将基元向下移动 1。
Name | Type | Description |
---|---|---|
primitive |
object | optional 要降低的原语。 |
Throws:
-
DeveloperError : primitive is not in this collection.
-
DeveloperError : 这个物体被摧毁了,destroy().
将基元降低到集合的 “bottom”。 如果集合中的所有基元都已绘制
在地球表面上,这会在视觉上将基元移动到底部。
Name | Type | Description |
---|---|---|
primitive |
object | optional 要降低到底部的基元。 |
Throws:
-
DeveloperError : primitive is not in this collection.
-
DeveloperError : 这个物体被摧毁了,destroy().
在集合中提升一个原始变量 “up one”。 如果集合中的所有基元都已绘制
在地球表面上,这会在视觉上将基元向上移动 1。
Name | Type | Description |
---|---|---|
primitive |
object | optional 要引发的原语。 |
Throws:
-
DeveloperError : 原语不在此集合中。
-
DeveloperError : 这个物体被摧毁了,destroy().
将原语提升到集合的 “top” 位置。 如果集合中的所有基元都已绘制
在地球曲面上,这会在视觉上将基元移动到顶部。
Name | Type | Description |
---|---|---|
primitive |
object | optional 用于抬高顶部的基元。 |
Throws:
-
DeveloperError : primitive is not in this collection.
-
DeveloperError : 这个物体被摧毁了,destroy().
从集合中删除基元。
Name | Type | Description |
---|---|---|
primitive |
object | optional 要删除的基元。 |
Returns:
true
(如果基元已被删除);如果
基元未定义
或在集合中找不到,则为 false。
Throws:
-
DeveloperError : 这个物体被摧毁了,destroy().
Example:
const billboards = scene.primitives.add(new Cesium.BillboardCollection());
scene.primitives.remove(billboards); // Returns true
See:
删除集合中的所有基元。
Throws:
-
DeveloperError : 这个物体被摧毁了,destroy().