PointPrimitiveCollection

new Cesium.PointPrimitiveCollection(options)

一个可渲染的点集合。

通过 PointPrimitiveCollection#addPointPrimitiveCollection#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:
Name Type Default Description
modelMatrix Matrix4 Matrix4.IDENTITY optional 将每个点从模型坐标变换到世界坐标的 4x4 变换矩阵。
debugShowBoundingVolume boolean false optional 仅用于调试。确定是否显示此图元命令的包围球。
blendOption BlendOption BlendOption.OPAQUE_AND_TRANSLUCENT optional 点的混合选项。默认值用于同时渲染不透明和半透明的点。然而,如果所有点都完全不透明或都完全半透明, 将技术设置为 BlendOption.OPAQUE 或 BlendOption.TRANSLUCENT 可将性能提升多达 2 倍。
show boolean true optional 确定集合中的图元是否显示。
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

点的混合选项。默认的混合选项用于同时渲染不透明和半透明的点。 然而,如果所有点都完全不透明或都完全半透明, 将技术设置为 BlendOption.OPAQUE 或 BlendOption.TRANSLUCENT 可将性能提升 多达 2 倍。
Default Value: BlendOption.OPAQUE_AND_TRANSLUCENT

debugShowBoundingVolume : boolean

此属性仅用于调试,不可用于生产环境,也未经过优化。

绘制该图元中每个绘制命令的包围球。

Default Value: false
返回此集合中的点数。它通常与 PointPrimitiveCollection#get 配合使用, 以遍历集合中的所有点。
将本集合中每个点从模型坐标变换到世界坐标的 4x4 变换矩阵。 当其为单位矩阵时,pointPrimitives 将在世界坐标(即地球的 WGS84 坐标)下绘制。 通过提供一个不同的变换矩阵(例如 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) 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 所示。
Returns:
被添加到集合中的点。
Throws:
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:

contains(pointPrimitive)boolean

检查此集合是否包含给定的点。
Name Type Description
pointPrimitive PointPrimitive optional 要检查的点。
Returns:
如果此集合包含该点则返回 true,否则返回 false。
See:
销毁此对象所持有的 WebGL 资源。销毁对象可以实现 WebGL 资源的确定性 释放,而不必依赖垃圾回收器来销毁该对象。

对象一旦被销毁便不应再使用;调用除 isDestroyed 以外的任何函数都会引发 DeveloperError 异常。因此, 请像示例中那样将返回值(undefined)赋给该对象。
Throws:
Example:
pointPrimitives = pointPrimitives && pointPrimitives.destroy();
See:
返回集合中指定索引处的点。索引从零开始, 并随点的添加而递增。移除一个点会将其后的所有点向左 移动,从而改变它们的索引。此函数通常与 PointPrimitiveCollection#length 配合使用, 以遍历集合中的所有点。
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 点的从零开始的索引。
Returns:
指定索引处的点。
Throws:
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:
如果此对象已被销毁则返回 true,否则返回 false。

如果此对象已被销毁,则不应再使用;调用除 isDestroyed 以外的任何函数都会引发 DeveloperError 异常。
Returns:
如果此对象已被销毁则返回 true,否则返回 false
See:

remove(pointPrimitive)boolean

从集合中移除一个点。
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.

Name Type Description
pointPrimitive PointPrimitive 要移除的点。
Returns:
如果点已被移除则返回 true;如果在集合中未找到该点则返回 false
Throws:
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:
Example:
pointPrimitives.add(...);
pointPrimitives.add(...);
pointPrimitives.removeAll();
See:
需要帮助?获取答案的最快方式是在 Cesium 论坛 上向社区和团队提问。