GroundPolylinePrimitive

new Cesium.GroundPolylinePrimitive(options)

GroundPolylinePrimitive 表示在 Scene 中的地形或 3D Tiles 上覆盖的折线。

仅可与包含 GroundPolylineGeometry 的 GeometryInstances 配合使用。

Name Type Description
options object optional 包含以下属性的对象:
Name Type Default Description
geometryInstances Array | GeometryInstance optional 包含 GroundPolylineGeometry 的 GeometryInstances
appearance Appearance optional 用于渲染折线的外观。默认使用 PolylineMaterialAppearance 上的白色 Material
show boolean true optional 确定是否显示此图元。
interleave boolean false optionaltrue 时,几何体顶点属性会交错存储,可略微提升渲染性能但会增加加载时间。
releaseGeometryInstances boolean true optionaltrue 时,图元不会保留输入 geometryInstances 的引用以节省内存。
allowPicking boolean true optionaltrue 时,每个几何体实例仅可通过 Scene#pick 拾取。当 false 时,可节省 GPU 内存。
asynchronous boolean true optional 确定图元是异步创建还是阻塞直到准备就绪。若为 false,必须先调用 initializeTerrainHeights()。
classificationType ClassificationType ClassificationType.BOTH optional 确定对地形、3D Tiles 还是两者进行分类。
debugShowBoundingVolume boolean false optional 仅用于调试。确定是否显示此图元命令的包围球。
debugShowShadowVolume boolean false optional 仅用于调试。确定是否绘制图元中每个几何体的阴影体。必须在创建时设为 true 才会生效。
Example:
// 1. Draw a polyline on terrain with a basic color material

const instance = new Cesium.GeometryInstance({
  geometry : new Cesium.GroundPolylineGeometry({
     positions : Cesium.Cartesian3.fromDegreesArray([
         -112.1340164450331, 36.05494287836128,
         -112.08821010582645, 36.097804071380715
     ]),
     width : 4.0
  }),
  id : 'object returned when this instance is picked and to get/set per-instance attributes'
});

scene.groundPrimitives.add(new Cesium.GroundPolylinePrimitive({
  geometryInstances : instance,
  appearance : new Cesium.PolylineMaterialAppearance()
}));

// 2. Draw a looped polyline on terrain with per-instance color and a distance display condition.
// Distance display conditions for polylines on terrain are based on an approximate terrain height
// instead of true terrain height.

const instance2 = new Cesium.GeometryInstance({
  geometry : new Cesium.GroundPolylineGeometry({
     positions : Cesium.Cartesian3.fromDegreesArray([
         -112.1340164450331, 36.05494287836128,
         -112.08821010582645, 36.097804071380715,
         -112.13296079730024, 36.168769146801104
     ]),
     loop : true,
     width : 4.0
  }),
  attributes : {
     color : Cesium.ColorGeometryInstanceAttribute.fromColor(Cesium.Color.fromCssColorString('green').withAlpha(0.7)),
     distanceDisplayCondition : new Cesium.DistanceDisplayConditionGeometryInstanceAttribute(1000, 30000)
  },
  id : 'object returned when this instance is picked and to get/set per-instance attributes'
});

scene.groundPrimitives.add(new Cesium.GroundPolylinePrimitive({
  geometryInstances : instance2,
  appearance : new Cesium.PolylineColorAppearance()
}));

Members

readonly allowPicking : boolean

true 时,每个几何体实例仅可通过 Scene#pick 拾取。当 false 时,可节省 GPU 内存。
Default Value: true
用于着色此图元的 Appearance。每个几何体实例 使用相同的外观进行着色。某些外观(如 PolylineColorAppearance)允许为每个实例指定独特的属性。
Default Value: undefined

readonly asynchronous : boolean

确定几何体实例是否将在 Web Worker 上创建和批处理。
Default Value: true
确定对地形、3D Tiles 还是两者进行分类。
Default Value: ClassificationType.BOTH

debugShowBoundingVolume : boolean

此属性仅用于调试,不适用于生产环境,也未经过优化。

绘制图元中每个绘制命令的包围球。

Default Value: false

readonly debugShowShadowVolume : boolean

此属性仅用于调试,不适用于生产环境,也未经过优化。

如果为 true,绘制图元中每个几何体的阴影体。

Default Value: false
使用此图元渲染的几何体实例。如果在构造图元时 options.releaseGeometryInstancestrue,则此属性可能为 undefined

在图元渲染后更改此属性无效。

Default Value: undefined
确定几何体顶点属性是否交错存储,这可略微提升渲染性能。
Default Value: false
确定图元是否已完成并准备好渲染。如果此属性为 true,则图元将在下次调用 GroundPolylinePrimitive#update 时进行渲染。

readonly releaseGeometryInstances : boolean

true 时,图元不会保留输入 geometryInstances 的引用以节省内存。
Default Value: true
确定是否显示此图元。这会影响图元中的所有几何体实例。
Default Value: true

Methods

static Cesium.GroundPolylinePrimitive.initializeTerrainHeights()Promise.<void>

初始化地形最小和最大高度。仅当同步创建 GroundPolylinePrimitive 时需要调用此方法。
Returns:
当地形高度加载完成后将解析的 Promise。

static Cesium.GroundPolylinePrimitive.isSupported(scene)boolean

检查给定的 Scene 是否支持 GroundPolylinePrimitives。 GroundPolylinePrimitives 需要支持 WEBGL_depth_texture 扩展。
Name Type Description
scene Scene 当前场景。
Returns:
当前场景是否支持 GroundPolylinePrimitives。
销毁此对象持有的 WebGL 资源。销毁对象可以实现确定性地 释放 WebGL 资源,而不是依赖垃圾回收器来销毁此对象。

对象一旦被销毁,就不应再使用;调用除 isDestroyed 之外的任何函数都将导致 DeveloperError 异常。因此, 应像示例中那样将返回值(undefined)赋给该对象。

Throws:
Example:
e = e && e.destroy();
See:

getGeometryInstanceAttributes(id)object

返回 GeometryInstance 的可修改的逐实例属性。
Name Type Description
id * GeometryInstance 的 id。
Returns:
属性格式的类型化数组,如果没有对应 id 的实例则返回 undefined。
Throws:
  • DeveloperError : 调用 getGeometryInstanceAttributes 之前必须先调用 update。
Example:
const attributes = primitive.getGeometryInstanceAttributes('an id');
attributes.color = Cesium.ColorGeometryInstanceAttribute.toValue(Cesium.Color.AQUA);
attributes.show = Cesium.ShowGeometryInstanceAttribute.toValue(true);
如果此对象已被销毁则返回 true,否则返回 false。

如果此对象已被销毁,则不应再使用它;调用除 isDestroyed 之外的任何函数都将导致 DeveloperError 异常。

Returns:
如果此对象已被销毁则返回 true,否则返回 false
See:
ViewerCesiumWidget 渲染场景时调用, 以获取渲染此图元所需的绘制命令。

请勿直接调用此函数。此处记录仅为 列出场景渲染时可能传播的异常:

Throws:
  • DeveloperError : 对于同步的 GroundPolylinePrimitives,必须调用 GroundPolylinePrimitives.initializeTerrainHeights() 并等待返回的 Promise 解析。
  • DeveloperError : 所有 GeometryInstances 必须具有颜色属性才能将 PolylineColorAppearance 与 GroundPolylinePrimitive 配合使用。
Need help? The fastest way to get answers is from the community and team on the Cesium Forum.