BufferPrimitiveCollection

Collection of primitives held in ArrayBuffer storage for performance and memory optimization.

To get the full performance benefit of using a BufferPrimitiveCollection containing "N" primitives, be careful to avoid allocating "N" instances of any related JavaScript object. BufferPrimitive, Color, Cartesian3, and other objects can all be reused when working with large collections, using the flyweight pattern.

abstract new Cesium.BufferPrimitiveCollection(options)

参数名称 类型 描述信息
options object
参数名称 类型 默认值 描述信息
primitiveCountMax number BufferPrimitiveCollection.DEFAULT_CAPACITY 可选
vertexCountMax number BufferPrimitiveCollection.DEFAULT_CAPACITY 可选
show boolean true 可选
debugShowBoundingVolume boolean false 可选
Experimental

This feature is not final and is subject to change without Cesium's standard deprecation policy.

参考:

成员(属性)

Bounding volume for all primitives in the collection, including both shown and hidden primitives.
Total byte length of buffers owned by this collection. Includes any unused space allocated by primitiveCountMax, even if no primitives have yet been added in that space.

debugShowBoundingVolume : boolean

This property is for debugging only; it is not for production use nor is it optimized.

Draws the bounding sphere for each draw command in the primitive.

默认值: false

readonly DEFAULT_CAPACITY : number

Default capacity of buffers on new collections. A quantity of elements: number of vertices in the vertex buffer, primitives in the primitive buffer, etc. This value is arbitrary, and collections cannot be resized, so specific per-buffer capacities should be provided in the collection constructor when available.

readonly primitiveCount : number

Number of primitives in collection. Must be <= primitiveCountMax.

readonly primitiveCountMax : number

Maximum number of primitives this collection can contain. Must be >= primitiveCount.
默认值: BufferPrimitiveCollection.DEFAULT_CAPACITY
Determines if primitives in this collection will be shown.
默认值: true
Number of vertices in collection. Must be <= vertexCountMax.

readonly vertexCountMax : number

Maximum number of vertices this collection can contain. Must be >= vertexCount.
默认值: BufferPrimitiveCollection.DEFAULT_CAPACITY

方法

static Cesium.BufferPrimitiveCollection.clone(collection, result)

Duplicates the contents of this collection into the result collection. Result collection is not resized, and must contain enough space for all primitives in the source collection. Existing primitives in the result collection will be overwritten.

Useful when allocating more space for a collection that has reached its capacity, and efficiently transferring features to the new collection.

参数名称 类型 描述信息
collection BufferPrimitiveCollection.<T>
result BufferPrimitiveCollection.<T>
使用示例:
const result = new BufferPrimitiveCollection({ ... }); // allocate larger 'result' collection
BufferPrimitiveCollection.clone(collection, result);   // copy primitives from 'collection' into 'result'
Adds a new primitive to the collection, with the specified options. A BufferPrimitive instance is linked to the new primitive, using the 'result' argument if given, or a new instance if not. For repeated calls, prefer to reuse a single BufferPrimitive instance rather than allocating a new instance on each call.
参数名称 类型 描述信息
options BufferPrimitiveOptions
result BufferPrimitive
返回值:
Makes the given BufferPrimitive a view onto this collection's primitive at the given index, for use when reading/writing primitive properties. When iterating over a large collection, prefer to reuse the same BufferPrimitive instance throughout the loop — rebinding an existing instance to a different primitive is cheap, and avoids allocating in-memory objects for every object.
参数名称 类型 描述信息
index number
result BufferPrimitive
返回值:
The BufferPrimitive instance passed as the 'result' argument, now bound to the specified primitive index.
使用示例:
const primitive = new BufferPrimitive();
for (let i = 0; i < collection.primitiveCount; i++) {
  collection.get(i, primitive);
  primitive.setColor(Color.RED);
}
Returns true if this object was destroyed; otherwise, false.
返回值:
True if this object was destroyed; otherwise, false.

sort(sortFn, result)Uint32Array

Sorts primitives of the collection. Because sorting changes the indices (but not the feature IDs) of primitives in the collection, the function also returns an array mapping from previous index to new index. When sorting repeatedly, the array can be reused and passed as the 'result' argument for each call.
参数名称 类型 描述信息
sortFn function
result Uint32Array
返回值:
Mapping from previous index to new index.
Returns a JSON-serializable array representing the collection. This encoding is not memory-efficient, and should generally be used for debugging and testing.
返回值:
List of JSON-serializable objects, one for each primitive in the collection.
使用示例:
console.table(collection.toJSON());
参数名称 类型 描述信息
frameState object