Performance:
为了获得最佳性能,请首选几个集合,每个集合都包含许多多段线,以便 许多集合,每个集合只有几条折线。 组织集合,以便多段线 具有相同的更新频率位于同一集合中,即 更改应在一个集合中;更改每个帧的多段线应位于另一个帧中 收集;等等。
Name | Type | Description | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
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
此属性仅用于调试;它不用于生产用途,也未进行优化。
为基元中的每个绘制命令绘制边界球体。
-
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:
// 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:
确定此集合是否包含指定的多段线。
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
返回集合中指定索引处的折线。 索引从 0 开始
并随着多段线的添加而增加。 删除多段线将在
它向左移动,更改其索引。 此功能通常用于
PolylineCollection#length
遍历所有多段线
在集合中。
Performance:
如果从集合中删除了多段线,并且
PolylineCollection#update
未调用,则隐式 O(n)
执行操作。
Name | Type | Description |
---|---|---|
index |
number | 折线的从零开始的索引。 |
Returns:
指定索引处的折线。
Throws:
-
DeveloperError : 这个物体被摧毁了,destroy().
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:
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); // Returns true
See:
从集合中删除所有多段线。
Performance:
O(n)。
删除所有多段线效率更高
从集合中,然后添加新的集合,而不是完全创建一个新集合。
Throws:
-
DeveloperError : 这个物体被摧毁了,destroy().
Example:
polylines.add(...);
polylines.add(...);
polylines.removeAll();
See:
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.