PointPrimitiveCollection

new Cesium.PointPrimitiveCollection(options)

可渲染的点集合。

使用 PointPrimitiveCollection#addPointPrimitiveCollection#remove 向集合中添加或移除点。
Performance:

为获得最佳性能,建议使用少量集合(每个集合包含大量点),而非大量仅包含少量点的集合。请按更新频率组织集合:即不变化的点放在一个集合,每帧变化的点放在另一个集合,以此类推。

Name Type Description
options object optional 包含以下属性的对象:
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变换矩阵。 当使用单位矩阵时,点图元将在世界坐标(即地球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:

调用add的时间复杂度为常数级。但集合的顶点缓冲区会被重写——这是一个O(n)操作,同时会产生CPU到GPU的开销。为获得最佳性能,请在调用update之前尽可能添加多个点。

Name Type Description
options object optional 描述点属性的模板,如示例1所示。
Returns:
添加到集合中的点。
Throws:
Examples:
// 示例1:添加一个点,指定所有默认值。
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
});
// 示例2:仅指定点的地理坐标位置。
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:

预期为常数时间。如果从集合中移除了点且未调用PointPrimitiveCollection#update,则会执行一个隐式的O(n)操作。

Name Type Description
index number 点的从零开始的索引。
Returns:
指定索引处的点。
Throws:
Example:
// 切换集合中每个点的show属性
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:

调用remove的时间复杂度为常数级。但集合的顶点缓冲区会被重写——这是一个O(n)操作,同时会产生CPU到GPU的开销。为获得最佳性能,请在调用update之前尽可能移除多个点。 如果目的是临时隐藏一个点,通常调用PointPrimitive#show比移除再重新添加点更高效。

Name Type Description
pointPrimitive PointPrimitive 要移除的点。
Returns:
如果点被移除则返回true;如果未在集合中找到该点则返回false
Throws:
Example:
const p = pointPrimitives.add(...);
pointPrimitives.remove(p);  // Returns true
See:
移除集合中的所有点。
Performance:

O(n)。从集合中移除所有点再添加新点,比完全创建新集合更高效。

Throws:
Example:
pointPrimitives.add(...);
pointPrimitives.add(...);
pointPrimitives.removeAll();
See:
Need help? The fastest way to get answers is from the community and team on the Cesium Forum.