
折线示例 Example polylines
使用以下命令在集合中添加和删除多段线 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:
|
示例: 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
Draws the bounding sphere for each draw command in the primitive.
-
默认值: Default Value:
false
PolylineCollection#get 迭代集合中的所有折线。 to iterate over all the polylines in the collection.
modelMatrix : Matrix4
Transforms.eastNorthUpToFixedFrame.
-
默认值: Default Value:
Matrix4.IDENTITY
-
默认值: Default Value:
true
方法 Methods
add(options) → Polyline
性能: Performance:
打电话后 After calling add, PolylineCollection#update 被调用并且集合的顶点缓冲区被重写 is called and the collection's vertex buffer is rewritten - an O(n) 操作也会产生 CPU 到 GPU 的开销。为了获得最佳性能,请在调用之前添加尽可能多的折线 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 所示。 A template describing the polyline's properties as shown in Example 1. |
返回: Returns:
抛出: Throws:
-
DeveloperError : This object was destroyed, i.e., destroy() was called.
示例: 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 | 要检查的折线。 The polyline to check for. |
返回: Returns:
另见: See:
一旦对象被销毁,就不应再使用;调用除 Once an object is destroyed, it should not be used; calling any function other than
isDestroyed 将导致 will result in a DeveloperError 例外。因此,分配返回值( exception. Therefore, assign the return value (undefined) 到对象,如示例中所做的那样。 ) to the object as done in the example.
抛出: Throws:
-
DeveloperError : This object was destroyed, i.e., destroy() was called.
示例: Example:
polylines = polylines && polylines.destroy();
另见: See:
get(index) → Polyline
PolylineCollection#length 迭代集合中的所有折线。 to iterate over all the polylines in the collection.
性能: 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 | 折线的从零开始的索引。 The zero-based index of the polyline. |
返回: Returns:
抛出: Throws:
-
DeveloperError : This object was destroyed, i.e., destroy() was called.
示例: 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:
如果该对象被破坏,则不应使用它;调用除 If this object was destroyed, it should not be used; calling any function other than
isDestroyed 将导致 will result in a DeveloperError exception.
返回: Returns:
true 如果该物体被摧毁;否则, if this object was destroyed; otherwise, false.
另见: See:
性能: Performance:
打电话后 After calling remove, PolylineCollection#update 被调用并且集合的顶点缓冲区被重写 is called and the collection's vertex buffer is rewritten - an O(n) 操作也会产生 CPU 到 GPU 的开销。为了获得最佳性能,请在调用之前删除尽可能多的折线 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 | 要删除的折线。 The polyline to remove. |
返回: Returns:
true 如果折线被删除; if the polyline was removed; false 如果在集合中未找到折线。 if the polyline was not found in the collection.
抛出: Throws:
-
DeveloperError : This object was destroyed, i.e., destroy() was called.
示例: 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:
-
DeveloperError : This object was destroyed, i.e., destroy() was called.
示例: Example:
polylines.add(...);
polylines.add(...);
polylines.removeAll();
另见: See:
Viewer or CesiumWidget 渲染场景以获取渲染此图元所需的绘制命令。 render the scene to get the draw commands needed to render this primitive.
不要直接调用该函数。记录此内容只是为了列出渲染场景时可能传播的异常: Do not call this function directly. This is documented just to list the exceptions that may be propagated when the scene is rendered:
抛出: 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.
