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 之前尽可能添加更多的 pointPrimitives。

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:

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

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:

调用 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:
需要帮助?获得答案的最快方法是来自社区和团队 Cesium Forum.