使用以下方法在集合中添加和删除点 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.
| 名称 Name | 类型 Type | 说明 Description | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
可选 optional
具有以下属性的对象: Object with the following properties:
|
示例: Example:
// 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
});
另见: See:
成员 Members
-
默认值: Default Value:
BlendOption.OPAQUE_AND_TRANSLUCENT
Draws the bounding sphere for each draw command in the primitive.
-
默认值: Default Value:
false
PointPrimitiveCollection#get 迭代集合中的所有点。 to iterate over all the points in the collection.
modelMatrix : Matrix4
Transforms.eastNorthUpToFixedFrame.
-
默认值: Default Value:
Matrix4.IDENTITY
示例: Example:
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
});
另见: See:
-
默认值: Default Value:
true
方法 Methods
性能: Performance:
Calling add 是预期的常数时间。然而,集合的顶点缓冲区被重写 is expected constant time. However, the collection's vertex buffer is rewritten - an O(n) 操作也会产生 CPU 到 GPU 的开销。为了获得最佳性能,请在调用之前添加尽可能多的 pointPrimitives operation that also incurs CPU to GPU overhead. For best performance, add as many pointPrimitives as possible before calling update.
| 名称 Name | 类型 Type | 说明 Description |
|---|---|---|
options |
object | 可选 optional 描述点属性的模板,如示例 1 所示。 A template describing the point's properties as shown in Example 1. |
返回: Returns:
抛出: Throws:
-
DeveloperError : This object was destroyed, i.e., destroy() was called.
示例: Examples:
// 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)
});
另见: See:
| 名称 Name | 类型 Type | 说明 Description |
|---|---|---|
pointPrimitive |
PointPrimitive | 可选 optional 要检查的点。 The point to check for. |
返回: Returns:
另见: See:
一旦对象被销毁,就不应再使用;调用除 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.
示例: Example:
pointPrimitives = pointPrimitives && pointPrimitives.destroy();
另见: See:
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.
| 名称 Name | 类型 Type | 说明 Description |
|---|---|---|
index |
number | 点的从零开始的索引。 The zero-based index of the point. |
返回: Returns:
抛出: Throws:
-
DeveloperError : This object was destroyed, i.e., destroy() was called.
示例: Example:
// 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;
}
另见: See:
如果该对象被破坏,则不应使用它;调用除 If this object was destroyed, it should not be used; calling any function other than
isDestroyed 将导致 will result in a DeveloperError exception.
返回: Returns:
true 如果该物体被摧毁;否则, if this object was destroyed; otherwise, false.
另见: See:
性能: Performance:
Calling remove 是预期的常数时间。然而,集合的顶点缓冲区被重写 is expected constant time. However, the collection's vertex buffer is rewritten - an O(n) 操作也会产生 CPU 到 GPU 的开销。为了获得最佳性能,请在调用之前删除尽可能多的点 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.
| 名称 Name | 类型 Type | 说明 Description |
|---|---|---|
pointPrimitive |
PointPrimitive | 要删除的点。 The point to remove. |
返回: Returns:
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.
示例: Example:
const p = pointPrimitives.add(...);
pointPrimitives.remove(p); // Returns true
另见: See:
性能: 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.
示例: Example:
pointPrimitives.add(...);
pointPrimitives.add(...);
pointPrimitives.removeAll();
