可渲染的标签集合。标签是定位在三维场景中的与视口对齐的文本。 每个标签可以有不同的字体、颜色、比例等。

Example labels
LabelCollection#add
从集合中添加和删除标签
和LabelCollection#remove
。Performance:
为了获得最佳性能,最好选择几个集合,每个集合都有多个标签 许多收藏只有几个标签。避免收藏 标签会更改每个帧,而其他帧则不会;相反,请创建一个或多个集合 对于静态标签,一个或多个集合用于动态标签。
Name | Type | Description | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object | optional
具有以下属性的对象:
|
Example:
// Create a label collection with two labels
var 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
标签混合选项。默认值用于渲染不透明和半透明标签。
但是,如果所有标签都是完全不透明的,或者所有标签都是完全透明的,
将技术设置为混合。不透明或者混合半透明可以改进
性能提高2倍。
-
Default Value:
BlendOption.OPAQUE_AND_TRANSLUCENT
此属性仅用于调试;它不用于生产用途,也不进行优化。
Draws the bounding sphere for each draw command in the primitive.
-
Default Value:
false
返回此集合中的标签数。通常用于
LabelCollection#get
遍历所有标签
收藏中。modelMatrix : Matrix4
4x4转换矩阵,用于将此集合中的每个标签从模型转换为世界坐标。
当这是单位矩阵时,标签以世界坐标系绘制,即地球的WGS84坐标系。
局部参考帧可以通过提供不同的转换矩阵来使用,就像返回的那样
通过
Transforms.eastNorthUpToFixedFrame
。-
Default Value:
Matrix4.IDENTITY
Example:
var 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'
});
Methods
add(options) → Label
创建具有指定初始属性的标签并将其添加到集合中。
将返回添加的标签,以便以后可以在集合中修改或删除它。
Performance:
调用add
应为常量时间。但是,集合的顶点缓冲区
重写;此操作为O(n)
,并且
CPU到GPU的开销。为了获得最佳性能,请在之前尽可能多地添加广告牌
拨打update
。
Name | Type | Description |
---|---|---|
options |
Object | optional 描述标签属性的模板,如示例1所示。 |
Returns:
添加到集合中的标签。
Throws:
-
DeveloperError :此对象已销毁,即调用destroy()。
Examples:
// Example 1: Add a label, specifying all the default values.
var 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.
var l = labels.add({
position : Cesium.Cartesian3.fromRadians(longitude, latitude, height),
text : 'Hello World',
font : '24px Helvetica',
});
See:
检查此集合是否包含给定的标签。
Name | Type | Description |
---|---|---|
label |
Label | 要检查的标签。 |
Returns:
如果此集合包含标签,则为true,否则为false。
See:
销毁此对象持有的WebGL资源。销毁一个对象允许确定性 释放WebGL资源,而不是依赖垃圾回收器销毁此对象。 一旦一个对象被销毁,就不应该使用它;调用除
isDestroyed
将导致DeveloperError
异常。因此,
如示例所示,将返回值(undefined
)分配给对象。Throws:
-
DeveloperError :此对象已销毁,即调用destroy()。
Example:
labels = labels && labels.destroy();
See:
get(index) → Label
返回集合中指定索引处的标签。指数以零为基础
并且随着标签的增加而增加。移除标签会在之后移动所有标签
它在左边,改变他们的指数。此函数常用于
LabelCollection#length
遍历所有标签
收藏中。Performance:
预期恒定时间。如果从集合中移除标签并且 不是6861166,是6866166 执行操作。
Name | Type | Description |
---|---|---|
index |
Number | 广告牌的从零开始的索引。 |
Returns:
指定索引处的标签。
Throws:
-
DeveloperError :此对象已销毁,即调用destroy()。
Example:
// Toggle the show property of every label in the collection
var len = labels.length;
for (var i = 0; i < len; ++i) {
var l = billboards.get(i);
l.show = !l.show;
}
See:
Returns:
如果此对象被销毁,则为True;否则为false。
从集合中移除标签。一旦删除,标签将不再可用。
Performance:
调用remove
应为常量时间。但是,集合的顶点缓冲区
重写-O(n)
操作也会导致CPU到GPU的开销。为
最佳性能,请在拨打update
之前删除尽可能多的标签。
如果您打算暂时隐藏一个标签,通常打电话更有效
Label#show
,而不是移除并重新添加标签。
Name | Type | Description |
---|---|---|
label |
Label | 要删除的标签。 |
Returns:
如果标签已移除,则为
true
;如果在集合中未找到标签,则为false
。Throws:
-
DeveloperError :此对象已销毁,即调用destroy()。
Example:
var l = labels.add(...);
labels.remove(l); // Returns true
See:
从集合中删除所有标签。
Performance:
O(n)
去掉所有的标签更有效
从一个集合中添加新的集合,而不是完全创建一个新集合。
Throws:
-
DeveloperError :此对象已销毁,即调用destroy()。
Example:
labels.add(...);
labels.add(...);
labels.removeAll();