Billboard

new Cesium.Billboard()



在3D场景中定位的视口对齐图像,即 并使用BillboardCollection进行渲染。创建了一个广告牌,其初始 属性通过调用BillboardCollection#add设置。

Example billboards
Performance:

读取属性(例如Billboard#show)是恒定时间。 为属性赋值是恒定时间,但会导致 调用BillboardCollection#update时CPU到GPU的流量。每个广告牌的流量是 不管更新了多少属性,都是一样的。如果一个集合中的大多数广告牌需要 更新后,使用BillboardCollection#removeAll清除集合可能更有效 增加新的广告牌,而不是修改每一个。

Throws:
  • DeveloperError : 缩放距离.far必须大于scaleByDistance.近
  • DeveloperError :translucencyByDistance.far公司必须大于translucencyByDistance.近
  • DeveloperError :像素ffsetScaleByDistance.far距离必须大于pixelOffsetScaleByDistance.近
  • DeveloperError :距离取消显示条件.far必须大于距离取消显示条件。接近
Demo:
See:

Members

获取或设置世界空间中的对齐轴。对齐轴是公告牌向上向量指向的单位向量。 默认值是零向量,这意味着广告牌与屏幕上方向向量对齐。
Examples:
// Example 1.
// Have the billboard up vector point north
billboard.alignedAxis = Cesium.Cartesian3.UNIT_Z;
// Example 2.
// Have the billboard point east.
billboard.alignedAxis = Cesium.Cartesian3.UNIT_Z;
billboard.rotation = -Cesium.Math.PI_OVER_TWO;
// Example 3.
// Reset the aligned axis
billboard.alignedAxis = Cesium.Cartesian3.ZERO;



获取或设置与公告牌纹理相乘的颜色。这有两个常见的用例。第一, 相同的白色纹理可能会被许多不同的广告牌使用,每一个都有不同的颜色,以创造 COLred广告牌。其次,颜色的alpha成分可以用来使广告牌半透明,如下所示。 0.0的alpha使公告牌透明,而1.0使公告牌不透明。
default
alpha : 0.5
红色、greenblue和alpha value由值的红色、绿色表示, 蓝色和alpha属性,如示例1所示。这些部件的范围为0.0 (无强度)至1.0(全强度)。
Examples:
// Example 1. Assign yellow.
b.color = Cesium.Color.YELLOW;
// Example 2. Make a billboard 50% translucent.
b.color = new Cesium.Color(1.0, 1.0, 1.0, 0.5);

disableDepthTestDistance : Number

获取或设置与摄影机的距离,在该距离处禁用深度测试,以防止针对地形进行剪裁。 设置为零时,始终应用深度测试。设置为时数正无穷大,则不应用深度测试。
获取或设置一个条件,该条件指定此公告牌将在距摄影机的距离处显示。
Default Value: undefined






获取或设置应用于eye坐标的三维笛卡尔偏移量。眼睛坐标是左手的 坐标系,其中x指向观看者的右侧,y指向上,并且 z指向屏幕。眼睛坐标使用与世界坐标和模型坐标相同的比例, 通常是米。 眼偏移通常用于在同一位置排列多个广告牌或物体,例如 在相应的三维模型上方放置一个广告牌。 下面,广告牌被定位在地球的中心,但眼睛的偏移使它总是 无论观测者或地球的方位如何,都会出现在地球的顶部。
b.eyeOffset = new Cartesian3(0.0, 8000000.0, 0.0);

height : Number

获取或设置广告牌的高度。如果未定义,将使用图像高度。
获取或设置此公告牌的高度引用。
Default Value: HeightReference.NONE


获取或设置此公告牌的水平原点,它确定公告牌是否 在其锚定位置的左侧、中心或右侧。

Example:
// Use a bottom, left origin
b.horizontalOrigin = Cesium.HorizontalOrigin.LEFT;
b.verticalOrigin = Cesium.VerticalOrigin.BOTTOM;
获取或设置拾取公告牌时返回的用户定义对象。

image : String

Gets or sets the image to be used for this billboard. If a texture has already been created for the given image, the existing texture is used.

This property can be set to a loaded Image, a URL which will be loaded as an Image automatically, a canvas, or another billboard's image property (from the same billboard collection).

Example:
// load an image from a URL
b.image = 'some/image/url.png';

// assuming b1 and b2 are billboards in the same billboard collection,
// use the same image for both billboards.
b2.image = b1.image;


获取或设置屏幕空间中距此公告牌原点的pixel偏移量。这是常见的y 在同一位置对齐多个广告牌和标签,如图像和文本。这个 屏幕空间原点是画布的左上角;x从 从右到下,从右到下依次递增。
default
b.pixeloffset = new Cartesian2(50, 25);
The billboard's origin is indicated by the yellow point.

pixelOffsetScaleByDistance : NearFarScalar

获取或设置基于广告牌与摄影机的距离的广告牌的近像素和远像素偏移缩放属性。 广告牌的像素偏移将在NearFarScalar#nearValueNearFarScalar#farValue,摄像机距离在上下限范围内 指定的NearFarScalar#nearNearFarScalar#far。 在这些范围之外,公告牌的像素偏移比例保持在最近的边界。如果未定义, pixelOffsetScaleByDistance将被禁用。
Examples:
// Example 1.
// Set a billboard's pixel offset scale to 0.0 when the
// camera is 1500 meters from the billboard and scale pixel offset to 10.0 pixels
// in the y direction the camera distance approaches 8.0e6 meters.
b.pixelOffset = new Cesium.Cartesian2(0.0, 1.0);
b.pixelOffsetScaleByDistance = new Cesium.NearFarScalar(1.5e2, 0.0, 8.0e6, 10.0);
// Example 2.
// disable pixel offset by distance
b.pixelOffsetScaleByDistance = undefined;
获取或设置此公告牌的笛卡尔位置。

readonly ready : Boolean

true时,此公告牌已准备好渲染,即图像 已下载并创建WebGL资源。
Default Value: false

rotation : Number

获取或设置以弧度为单位的旋转角度。

scale : Number



获取或设置与公告牌的图像大小(以像素为单位)相乘的统一比例。 比例尺1.0不会改变广告牌的大小;比例尺大于 1.0放大广告牌;小于1.0的正比例缩小 广告牌。

From left to right in the above image, the scales are 0.5, 1.0, and 2.0.
获取或设置基于公告牌与摄影机的距离的公告牌的近缩放和远缩放属性。 广告牌的比例尺将在NearFarScalar#nearValueNearFarScalar#farValue,摄像机距离在上下限范围内 指定的NearFarScalar#nearNearFarScalar#far。 在这些范围之外,广告牌的刻度保持在最近的范围内。如果未定义, scaleByDistance将被禁用。
Examples:
// Example 1.
// Set a billboard's scaleByDistance to scale by 1.5 when the
// camera is 1500 meters from the billboard and disappear as
// the camera distance approaches 8.0e6 meters.
b.scaleByDistance = new Cesium.NearFarScalar(1.5e2, 1.5, 8.0e6, 0.0);
// Example 2.
// disable scaling by distance
b.scaleByDistance = undefined;

show : Boolean

确定是否显示此公告牌。用这个来隐藏或显示广告牌 删除并重新添加到集合中。
Default Value: true

sizeInMeters : Boolean

获取或设置公告牌大小是否以米或像素为单位。true以米为单位调整广告牌的尺寸; 否则,大小以像素为单位。
Default Value: false

translucencyByDistance : NearFarScalar

获取或设置基于广告牌到摄影机的距离的公告牌的近半透明和远半透明属性。 广告牌的半透明性将在NearFarScalar#nearValueNearFarScalar#farValue,摄像机距离在上下限范围内 指定的NearFarScalar#nearNearFarScalar#far。 在这些范围之外,广告牌的半透明性保持在最近的边界。如果未定义, 半透明ByDistance将被禁用。
Examples:
// Example 1.
// Set a billboard's translucency to 1.0 when the
// camera is 1500 meters from the billboard and disappear as
// the camera distance approaches 8.0e6 meters.
b.translucencyByDistance = new Cesium.NearFarScalar(1.5e2, 1.0, 8.0e6, 0.0);
// Example 2.
// disable translucency by distance
b.translucencyByDistance = undefined;


获取或设置此公告牌的垂直原点,它确定公告牌是否 在其锚位置的上方、下方或中心。

Example:
// Use a bottom, left origin
b.horizontalOrigin = Cesium.HorizontalOrigin.LEFT;
b.verticalOrigin = Cesium.VerticalOrigin.BOTTOM;

width : Number

获取或设置公告牌的宽度。如果未定义,将使用图像宽度。

Methods

computeScreenSpacePosition(scene, result)Cartesian2

计算广告牌原点的屏幕空间位置,同时考虑Ey6E和pixel偏移。 屏幕空间原点是画布的左上角;x从 从右到下,从右到下依次递增。
Name Type Description
scene Scene 现场。
result Cartesian2 optional 要将结果存储到的对象。
Returns:
广告牌的屏幕空间位置。
Throws:
Example:
console.log(b.computeScreenSpacePosition(scene).toString());
See:

equals(other)Boolean

确定此公告牌是否等于另一个公告牌。如果广告牌的所有属性都相同 是平等的。不同集合的广告牌可以相等。
Name Type Description
other Billboard 比较平等的广告牌。
Returns:
如果广告牌相等,则为true;否则为false

setImage(id, image)

Sets the image to be used for this billboard. If a texture has already been created for the given id, the existing texture is used.

This function is useful for dynamically creating textures that are shared across many billboards. Only the first billboard will actually call the function and create the texture, while subsequent billboards created with the same id will simply re-use the existing texture.

To load an image from a URL, setting the Billboard#image property is more convenient.

Name Type Description
id String 图像的id。这可以是唯一标识图像的任何字符串。
image HTMLImageElement | HTMLCanvasElement | String | Resource | Billboard.CreateImageCallback 要加载的图像。此参数 可以是加载的图像,也可以是画布,URL将作为图像自动加载, 或者调用一个函数来创建图像,如果它还没有加载。
Example:
// create a billboard image dynamically
function drawImage(id) {
  // create and draw an image using a canvas
  var canvas = document.createElement('canvas');
  var context2D = canvas.getContext('2d');
  // ... draw image
  return canvas;
}
// drawImage will be called to create the texture
b.setImage('myImage', drawImage);

// subsequent billboards created in the same collection using the same id will use the existing
// texture, without the need to create the canvas or draw the image
b2.setImage('myImage', drawImage);

setImageSubRegion(id, subRegion)

使用具有给定id的图像的子区域作为此公告牌的图像, 从左下角开始以像素为单位测量。
Name Type Description
id String 要使用的映像的id。
subRegion BoundingRectangle 图像的子区域。
Throws:

Type Definitions

Cesium.Billboard.CreateImageCallback(id)HTMLImageElement|HTMLCanvasElement|Promise.<(HTMLImageElement|HTMLCanvasElement)>

创建图像的函数。
Name Type Description
id String 要加载的图像的标识符。
Returns:
形象,或承诺,将解决一个形象。