将创建一个公告板,其初始
属性通过调用
位于 3D 场景中的与视口对齐的图像,该图像是创建的
并使用 BillboardCollection#add
. 不要直接调用构造函数。
BillboardCollection
进行渲染。

广告牌示例
Performance:
读取属性(例如 Billboard#show
)是恒定时间。
分配给属性是恒定时间,但会导致
调用 BillboardCollection#update
时的 CPU 到 GPU 流量。 每个公告牌的流量为
无论更新了多少个属性,都是相同的。 如果集合中的大多数广告牌都需要
更新,使用 BillboardCollection#removeAll
清除收藏可能会更有效。
并添加新的广告牌,而不是修改每个广告牌。
Name | Type | Description |
---|---|---|
options |
Billboard.ConstructorOptions | 描述初始化选项的对象 |
billboardCollection |
BillboardCollection | Instance of BillboardCollection |
Throws:
-
DeveloperError : scaleByDistance.far must be greater than scaleByDistance.near
-
DeveloperError : translucencyByDistance.far must be greater than translucencyByDistance.near
-
DeveloperError : pixelOffsetScaleByDistance.far must be greater than pixelOffsetScaleByDistance.near
-
DeveloperError : distanceDisplayCondition.far must be greater than distanceDisplayCondition.near
Members
alignedAxis : Cartesian3
获取或设置世界空间中的 aligned axis (对齐轴)。对齐轴是公告牌向上矢量指向的单位向量。
默认值为零矢量,这意味着公告牌与屏幕向上矢量对齐。
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;
获取或设置与 Billboard 的纹理相乘的颜色。 这有两个常见的用例。 第一
相同的白色纹理可以被许多不同的广告牌使用,每个广告牌都有不同的颜色,以创建
彩色广告牌。 其次,颜色的 Alpha 分量可用于使公告牌半透明,如下所示。
Alpha 值为
红色、绿色、蓝色和 alpha 值由
0.0
时,广告牌透明,Alpha 值为 1.0
时,广告牌不透明。
default ![]() |
alpha : 0.5 ![]() |
红色、绿色、蓝色和 alpha 值由
值的
red
、green
、
blue
和 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);
获取或设置与摄像机的距离,以禁用深度测试,以防止根据地形进行裁剪。
当设置为零时,始终应用深度测试。设置为 Number.POSITIVE_INFINITY 时,从不应用深度测试。
distanceDisplayCondition : DistanceDisplayCondition
获取或设置条件 指定此公告牌将在距离摄像机多远处显示。
-
Default Value:
undefined
eyeOffset : Cartesian3
获取或设置在眼睛坐标中应用于此广告牌的 3D 笛卡尔偏移。 眼睛坐标是左撇子
坐标系,其中
眼动偏移通常用于将多个广告牌或对象排列在同一位置,例如,将 在其相应的 3D 模型上方布置广告牌。
在下面,广告牌位于地球的中心,但眼睛偏移使其始终 显示在地球顶部,无论观看者或地球的方向如何。
x
指向查看器的右侧,y
指向上方,并且
z
指向屏幕。 眼睛坐标使用与世界和模型坐标相同的比例。
通常为 meters。
眼动偏移通常用于将多个广告牌或对象排列在同一位置,例如,将 在其相应的 3D 模型上方布置广告牌。
在下面,广告牌位于地球的中心,但眼睛偏移使其始终 显示在地球顶部,无论观看者或地球的方向如何。
![]() |
![]() |
b.eyeOffset = new Cartesian3(0.0, 8000000.0, 0.0);
获取或设置公告板的高度。如果未定义,则将使用图像高度。
heightReference : HeightReference
获取或设置高度参考。
-
Default Value:
HeightReference.NONE
horizontalOrigin : HorizontalOrigin
获取或设置此公告板的水平原点,用于确定公告板是否为
拖动到其锚点位置的左侧、中间或右侧。


