LabelCollection
A renderable collection of labels. Labels are viewport-aligned text positioned in the 3D scene. Each label can have a different font, color, scale, etc.
Labels are added and removed from the collection using LabelCollection.add and LabelCollection.remove.
// Create a label collection with two labels
const labels = scene.primitives.add(new LabelCollection());
labels.add({
position : new Cartesian3(1.0, 2.0, 3.0),
text : 'A label'
});
labels.add({
position : new Cartesian3(4.0, 5.0, 6.0),
text : 'Another label'
});See also
Types
Properties
The label blending option. The default is used for rendering both opaque and translucent labels. However, if either all of the labels are completely opaque or all are completely translucent, setting the technique to BlendOption.OPAQUE or BlendOption.TRANSLUCENT can improve performance by up to 2x.
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. When set to 0, the approximate depth test is always applied. When set to Number.POSITIVE_INFINITY, the approximate depth test is never applied.
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.
This property is for debugging only; it is not for production use nor is it optimized.
Returns the number of labels in this collection. This is commonly used with LabelCollection.get to iterate over all the labels in the collection.
The 4x4 transformation matrix that transforms each label in this collection from model to world coordinates. When this is the identity matrix, the labels are drawn in world coordinates, i.e., Earth's WGS84 coordinates. Local reference frames can be used by providing a different transformation matrix, like that returned by Transforms.eastNorthUpToFixedFrame.
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 against three key points. This ensures that if any key point of the label is visible, the whole label will be visible. When set to 0, this feature is disabled and portions of a label behind terrain be clipped.
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.
Functions
Creates and adds a label with the specified initial properties to the collection. The added label is returned so it can be modified or removed from the collection later.
Returns the label in the collection at the specified index. Indices are zero-based and increase as labels are added. Removing a label shifts all labels after it to the left, changing their indices. This function is commonly used with LabelCollection.length to iterate over all the labels in the collection.
Returns true if this object was destroyed; otherwise, false.