PolylineCollection

new Cesium.PolylineCollection(options)

多段线的可渲染集合。


多段线示例


使用 PolylineCollection#add 在集合中添加和删除折线 和 PolylineCollection#remove 的 Package。
Performance:

为了获得最佳性能,请首选几个集合,每个集合都包含许多多段线,以便 许多集合,每个集合只有几条折线。 组织集合,以便多段线 具有相同的更新频率位于同一集合中,即 更改应在一个集合中;更改每个帧的多段线应位于另一个帧中 收集;等等。

Name Type Description
options object optional 对象,具有以下属性:
Name Type Default Description
modelMatrix Matrix4 Matrix4.IDENTITY optional 将每条折线从模型转换为世界坐标的 4x4 变换矩阵。
debugShowBoundingVolume boolean false optional 仅用于调试。确定是否显示此基本体的命令的边界球体。
show boolean true optional 确定是否显示集合中的多段线。
Example:
// Create a polyline collection with two polylines
const polylines = new Cesium.PolylineCollection();
polylines.add({
  positions : Cesium.Cartesian3.fromDegreesArray([
    -75.10, 39.57,
    -77.02, 38.53,
    -80.50, 35.14,
    -80.12, 25.46]),
  width : 2
});

polylines.add({
  positions : Cesium.Cartesian3.fromDegreesArray([
    -73.10, 37.57,
    -75.02, 36.53,
    -78.50, 33.14,
    -78.12, 23.46]),
  width : 4
});
See:

Members

debugShowBoundingVolume : boolean

此属性仅用于调试;它不用于生产用途,也未进行优化。

为基元中的每个绘制命令绘制边界球体。

Default Value: false
返回此集合中的多段线数。 这通常与 PolylineCollection#get 遍历所有多段线 在集合中。
4x4 转换矩阵,用于将此集合中的每条折线从模型转换为世界坐标。 当这是单位矩阵时,折线以世界坐标(即地球的 WGS84 坐标)绘制。 可以通过提供不同的转换矩阵来使用本地参考帧,就像返回的矩阵一样 由 Transforms.eastNorthUpToFixedFrame.
Default Value: Matrix4.IDENTITY
确定是否显示此集合中的多段线。
Default Value: true

Methods

创建具有指定初始属性的多段线并将其添加到集合中。 将返回添加的多段线,以便以后可以对其进行修改或从集合中删除。
Performance:

调用 add 后,将调用 PolylineCollection#update 并 集合的顶点缓冲区被重写 - 一个 O(n) 操作,也会导致 CPU 到 GPU 的开销。 为了获得最佳性能,请在调用 update 之前添加尽可能多的多段线。

Name Type Description
options object optional 描述多段线属性的模板,如示例 1 所示。
Returns:
已添加到集合中的折线。
Throws:
Example:
// Example 1:  Add a polyline, specifying all the default values.
const p = polylines.add({
  show : true,
  positions : ellipsoid.cartographicArrayToCartesianArray([
           Cesium.Cartographic.fromDegrees(-75.10, 39.57),
           Cesium.Cartographic.fromDegrees(-77.02, 38.53)]),
  width : 1
});
See:

contains(polyline)boolean

确定此集合是否包含指定的多段线。
Name Type Description
polyline Polyline 要检查的折线。
Returns:
true(如果此集合包含折线),否则 false,。
See:
销毁此对象持有的 WebGL 资源。 销毁对象允许确定性 释放 WebGL 资源,而不是依赖垃圾回收器来销毁这个对象。

一旦对象被销毁,就不应该使用它;调用 isDestroyed 将导致 DeveloperError 异常。 因此 将返回值 (undefined) 分配给对象,如示例中所示。
Throws:
Example:
polylines = polylines && polylines.destroy();
See:
返回集合中指定索引处的折线。 索引从 0 开始 并随着多段线的添加而增加。 删除多段线将在 它向左移动,更改其索引。 此功能通常用于 PolylineCollection#length 遍历所有多段线 在集合中。
Performance:

如果从集合中删除了多段线,并且 PolylineCollection#update 未调用,则隐式 O(n) 执行操作。

Name Type Description
index number 折线的从零开始的索引。
Returns:
指定索引处的折线。
Throws:
Example:
// Toggle the show property of every polyline in the collection
const len = polylines.length;
for (let i = 0; i < len; ++i) {
  const p = polylines.get(i);
  p.show = !p.show;
}
See:
如果此对象已销毁,则返回 true;否则为 false。

如果此对象已销毁,则不应使用;调用 isDestroyed 将导致 DeveloperError 异常。
Returns:
true,如果此对象被销毁;否则为 false
See:

remove(polyline)boolean

从集合中删除多段线。
Performance:

调用 remove 后,将调用 PolylineCollection#update 并 集合的顶点缓冲区被重写 - 一个 O(n) 操作,也会导致 CPU 到 GPU 的开销。 为了获得最佳性能,请在调用 update 之前删除尽可能多的多段线。 如果您打算暂时隐藏多段线,则通常调用 Polyline#show 而不是删除并重新添加折线。

Name Type Description
polyline Polyline 要删除的折线。
Returns:
true,如果删除了折线;如果在集合中找不到折线,则为 false
Throws:
Example:
const p = polylines.add(...);
polylines.remove(p);  // Returns true
See:
从集合中删除所有多段线。
Performance:

O(n)。 删除所有多段线效率更高 从集合中,然后添加新的集合,而不是完全创建一个新集合。

Throws:
Example:
polylines.add(...);
polylines.add(...);
polylines.removeAll();
See:
ViewerCesiumWidget 将场景渲染到 获取渲染此基元所需的绘制命令。

请勿直接调用此函数。 这记录下来只是为了 列出渲染场景时可能传播的异常:

Throws:
  • RuntimeError : Vertex texture fetch support is required to render primitives with per-instance attributes. The maximum number of vertex texture image units must be greater than zero.
Need help? The fastest way to get answers is from the community and team on the Cesium Forum.