Example:
// Use a bottom, left origin
b.horizontalOrigin = Cesium.HorizontalOrigin.LEFT;
b.verticalOrigin = Cesium.VerticalOrigin.BOTTOM;
获取或设置选取 Billboard 时返回的 User-defined 对象。
获取或设置图像。 如果已为 给定图像,则使用现有纹理。
此属性可以设置为加载的 Image,该 URL 将自动加载为 Image, 画布或其他 Billboard 的图像属性(来自同一 Billboard 集合)。
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;
pixelOffset : Cartesian2
获取或设置屏幕空间中与此公告牌原点的像素偏移。 这是常用的
将多个广告牌和标签对齐在同一位置,例如,图像和文本。 这
屏幕空间原点是画布的左上角;
公告牌的原点由黄点表示。
x
从
从左到右,y
从上到下增加。
default ![]() |
b.pixeloffset = new Cartesian2(50, 25); ![]() |
pixelOffsetScaleByDistance : NearFarScalar
根据公告板与摄像机的距离获取或设置公告牌的近像素偏移和远像素偏移缩放属性。
公告牌的像素偏移将在
NearFarScalar#nearValue
和
NearFarScalar#farValue
当摄像机距离落在下限和上限内时
指定的 NearFarScalar#near
和 NearFarScalar#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;
position : Cartesian3
获取或设置此广告牌的笛卡尔位置。
如果为
true
,则此公告牌已准备好进行渲染,即图像
已下载,并且 WebGL 资源已创建。
-
Default Value:
false
获取或设置旋转角度(以弧度为单位)。
获取或设置Uniform Scale (均匀缩放),乘以公告牌的图像大小(以像素为单位)。

在上图中,比例尺从左到右依次为
1.0
的比例不会改变广告牌的大小;大于
1.0
放大广告牌;小于 1.0
的正比例会收缩
广告牌。

在上图中,比例尺从左到右依次为
0.5
, 1.0
,
和 2.0
.
scaleByDistance : NearFarScalar
根据公告板与摄像机的距离获取或设置公告牌的近距和远距缩放属性。
公告牌的比例将在
NearFarScalar#nearValue
和
NearFarScalar#farValue
当摄像机距离落在下限和上限内时
指定的 NearFarScalar#near
和 NearFarScalar#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;
确定是否显示此公告牌。 使用它来隐藏或显示公告牌
将其删除并重新添加到集合中。
-
Default Value:
true
获取或设置是否公告牌大小以米或像素为单位。
true
以米为单位调整广告牌的大小;
否则,大小以像素为单位。
-
Default Value:
false
splitDirection : SplitDirection
获取或设置
SplitDirection
这个广告牌。
-
Default Value:
SplitDirection.NONE
translucencyByDistance : NearFarScalar
根据公告板与摄像机的距离获取或设置公告牌的近距和远距半透明属性。
公告牌的半透明性将在
NearFarScalar#nearValue
和 之间插值
NearFarScalar#farValue
当摄像机距离落在下限和上限内时
指定的 NearFarScalar#near
和 NearFarScalar#far
的 。
在这些范围之外,公告牌的半透明性仍然被限制在最近的边界上。 如果未定义,则
translucencyByDistance 将被禁用。
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;
verticalOrigin : VerticalOrigin
获取或设置此公告板的垂直原点,用于确定公告板是否为
拖动到其锚点位置的上方、下方或中心。


