Appearance
KBE3D / KBCore / Cesium / PrimitiveCollection
类: PrimitiveCollection
A collection of primitives. This is most often used with Scene#primitives, but <code>PrimitiveCollection</code> is also a primitive itself so collections can be added to collections forming a hierarchy.
示例
ts
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参数
Object with the following properties:
参数
Determines if the primitives in the collection will be shown.
参数
Determines if primitives in the collection are destroyed when they are removed.
属性
show
show:
boolean
Determines if primitives in this collection will be shown.
destroyPrimitives
destroyPrimitives:
boolean
Determines if primitives in the collection are destroyed when they are removed by PrimitiveCollection#destroy or PrimitiveCollection#remove or implicitly by PrimitiveCollection#removeAll.
Examples
ts
// 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(); // truets
// 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 destroylength
readonlylength:number
Gets the number of primitives in the collection.
primitiveAdded
readonlyprimitiveAdded:Event
An event that is raised when a primitive is added to the collection. Event handlers are passed the primitive that was added.
primitiveRemoved
readonlyprimitiveRemoved:Event
An event that is raised when a primitive is removed from the collection. Event handlers are passed the primitive that was removed. <p> Note: Depending on the destroyPrimitives constructor option, the primitive may already be destroyed. </p>
方法
add()
add(
primitive:any,index?:number):any
Adds a primitive to the collection.
参数
primitive
any
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.
返回
any
The primitive added to the collection.
示例
ts
const billboards = scene.primitives.add(new Cesium.BillboardCollection());remove()
remove(
primitive?:any):boolean
Removes a primitive from the collection.
参数
primitive?
any
The primitive to remove.
返回
boolean
true if the primitive was removed; false if the primitive is undefined or was not found in the collection.
示例
ts
const billboards = scene.primitives.add(new Cesium.BillboardCollection());
scene.primitives.remove(billboards); // Returns trueremoveAll()
removeAll():
void
Removes all primitives in the collection.
返回
void
contains()
contains(
primitive?:any):boolean
Determines if this collection contains a primitive.
参数
primitive?
any
The primitive to check for.
返回
boolean
true if the primitive is in the collection; false if the primitive is undefined or was not found in the collection.
raise()
raise(
primitive?:any):void
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?
any
The primitive to raise.
返回
void
raiseToTop()
raiseToTop(
primitive?:any):void
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?
any
The primitive to raise the top.
返回
void
lower()
lower(
primitive?:any):void
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?
any
The primitive to lower.
返回
void
lowerToBottom()
lowerToBottom(
primitive?:any):void
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?
any
The primitive to lower to the bottom.
返回
void
get()
get(
index:number):any
Returns the primitive in the collection at the specified index.
参数
index
number
The zero-based index of the primitive to return.
返回
any
The primitive at the index.
示例
ts
// 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;
}isDestroyed()
isDestroyed():
boolean
Returns true if this object was destroyed; otherwise, false. <br /><br /> If this object was destroyed, it should not be used; calling any function other than <code>isDestroyed</code> will result in a DeveloperError exception.
返回
boolean
True if this object was destroyed; otherwise, false.
destroy()
destroy():
void
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. <br /><br /> 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. <br /><br /> Once this collection is destroyed, it should not be used; calling any function other than <code>isDestroyed</code> will result in a DeveloperError exception. Therefore, assign the return value (<code>undefined</code>) to the object as done in the example.
返回
void
示例
ts
primitives = primitives && primitives.destroy();构造函数
构造函数
new PrimitiveCollection(
options?: {show?:boolean;destroyPrimitives?:boolean; }):PrimitiveCollection
参数
options?
show?
boolean
destroyPrimitives?
boolean
返回
PrimitiveCollection
