Label

internal constructor new Cesium.Label(options, labelCollection)

Create labels by calling LabelCollection#add. Do not call the constructor directly.
参数名称 类型 描述信息
options Label.ConstructorOptions Object describing initialization options
labelCollection LabelCollection Instance of LabelCollection
Throws:
  • 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
Demo:
参考:

成员(属性)

static Cesium.Label.enableRightToLeftDetection : boolean

Determines whether or not run the algorithm, that match the text of the label to right-to-left languages
默认值: false
使用示例s:
// Example 1.
// Set a label's rightToLeft before init
Cesium.Label.enableRightToLeftDetection = true;
const myLabelEntity = viewer.entities.add({
  label: {
    id: 'my label',
    text: 'זה טקסט בעברית \n ועכשיו יורדים שורה',
  }
});
// Example 2.
const myLabelEntity = viewer.entities.add({
  label: {
    id: 'my label',
    text: 'English text'
  }
});
// Set a label's rightToLeft after init
Cesium.Label.enableRightToLeftDetection = true;
myLabelEntity.text = 'טקסט חדש';
Gets or sets the background color of this label.
默认值: new Color(0.165, 0.165, 0.165, 0.8)
Gets or sets the background padding, in pixels, of this label. The x value controls horizontal padding, and the y value controls vertical padding.
默认值: new Cartesian2(7, 5)

disableDepthTestDistance : number

Gets or sets the distance from the camera at which to disable the depth test to, for example, prevent clipping against terrain. When set to zero, the depth test is always applied. When set to Number.POSITIVE_INFINITY, the depth test is never applied.
Gets or sets the condition specifying at what distance from the camera that this label will be displayed.
默认值: undefined
Gets and sets the 3D Cartesian offset applied to this label in eye coordinates. Eye coordinates is a left-handed coordinate system, where x points towards the viewer's right, y points up, and z points into the screen. Eye coordinates use the same scale as world and model coordinates, which is typically meters.

An eye offset is commonly used to arrange multiple label or objects at the same position, e.g., to arrange a label above its corresponding 3D model.

Below, the label is positioned at the center of the Earth but an eye offset makes it always appear on top of the Earth regardless of the viewer's or Earth's orientation.

l.eyeOffset = new Cartesian3(0.0, 8000000.0, 0.0);

默认值: Cartesian3.ZERO
Gets or sets the fill color of this label.
默认值: Color.WHITE
参考:
Gets or sets the font used to draw this label. Fonts are specified using the same syntax as the CSS 'font' property.
默认值: '30px sans-serif'
参考:
Gets or sets the height reference of this billboard.
默认值: HeightReference.NONE
Gets or sets the horizontal origin of this label, which determines if the label is drawn to the left, center, or right of its anchor position.


默认值: HorizontalOrigin.LEFT
使用示例:
// Use a top, right origin
l.horizontalOrigin = Cesium.HorizontalOrigin.RIGHT;
l.verticalOrigin = Cesium.VerticalOrigin.TOP;
Gets or sets the user-defined value returned when the label is picked.
Gets or sets the outline color of this label.
默认值: Color.BLACK
参考:

outlineWidth : number

Gets or sets the outline width of this label.
默认值: 1.0
参考:
Gets or sets the pixel offset in screen space from the origin of this label. This is commonly used to align multiple labels and billboards at the same position, e.g., an image and text. The screen space origin is the top, left corner of the canvas; x increases from left to right, and y increases from top to bottom.

default
l.pixeloffset = new Cartesian2(25, 75);
The label's origin is indicated by the yellow point.
默认值: Cartesian2.ZERO

pixelOffsetScaleByDistance : NearFarScalar

Gets or sets near and far pixel offset scaling properties of a Label based on the Label's distance from the camera. A label's pixel offset will be scaled between the NearFarScalar#nearValue and NearFarScalar#farValue while the camera distance falls within the lower and upper bounds of the specified NearFarScalar#near and NearFarScalar#far. Outside of these ranges the label's pixel offset scaling remains clamped to the nearest bound. If undefined, pixelOffsetScaleByDistance will be disabled.
使用示例s:
// Example 1.
// Set a label's pixel offset scale to 0.0 when the
// camera is 1500 meters from the label and scale pixel offset to 10.0 pixels
// in the y direction the camera distance approaches 8.0e6 meters.
text.pixelOffset = new Cesium.Cartesian2(0.0, 1.0);
text.pixelOffsetScaleByDistance = new Cesium.NearFarScalar(1.5e2, 0.0, 8.0e6, 10.0);
// Example 2.
// disable pixel offset by distance
text.pixelOffsetScaleByDistance = undefined;
Gets or sets the Cartesian position of this label.
Gets or sets the uniform scale that is multiplied with the label's size in pixels. A scale of 1.0 does not change the size of the label; a scale greater than 1.0 enlarges the label; a positive scale less than 1.0 shrinks the label.

Applying a large scale value may pixelate the label. To make text larger without pixelation, use a larger font size when calling Label#font instead.


From left to right in the above image, the scales are 0.5, 1.0, and 2.0.
默认值: 1.0
Gets or sets near and far scaling properties of a Label based on the label's distance from the camera. A label's scale will interpolate between the NearFarScalar#nearValue and NearFarScalar#farValue while the camera distance falls within the lower and upper bounds of the specified NearFarScalar#near and NearFarScalar#far. Outside of these ranges the label's scale remains clamped to the nearest bound. If undefined, scaleByDistance will be disabled.
使用示例s:
// Example 1.
// Set a label's scaleByDistance to scale by 1.5 when the
// camera is 1500 meters from the label and disappear as
// the camera distance approaches 8.0e6 meters.
label.scaleByDistance = new Cesium.NearFarScalar(1.5e2, 1.5, 8.0e6, 0.0);
// Example 2.
// disable scaling by distance
label.scaleByDistance = undefined;
Determines if this label will be shown. Use this to hide or show a label, instead of removing it and re-adding it to the collection.
默认值: true

