new Cesium.LabelCollection(options)

一套可行的标签集。 标签是位于3D场景的视图-对齐文本. 每个标签可以有不同的字体,颜色,比例等.


Example labels


Labels are added and removed from the collection using LabelCollection#addLabelCollection#remove .
Performance:

For best performance, prefer a few collections, each with many labels, to 许多收藏,每个只有几个标签. 避免收藏一些 标签更改每个框架, 其它框架不更改; 相反, 创建一个或多个收藏 用于静态标签,以及用于动态标签的一个或多个集合.

Name Type Description
options object optional 下列属性的对象 :
Name Type Default Description
modelMatrix Matrix4 Matrix4.IDENTITY optional The 4x4 transformation matrix that transforms each label from model to world coordinates.
debugShowBoundingVolume boolean false optional For debugging only. Determines if this primitive's commands' bounding spheres are shown.
scene Scene optional 对于使用高度参考属性的标签, 或将针对地球进行深度测试的标签, 必须经过 .
blendOption BlendOption BlendOption.OPAQUE_AND_TRANSLUCENT optional The label blending option. The default 用于渲染不透明标签和透明标签。 但是,如果任何一种标签都是完全不透明的或者所有标签都是完全透明的, 将技术设置为 BlendOption.OPAQUE 或 BlendOption.TRANSLUCENT ,可以提高性能最多2×.
show boolean true optional Determines if the labels in the collection will be shown.
coarseDepthTestDistance number optional The distance from the camera, beyond which, labels are depth-tested against an approximation of the globe ellipsoid rather than against the full globe depth buffer. If unspecified, the default value is determined relative to the value of Ellipsoid.default.
threePointDepthTestDistance number optional The distance from the camera, within which, lables with a Label#heightReference value of HeightReference.CLAMP_TO_GROUND or HeightReference.CLAMP_TO_TERRAIN are depth tested against three key points. This ensures that if any key point of the label is visible, the whole label will be visible. If unspecified, the default value is determined relative to the value of Ellipsoid.default.
Example:
// Create a label collection with two labels
const labels = scene.primitives.add(new Cesium.LabelCollection());
labels.add({
  position : new Cesium.Cartesian3(1.0, 2.0, 3.0),
  text : 'A label'
});
labels.add({
  position : new Cesium.Cartesian3(4.0, 5.0, 6.0),
  text : 'Another label'
});
Demo:
See:

Members

blendOption : BlendOption

标签混合选项 。 默认用于渲染不透明标签和透明标签. 但是,如果任何一种标签都是完全不透明的或者所有标签都是完全透明的, 将技术设置为 NT 0 或 NT 1 可以改进 最多2x的表演.
Default Value: -NT=0=- 翻译:

coarseDepthTestDistance : number

距离照相机的距离,超过这个距离,标签会针对近似值进行深度测试 地球椭圆,而不是与全地球深度缓冲。 当设定为 NT 0 0 NT 1 时 通常采用近似深度测试。 当设定为 NT 时 从未应用过近似深度测试 .

This setting only applies when a label's Label#disableDepthTestDistance value would otherwise allow depth testing—i.e., distance from the camera to the label is less than the label's Label#disableDepthTestDistance value.

debugShowBoundingVolume : boolean

此属性仅用于调试;不用于生产,也不优化.

绘制原始中每个绘图命令的边框.

Default Value: false

readonly length : number

返回此收藏中的标签数 。 这通常用于 LabelCollection#get to iterate over all the labels 在收藏中.

modelMatrix : Matrix4

4x4变换矩阵将本集中的每个标签从模型变为世界坐标. 当这是身份矩阵时,这些标签会绘制在世界坐标, i.e .,地球的 WGS84 坐标. 本地参考框架可以通过提供不同的变换矩阵来使用, 如返回的变换矩阵 by Transforms.eastNorthUpToFixedFrame.
Default Value: Matrix4.IDENTITY
Example:
const center = Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883);
labels.modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(center);
labels.add({
  position : new Cesium.Cartesian3(0.0, 0.0, 0.0),
  text     : 'Center'
});
labels.add({
  position : new Cesium.Cartesian3(1000000.0, 0.0, 0.0),
  text     : 'East'
});
labels.add({
  position : new Cesium.Cartesian3(0.0, 1000000.0, 0.0),
  text     : 'North'
});
labels.add({
  position : new Cesium.Cartesian3(0.0, 0.0, 1000000.0),
  text     : 'Up'
});

show : boolean

确定是否在此收藏中显示标签 .
Default Value: true

threePointDepthTestDistance : number

The distance from the camera, within which, labels with a Label#heightReference value of HeightReference.CLAMP_TO_GROUND or HeightReference.CLAMP_TO_TERRAIN are depth tested 对三个关键点。 这将确保如果标签的任何关键点可见,则整个 标签将可见。 当设定为 NT 0 0 NT 1 时,此特性已禁用,并部分为 a 将地形后面的标签剪切.

