PolylineCollection

new Cesium.PolylineCollection(options)

一个可渲染的折线集合。


示例折线


Polylines are added and removed from the collection using PolylineCollection#add and PolylineCollection#remove.
Performance:

For best performance, prefer a few collections, each with many polylines, to many collections with only a few polylines each. Organize collections so that polylines with the same update frequency are in the same collection, i.e., polylines that do not change should be in one collection; polylines 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 仅用于调试。确定是否显示此图元命令的包围球。
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:

After calling add, PolylineCollection#update is called and the collection's vertex buffer is rewritten - an O(n) operation that also incurs CPU to GPU overhead. For best performance, add as many polylines as possible before calling 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:
返回集合中指定索引处的折线。索引从零开始, 并随折线的添加而递增。移除一条折线会将其后的所有折线向左 移动,从而改变它们的索引。此函数通常与 PolylineCollection#length 配合使用, 以遍历集合中的所有折线。
Performance:

If polylines were removed from the collection and PolylineCollection#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 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:

After calling remove, PolylineCollection#update is called and the collection's vertex buffer is rewritten - an O(n) operation that also incurs CPU to GPU overhead. For best performance, remove as many polylines as possible before calling update. If you intend to temporarily hide a polyline, it is usually more efficient to call Polyline#show instead of removing and re-adding the polyline.

Name Type Description
polyline Polyline 要移除的折线。
Returns:
如果折线已被移除则返回 true;如果在集合中未找到该折线则返回 false
Throws:
Example:
const p = polylines.add(...);
polylines.remove(p);  // Returns true
See:
从集合中移除所有折线。
Performance:

O(n). It is more efficient to remove all the polylines from a collection and then add new ones than to create a new collection entirely.

Throws:
Example:
polylines.add(...);
polylines.add(...);
polylines.removeAll();
See:
ViewerCesiumWidget 渲染场景以获取渲染此图元 所需的绘制命令时调用。

请勿直接调用此函数。此处进行说明仅是为了 列出场景渲染时可能传播的异常:

Throws:
  • RuntimeError : 渲染带有逐实例属性的图元需要顶点纹理获取支持。顶点纹理图像单元的最大数量必须大于零。
需要帮助?获取答案的最快方式是在 Cesium 论坛 上向社区和团队提问。