Performance:
为获得最佳性能,建议使用少量集合,每个集合包含多条折线,而非多个集合各包含少量折线。请将更新频率相同的折线组织在同一个集合中,即不变化的折线应放在一个集合中;每帧都变化的折线应放在另一个集合中;以此类推。
| Name | Type | Description | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
optional
包含以下属性的对象:
|
Example:
// 创建包含两条折线的折线集合
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
此属性仅用于调试,不适用于生产环境,也未经过优化。
绘制图元中每个绘制命令的包围球。
-
Default Value:
false
返回此集合中的折线数量。通常与
PolylineCollection#get 配合使用,以遍历集合中的所有折线。
modelMatrix : Matrix4
将集合中每条折线从模型坐标转换为世界坐标的 4x4 变换矩阵。
当此矩阵为单位矩阵时,折线将绘制在世界坐标中,即地球的 WGS84 坐标。
可以通过提供不同的变换矩阵来使用局部参考系,例如
Transforms.eastNorthUpToFixedFrame 返回的矩阵。
-
Default Value:
Matrix4.IDENTITY
确定是否显示此集合中的折线。
-
Default Value:
true
Methods
add(options) → Polyline
创建并将具有指定初始属性的折线添加到集合中。
返回添加的折线,以便稍后修改或从集合中移除。
Performance:
调用 add 后,会调用 PolylineCollection#update 并
重写集合的顶点缓冲区——这是一个 O(n) 操作,还会产生 CPU 到 GPU 的开销。
为获得最佳性能,请在调用 update 之前尽可能多地添加折线。
| Name | Type | Description |
|---|---|---|
options |
object | optional 描述折线属性的模板,如示例1所示。 |
Returns:
添加到集合中的折线。
Throws:
-
DeveloperError : 此对象已被销毁,即已调用 destroy()。
Example:
// 示例1:添加一条折线,指定所有默认值。
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:
确定此集合是否包含指定的折线。
| Name | Type | Description |
|---|---|---|
polyline |
Polyline | 要检查的折线。 |
Returns:
如果此集合包含该折线则返回 true,否则返回 false。
销毁此对象持有的 WebGL 资源。销毁对象可以确定性地
释放 WebGL 资源,而不是依赖垃圾回收器来销毁此对象。
一旦对象被销毁,就不应使用它;调用除
一旦对象被销毁,就不应使用它;调用除
isDestroyed 之外的任何函数都会导致 DeveloperError 异常。因此,
应像示例中那样将返回值(undefined)赋给对象。
Throws:
-
DeveloperError : 此对象已被销毁,即已调用 destroy()。
Example:
polylines = polylines && polylines.destroy();
See:
get(index) → Polyline
返回集合中指定索引处的折线。索引从零开始,
并随着折线的添加而增加。移除折线会将其后的所有折线向左移动,改变它们的索引。
此函数通常与
PolylineCollection#length 配合使用,以遍历集合中的所有折线。
Performance:
如果从集合中移除了折线且未调用
PolylineCollection#update,则会执行一个隐式的 O(n) 操作。
| Name | Type | Description |
|---|---|---|
index |
number | 折线的从零开始的索引。 |
Returns:
指定索引处的折线。
Throws:
-
DeveloperError : 此对象已被销毁,即已调用 destroy()。
Example:
// 切换集合中每条折线的 show 属性
const len = polylines.length;
for (let i = 0; i < len; ++i) {
const p = polylines.get(i);
p.show = !p.show;
}
See:
Returns:
如果此对象已被销毁则返回
true,否则返回 false。
从集合中移除一条折线。
Performance:
调用 remove 后,会调用 PolylineCollection#update 并
重写集合的顶点缓冲区——这是一个 O(n) 操作,还会产生 CPU 到 GPU 的开销。
为获得最佳性能,请在调用 update 之前尽可能多地移除折线。
如果打算临时隐藏一条折线,通常更高效的方法是调用
Polyline#show,而不是移除后重新添加折线。
| Name | Type | Description |
|---|---|---|
polyline |
Polyline | 要移除的折线。 |
Returns:
如果折线已被移除则返回
true;如果未在集合中找到折线则返回 false。
Throws:
-
DeveloperError : 此对象已被销毁,即已调用 destroy()。
Example:
const p = polylines.add(...);
polylines.remove(p); // 返回 true
See:
从集合中移除所有折线。
Performance:
O(n)。从集合中移除所有折线后再添加新折线,
比完全创建新集合更高效。
Throws:
-
DeveloperError : 此对象已被销毁,即已调用 destroy()。
Example:
polylines.add(...);
polylines.add(...);
polylines.removeAll();
See:
Throws:
-
RuntimeError : 渲染具有每实例属性的图元需要顶点纹理获取支持。顶点纹理图像单元的最大数量必须大于零。