This setting only applies when a labels's Label#disableDepthTestDistance value would otherwise allow depth testing—i.e., distance from the camera to the label is less than the labels's Label#disableDepthTestDistance value.
See:

Methods

add(options)Label

在收藏中创建和添加带有指定初始属性的标签. 添加的标签被返回,以便日后可以修改或从收藏中移除.
Performance:

Calling add is expected constant time. However, the collection's vertex buffer 正在重写; 此操作为 NT 0 O( n) NT 1 , 并发生 CPU to GPU overhead. For best performance, add as many billboards as possible before calling update.

Name Type Description
options Label.ConstructorOptions optional 例1所示描述标签属性的模板.
Returns:
收藏中加入的标签.
Throws:
  • DeveloperError : This object was destroyed, i.e., destroy() was called.
Examples:
// Example 1:  Add a label, specifying all the default values.
const l = labels.add({
  show : true,
  position : Cesium.Cartesian3.ZERO,
  text : '',
  font : '30px sans-serif',
  fillColor : Cesium.Color.WHITE,
  outlineColor : Cesium.Color.BLACK,
  outlineWidth : 1.0,
  showBackground : false,
  backgroundColor : new Cesium.Color(0.165, 0.165, 0.165, 0.8),
  backgroundPadding : new Cesium.Cartesian2(7, 5),
  style : Cesium.LabelStyle.FILL,
  pixelOffset : Cesium.Cartesian2.ZERO,
  eyeOffset : Cesium.Cartesian3.ZERO,
  horizontalOrigin : Cesium.HorizontalOrigin.LEFT,
  verticalOrigin : Cesium.VerticalOrigin.BASELINE,
  scale : 1.0,
  translucencyByDistance : undefined,
  pixelOffsetScaleByDistance : undefined,
  heightReference : HeightReference.NONE,
  distanceDisplayCondition : undefined
});
// Example 2:  Specify only the label's cartographic position,
// text, and font.
const l = labels.add({
  position : Cesium.Cartesian3.fromRadians(longitude, latitude, height),
  text : 'Hello World',
  font : '24px Helvetica',
});
See:

contains(label)boolean

检查此收藏是否包含给定标签 .
Name Type Description
label Label 要检查的标签 .
Returns:
如果此收藏包含标签, 则属真, 否则为假 .
See:

destroy()

Destroys the WebGL resources held by this object. Destroying an object allows for deterministic 释放 WebGL 资源,而不是依赖垃圾收集器来摧毁此对象.

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:
labels = labels && labels.destroy();
See:

get(index)Label

在指定的索引中返回收藏中的标签。 指数为零 并随着标签的增加而增加。 删除标签后所有标签都移转 在左边,改变他们的指数。 此函数通常用于 LabelCollection#length to iterate over all the labels 在收藏中.
Performance:

Expected constant time. If labels were removed from the collection and Scene#render was not called, an implicit O(n) 操作完成.

Name Type Description
index number 公告牌百强单曲榜零基指数.
Returns:
指定索引上的标签 .
Throws:
  • DeveloperError : This object was destroyed, i.e., destroy() was called.
Example:
// Toggle the show property of every label in the collection
const len = labels.length;
for (let i = 0; i < len; ++i) {
  const l = billboards.get(i);
  l.show = !l.show;
}
See:

isDestroyed()boolean

如果此对象被销毁, 返回真实; 否则, 错误 .

If this object was destroyed, it should not be used; calling any function other than isDestroyed will result in a DeveloperError exception.
Returns:
如果此天体被销毁, 则属真; 否则, 属假 .
See:

remove(label)boolean

从收藏中删除标签。 一旦移除,标签就不再可用.
Performance:

Calling remove is expected constant time. However, the collection's vertex buffer is rewritten - an O(n) operation that also incurs CPU to GPU overhead. For 最佳性能,在拨打 NT 0 update NT 1 前删除尽可能多的标签. 如果打算暂时隐藏标签,通常更高效的调用 Label#show 而不是删除和重新添加标签.

Name Type Description
label Label 要删除的标签 .
Returns:
true if the label was removed; false if the label was not found in the collection.
Throws:
  • DeveloperError : This object was destroyed, i.e., destroy() was called.
Example:
const l = labels.add(...);
labels.remove(l);  // Returns true
See:

removeAll()

从收藏中删除所有标签.
Performance:

O(n). It is more efficient to remove all the labels 从收藏开始,然后添加新收藏,而不是完全创建新收藏.

Throws:
  • DeveloperError : This object was destroyed, i.e., destroy() was called.
Example:
labels.add(...);
labels.add(...);
labels.removeAll();
See:
Need help? The fastest way to get answers is from the community and team on the Cesium Forum.