Class: LabelGraphics

LabelGraphics

new LabelGraphics(options)

Draw label class

The location is defined by the Entity.


Example labels

Name Type Description
options Object optional

Object is an object that contains the following properties:

Name Type Default Description
show Property true optional

Boolean attribute, specifying the visibility of the label.

text Property optional

The string attribute specifies the text of the label. Use '\ n' for line breaks.

font Property '30px sans-serif' optional

Specify CSS font

style Property LabelStyle.FILL optional

LabelStyle property.

scale Property 1.0 optional

The number attribute specifies the scaling ratio of the label.

showBackground Property false optional

Boolean property, specifying whether the label background should be displayed.

backgroundColor Property new Color(0.165, 0.165, 0.165, 0.8) optional

The Color property specifies the background color of the label.

backgroundPadding Property new Cartesian2(7, 5) optional

Cartesian2 attribute, specifying the background padding distance between the horizontal and vertical directions of the label, in pixels.

pixelOffset Property Cartesian2.ZERO optional

Cartesian2 attribute, specifying pixel offset.

eyeOffset Property Cartesian3.ZERO optional

Cartesian3 attribute, specifying eye offset.

horizontalOrigin Property HorizontalOrigin.CENTER optional

HorizontalOrigin property.

verticalOrigin Property VerticalOrigin.CENTER optional

VerticalOrigin attribute.

heightReference Property HeightReference.NONE optional

The HeightReference property specifies the relative reference point of the height.

fillColor Property Color.WHITE optional

The Color property specifies the fill color of the label.

outlineColor Property Color.BLACK optional

The Color property specifies the color of the contour.

outlineWidth Property 1.0 optional

The number attribute specifies the pixel width of the contour.

translucencyByDistance Property optional

The NearFarScalar property is used to modify the transparency of labels based on their distance from the camera.

pixelOffsetScaleByDistance Property optional

The NearFarScalar property is used to scale the pixel offset of a label based on its distance from the camera.

scaleByDistance Property optional

The NearFarScalar property is used to scale the size of labels based on their distance from the camera.

distanceDisplayCondition Property optional

The DistanceDisplayCondition property specifies how far away the label should be displayed from the camera.

disableDepthTestDistance Property optional

The number attribute specifies that depth detection is turned off when the distance from the tag to the camera is less than a specified value.

Members

backgroundColorProperty

Get or set the Color property to specify the label background color.

Default Value:
new Color(0.165, 0.165, 0.165, 0.8)

backgroundPaddingProperty

Get or set the Cartesian2 property, specifying the horizontal and vertical background padding distance of the label in pixels.

Default Value:
new Cartesian2(7, 5)

readonly definitionChangedEvent

Get events. This event is thrown when the value of a property or sub property is modified, or when the definition is modified.

disableDepthTestDistanceProperty

Get or set the distance between the label and the camera. When the distance between the label and the camera is less than this distance, turn off depth detection. For example, to prevent being cut off due to terrain obstruction. When the value is 0, always enable depth detection. The value is Number. POSITIVE.INFINITY, and depth detection is always turned off.

distanceDisplayConditionProperty

Get or set the DistanceDisplayCondition property, specifying how far away the label should be displayed from the camera.

eyeOffsetProperty

Get or set a Cartesian3 property that specifies the offset of the label in camera space. The camera space is a left-hand coordinate system space. The x-axis points to the right of the observer, the y-axis points to the top of the observer, and the z-axis points inside the screen.

EyeOffset is usually used to arrange multiple labels in the same position, such as placing one label on top of its corresponding model

The figure below shows a label placed at the center of the Earth.However, eyeOffset allows the label to always appear above the Earth, regardless of the observer's or Earth's orientation.

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

Default Value:
Cartesian3.ZERO

fillColorProperty

Get or set the Color property to specify the fill color.

fontProperty

Get or set the string property, specify the font information of the label's text, in CSS syntax format.

heightReferenceProperty

Get or set the HeightReference property.

Default Value:
HeightReference.NONE

horizontalOriginProperty

Gets or sets the property of the specified HorizontalOrigin.

outlineColorProperty

Get or set the Color property to specify the color of the contour.

outlineWidthProperty

Get or set the number property to specify the contour width.

pixelOffsetProperty

Get or set the Cartesian2 property. Specify the pixel offset of the label from its origin in screen space. This is usually used to align multiple labels to the same position. The origin of screen space is the upper left corner of the canvas; The value of x increases from left to right, and the value of y increases from top to bottom.

default
l.pixeloffset = new Cartesian2(25, 75);
The label origin is a yellow dot.

Default Value:
Cartesian2.ZERO

pixelOffsetScaleByDistanceProperty

Get or set the value of NearFarScalar. This attribute specifies the pixel offset of the label based on the distance between the label and the camera. When the distance between the camera and the label is between NearFarScalar # near and NearFarScalar # far, the pixel offset of the label will be interpolated between NearFarScalar # nearValue and NearFarScalar # farValue. When the distance between the camera and the label is outside of NearFarScalar # near and NearFarScalar # far, the pixel offset of the label will be the closest value.

scaleProperty

Get or set the number property to specify the scaling ratio of the label. A ratio greater than 1.0 will enlarge the cousin, while a ratio less than 1.0 will shrink the label.


The image above, from left to right, shows scale ratios of0.5, 1.0, and 2.0.

Default Value:
1.0

scaleByDistanceProperty

Get or set the NearFarScalar property. This attribute specifies the scaling ratio of the label based on the distance between the label and the camera. When the distance between the camera and the label is between NearFarScalar # near and NearFarScalar # far, the scaling ratio of the label will be interpolated between NearFarScalar # nearValue and NearFarScalar # farValue. When the distance between the camera and the label is outside of NearFarScalar # near and NearFarScalar # far, the scaling ratio of the label will be the closest value. If this property is not defined, the scaleByDistance property will not work.

showProperty

Get or set boolean attribute to specify the visibility of the label.

showBackgroundProperty

Get or set boolean property to specify whether the label background should be displayed.

Default Value:
false

styleProperty

Get or set the LabelStyle property.

textProperty

Get or set the string property to specify the text of the label. Use '\ n' for line breaks.

translucencyByDistanceProperty

Get or set the value of NearFarScalar. This attribute specifies the transparency of the label based on the distance between the label and the camera. When the distance between the camera and the label is between NearFarScalar # near and NearFarScalar # far, the transparency of the label will be interpolated between NearFarScalar # nearValue and NearFarScalar # farValue. When the distance between the camera and the label is outside of NearFarScalar # near and NearFarScalar # far, the transparency of the label will be the closest value.

verticalOriginProperty

Gets or sets the property of the specified VerticalOrigin.

Methods

clone(result){LabelGraphics}

Copy instance

Name Type Description
result LabelGraphics optional

The object that stores the copied results

Returns:
Type Description
LabelGraphics If input parameters are provided, return the modified input parameter object. If no input parameters are provided, return a new instance.

merge(source)

Assign the attribute values corresponding to the source object to all unspecified attributes of this instance.

Name Type Description
source LabelGraphics

An object that provides attribute values.