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.
参数名称 | 类型 | 描述信息 | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
可选
Object with the following properties:
|
使用示例:
// 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
});
参考:
成员(属性)
Draws the bounding sphere for each draw command in the primitive.
-
默认值:
false
PolylineCollection#get
to iterate over all the polylines
in the collection.
modelMatrix : Matrix4
Transforms.eastNorthUpToFixedFrame
.
-
默认值:
Matrix4.IDENTITY
-
默认值:
true
方法
add(options) → Polyline
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
.
参数名称 | 类型 | 描述信息 |
---|---|---|
options |
object | 可选 A template describing the polyline's properties as shown in Example 1. |
返回值:
Throws:
-
DeveloperError : This object was destroyed, i.e., destroy() was called.
使用示例:
// 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
});
参考:
参数名称 | 类型 | 描述信息 |
---|---|---|
polyline |
Polyline | The polyline to check for. |
返回值:
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.
使用示例:
polylines = polylines && polylines.destroy();
参考:
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.
参数名称 | 类型 | 描述信息 |
---|---|---|
index |
number | The zero-based index of the polyline. |
返回值:
Throws:
-
DeveloperError : This object was destroyed, i.e., destroy() was called.
使用示例:
// 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;
}
参考:
If this object was destroyed, it should not be used; calling any function other than
isDestroyed
will result in a DeveloperError
exception.
返回值:
true
if this object was destroyed; otherwise, false
.
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.
参数名称 | 类型 | 描述信息 |
---|---|---|
polyline |
Polyline | The polyline to remove. |
返回值:
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.
使用示例:
const p = polylines.add(...);
polylines.remove(p); // Returns true
参考:
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.
使用示例:
polylines.add(...);
polylines.add(...);
polylines.removeAll();
参考:
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.