Points are added and removed from the collection using
PointPrimitiveCollection#add
and PointPrimitiveCollection#remove
.
Performance:
For best performance, prefer a few collections, each with many points, to many collections with only a few points each. Organize collections so that points with the same update frequency are in the same collection, i.e., points that do not change should be in one collection; points that change every frame should be in another collection; and so on.
参数名称 | 类型 | 描述信息 | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
可选
Object with the following properties:
|
使用示例:
// Create a pointPrimitive collection with two points
const points = scene.primitives.add(new Cesium.PointPrimitiveCollection());
points.add({
position : new Cesium.Cartesian3(1.0, 2.0, 3.0),
color : Cesium.Color.YELLOW
});
points.add({
position : new Cesium.Cartesian3(4.0, 5.0, 6.0),
color : Cesium.Color.CYAN
});
参考:
成员(属性)
-
默认值:
BlendOption.OPAQUE_AND_TRANSLUCENT
Draws the bounding sphere for each draw command in the primitive.
-
默认值:
false
PointPrimitiveCollection#get
to iterate over all the points
in the collection.
modelMatrix : Matrix4
Transforms.eastNorthUpToFixedFrame
.
-
默认值:
Matrix4.IDENTITY
使用示例:
const center = Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883);
pointPrimitives.modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(center);
pointPrimitives.add({
color : Cesium.Color.ORANGE,
position : new Cesium.Cartesian3(0.0, 0.0, 0.0) // center
});
pointPrimitives.add({
color : Cesium.Color.YELLOW,
position : new Cesium.Cartesian3(1000000.0, 0.0, 0.0) // east
});
pointPrimitives.add({
color : Cesium.Color.GREEN,
position : new Cesium.Cartesian3(0.0, 1000000.0, 0.0) // north
});
pointPrimitives.add({
color : Cesium.Color.CYAN,
position : new Cesium.Cartesian3(0.0, 0.0, 1000000.0) // up
});
参考:
-
默认值:
true
方法
Performance:
Calling add
is expected constant time. However, the collection's vertex buffer
is rewritten - an O(n)
operation that also incurs CPU to GPU overhead. For
best performance, add as many pointPrimitives as possible before calling update
.
参数名称 | 类型 | 描述信息 |
---|---|---|
options |
object | 可选 A template describing the point's properties as shown in Example 1. |
返回值:
Throws:
-
DeveloperError : This object was destroyed, i.e., destroy() was called.
使用示例s:
// Example 1: Add a point, specifying all the default values.
const p = pointPrimitives.add({
show : true,
position : Cesium.Cartesian3.ZERO,
pixelSize : 10.0,
color : Cesium.Color.WHITE,
outlineColor : Cesium.Color.TRANSPARENT,
outlineWidth : 0.0,
id : undefined
});
// Example 2: Specify only the point's cartographic position.
const p = pointPrimitives.add({
position : Cesium.Cartesian3.fromDegrees(longitude, latitude, height)
});
参考:
参数名称 | 类型 | 描述信息 |
---|---|---|
pointPrimitive |
PointPrimitive | 可选 The point to check for. |
返回值:
Once an object 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.
使用示例:
pointPrimitives = pointPrimitives && pointPrimitives.destroy();
参考:
PointPrimitiveCollection#length
to iterate over all the points
in the collection.
Performance:
Expected constant time. If points were removed from the collection and
PointPrimitiveCollection#update
was not called, an implicit O(n)
operation is performed.
参数名称 | 类型 | 描述信息 |
---|---|---|
index |
number | The zero-based index of the point. |
返回值:
Throws:
-
DeveloperError : This object was destroyed, i.e., destroy() was called.
使用示例:
// Toggle the show property of every point in the collection
const len = pointPrimitives.length;
for (let i = 0; i < len; ++i) {
const p = pointPrimitives.get(i);
p.show = !p.show;
}
参考:
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
.
Performance:
Calling remove
is expected constant time. However, the collection's vertex buffer
is rewritten - an O(n)
operation that also incurs CPU to GPU overhead. For
best performance, remove as many points as possible before calling update
.
If you intend to temporarily hide a point, it is usually more efficient to call
PointPrimitive#show
instead of removing and re-adding the point.
参数名称 | 类型 | 描述信息 |
---|---|---|
pointPrimitive |
PointPrimitive | The point to remove. |
返回值:
true
if the point was removed; false
if the point was not found in the collection.
Throws:
-
DeveloperError : This object was destroyed, i.e., destroy() was called.
使用示例:
const p = pointPrimitives.add(...);
pointPrimitives.remove(p); // Returns true
参考:
Performance:
O(n)
. It is more efficient to remove all the points
from a collection and then add new ones than to create a new collection entirely.
Throws:
-
DeveloperError : This object was destroyed, i.e., destroy() was called.
使用示例:
pointPrimitives.add(...);
pointPrimitives.add(...);
pointPrimitives.removeAll();