Example:
// Use a bottom, left origin
b.horizontalOrigin = Cesium.HorizontalOrigin.LEFT;
b.verticalOrigin = Cesium.VerticalOrigin.BOTTOM;
获取或设置公告板的宽度。如果未定义,则将使用图像宽度。
Methods
computeScreenSpacePosition(scene, result) → Cartesian2
计算公告牌原点的屏幕空间位置,同时考虑眼睛和像素偏移。
屏幕空间原点是画布的左上角;
x
从
从左到右,y
从上到下增加。
Name | Type | Description |
---|---|---|
scene |
Scene | 场景。 |
result |
Cartesian2 | optional 要在其上存储结果的对象。 |
Returns:
公告牌的屏幕空间位置。
Throws:
-
DeveloperError : Billboard must be in a collection.
Example:
console.log(b.computeScreenSpacePosition(scene).toString());
See:
确定此公告牌是否等于另一个公告牌。 如果广告牌都是平等的ties
相等。 不同集合中的广告牌可以相等。
Name | Type | Description |
---|---|---|
other |
Billboard | optional 要比较相等性的广告牌。 |
Returns:
如果广告牌相等,则为
true
;否则为 false
。
设置用于此公告牌的图像。 如果已为 给定 id,则使用现有纹理。
此功能可用于动态创建在多个公告牌之间共享的纹理。 只有第一个公告牌会实际调用该函数并创建纹理,而后续的 使用相同 ID 创建的公告板将简单地重复使用现有纹理。
要从 URL 加载图像,设置 Billboard#image
属性会更方便。
Name | Type | Description |
---|---|---|
id |
string | 图像的 ID。 这可以是唯一标识图像的任何字符串。 |
image |
HTMLImageElement | HTMLCanvasElement | string | Resource | Billboard.CreateImageCallback | 要加载的图像。 此参数 可以是加载的 Image 或 Canvas,一个将自动作为 Image 加载的 URL, 或将调用该函数来创建图像(如果尚未加载)。 |
Example:
// create a billboard image dynamically
function drawImage(id) {
// create and draw an image using a canvas
const canvas = document.createElement('canvas');
const 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);
使用具有给定 id 的图像子区域作为此公告牌的图像,
以左下角的像素为单位。
Name | Type | Description |
---|---|---|
id |
string | 要使用的图像的 ID。 |
subRegion |
BoundingRectangle | 图像的子区域。 |
Throws:
-
RuntimeError : image with id must be in the atlas
Type Definitions
Billboard 构造函数的第一个参数的初始化选项
Properties:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
position |
Cartesian3 | 广告牌的笛卡尔位置。 | ||
id |
* |
<optional> |
使用 Scene#pick 选取公告牌时返回的用户定义对象。 |
|
show |
boolean |
<optional> |
true | 确定是否显示此公告板。 |
image |
string | HTMLCanvasElement |
<optional> |
一个加载的 HTMLImageElement、ImageData 或用于广告牌的图像的 URL。 | |
scale |
number |
<optional> |
1.0 | 一个数字,用于指定均匀缩放比例,该比例乘以公告牌的图像大小(以像素为单位)。 |
pixelOffset |
Cartesian2 |
<optional> |
Cartesian2.ZERO | A Cartesian2 指定屏幕空间中与此广告牌原点的像素偏移量。 |
eyeOffset |
Cartesian3 |
<optional> |
Cartesian3.ZERO | A Cartesian3 指定在眼坐标中应用于此广告牌的 3D 笛卡尔偏移量。 |
horizontalOrigin |
HorizontalOrigin |
<optional> |
HorizontalOrigin.CENTER | A HorizontalOrigin 指定此广告牌的水平原点。 |
verticalOrigin |
VerticalOrigin |
<optional> |
VerticalOrigin.CENTER | A VerticalOrigin 指定此广告牌的垂直原点。 |
heightReference |
HeightReference |
<optional> |
HeightReference.NONE | A HeightReference 指定此公告牌的高度参考。 |
color |
Color |
<optional> |
Color.WHITE | A Color 指定与公告牌纹理相乘的颜色。 |
rotation |
number |
<optional> |
0 | 一个数字,指定以弧度为单位的旋转角度。 |
alignedAxis |
Cartesian3 |
<optional> |
Cartesian3.ZERO | A Cartesian3 指定世界空间中对齐的轴。 |
sizeInMeters |
boolean |
<optional> |
一个布尔值,指定广告牌的大小是以米为单位还是以像素为单位。 | |
width |
number |
<optional> |
指定公告牌宽度的数字。如果未定义,则将使用图像宽度。 | |
height |
number |
<optional> |
指定公告牌高度的数字。如果未定义,则将使用图像高度。 | |
scaleByDistance |
NearFarScalar |
<optional> |
A NearFarScalar 根据公告牌与摄像机的距离指定公告牌的近距和远距缩放属性。 |
|
translucencyByDistance |
NearFarScalar |
<optional> |
A NearFarScalar 根据公告牌与摄像机的距离指定公告牌的近距和远距半透明属性。 |
|
pixelOffsetScaleByDistance |
NearFarScalar |
<optional> |
A NearFarScalar 根据公告牌与摄像机的距离指定公告牌的近距和远距像素偏移缩放属性。 |
|
imageSubRegion |
BoundingRectangle |
<optional> |
A BoundingRectangle 指定要用于公告牌的图像子区域,而不是整个图像。 |
|
distanceDisplayCondition |
DistanceDisplayCondition |
<optional> |
A DistanceDisplayCondition 指定显示此公告牌的摄像机的距离。 |
|
disableDepthTestDistance |
number |
<optional> |
一个数字,用于指定与摄像机的距离,在该距离处禁用深度测试,例如,防止针对地形进行裁剪。 | |
splitDirection |
SplitDirection |
<optional> |
A SplitDirection 指定公告牌的 split 属性。 |
Cesium.Billboard.CreateImageCallback(id) → HTMLImageElement|HTMLCanvasElement|Promise.<(HTMLImageElement|HTMLCanvasElement)>
创建图像的函数。
Name | Type | Description |
---|---|---|
id |
string | 要加载的图像的标识符。 |
Returns:
镜像或将解析为镜像的 Promise。