showBackground : boolean

Determines if a background behind this label will be shown.
默认值: false
Gets or sets the style of this label.
默认值: LabelStyle.FILL
Gets or sets the text of this label.

totalScale : number

Gets the total scale of the label, which is the label's scale multiplied by the computed relative size of the desired font compared to the generated glyph size.
默认值: 1.0
Gets or sets near and far translucency properties of a Label based on the Label's distance from the camera. A label's translucency will interpolate between the NearFarScalar#nearValue and NearFarScalar#farValue while the camera distance falls within the lower and upper bounds of the specified NearFarScalar#near and NearFarScalar#far. Outside of these ranges the label's translucency remains clamped to the nearest bound. If undefined, translucencyByDistance will be disabled.
使用示例s:
// Example 1.
// Set a label's translucencyByDistance to 1.0 when the
// camera is 1500 meters from the label and disappear as
// the camera distance approaches 8.0e6 meters.
text.translucencyByDistance = new Cesium.NearFarScalar(1.5e2, 1.0, 8.0e6, 0.0);
// Example 2.
// disable translucency by distance
text.translucencyByDistance = undefined;
Gets or sets the vertical origin of this label, which determines if the label is to the above, below, or at the center of its anchor position.


默认值: VerticalOrigin.BASELINE
使用示例:
// Use a top, right origin
l.horizontalOrigin = Cesium.HorizontalOrigin.RIGHT;
l.verticalOrigin = Cesium.VerticalOrigin.TOP;

方法

computeScreenSpacePosition(scene, result)Cartesian2

Computes the screen-space position of the label's origin, taking into account eye and pixel offsets. The screen space origin is the top, left corner of the canvas; x increases from left to right, and y increases from top to bottom.
参数名称 类型 描述信息
scene Scene The scene the label is in.
result Cartesian2 可选 The object onto which to store the result.
返回值:
The screen-space position of the label.
使用示例:
console.log(l.computeScreenSpacePosition(scene).toString());
参考:

equals(other)boolean

Determines if this label equals another label. Labels are equal if all their properties are equal. Labels in different collections can be equal.
参数名称 类型 描述信息
other Label The label to compare for equality.
返回值:
true if the labels are equal; otherwise, false.

isDestroyed()boolean

Returns true if this object was destroyed; otherwise, false.

If this object was destroyed, it should not be used; calling any function other than isDestroyed will result in a DeveloperError exception.
返回值:
True if this object was destroyed; otherwise, false.

定义的类型

Cesium.Label.ConstructorOptions

Initialization options for the Label constructor
属性:
属性名称 类型 可选 默认值 描述信息
position Cartesian3 The cartesian position of the label.
id * <可选>
A user-defined object to return when the label is picked with Scene#pick.
show boolean <可选>
true Determines if this label will be shown.
text string <可选>
A string specifying the text of the label.
font string <可选>
'30px sans-serif' A string specifying the font used to draw this label. Fonts are specified using the same syntax as the CSS 'font' property.
style LabelStyle <可选>
LabelStyle.FILL A LabelStyle specifying the style of the label.
scale number <可选>
1.0 A number specifying the uniform scale that is multiplied with the label size.
showBackground boolean <可选>
false Determines if a background behind this label will be shown.
backgroundColor Color <可选>
new Color(0.165, 0.165, 0.165, 0.8) A Color specifying the background color of the label.
backgroundPadding Cartesian2 <可选>
new Cartesian2(7, 5) A Cartesian2 Specifying the horizontal and vertical background padding in pixels.
pixelOffset Cartesian2 <可选>
Cartesian2.ZERO A Cartesian2 specifying the pixel offset in screen space from the origin of this label.
eyeOffset Cartesian3 <可选>
Cartesian3.ZERO A Cartesian3 specifying the 3D Cartesian offset applied to this label in eye coordinates.
horizontalOrigin HorizontalOrigin <可选>
HorizontalOrigin.LEFT A HorizontalOrigin specifying the horizontal origin of this label.
verticalOrigin VerticalOrigin <可选>
VerticalOrigin.BASELINE A VerticalOrigin specifying the vertical origin of this label.
heightReference HeightReference <可选>
HeightReference.NONE A HeightReference specifying the height reference of this label.
fillColor Color <可选>
Color.WHITE A Color specifying the fill color of the label.
outlineColor Color <可选>
Color.BLACK A Color specifying the outline color of the label.
outlineWidth number <可选>
1.0 A number specifying the outline width of the label.
translucencyByDistance NearFarScalar <可选>
A NearFarScalar specifying near and far translucency properties of the label based on the label's distance from the camera.
pixelOffsetScaleByDistance NearFarScalar <可选>
A NearFarScalar specifying near and far pixel offset scaling properties of the label based on the label's distance from the camera.
scaleByDistance NearFarScalar <可选>
A NearFarScalar specifying near and far scaling properties of the label based on the label's distance from the camera.
distanceDisplayCondition DistanceDisplayCondition <可选>
A DistanceDisplayCondition specifying at what distance from the camera that this label will be displayed.
disableDepthTestDistance number <可选>
A number specifying the distance from the camera at which to disable the depth test to, for example, prevent clipping against terrain.