BillboardCollection

BillboardCollection

new

A renderable collection of billboards. Billboards are viewport-aligned images positioned in the 3D scene.


Example billboards


Billboards are added and removed from the collection using BillboardCollection#add and BillboardCollection#remove. All billboards in a collection reference images from the same texture atlas, which is assigned using BillboardCollection#setTextureAtlas.

Performance:

For best performance, prefer a few collections, each with many billboards, to many collections with only a few billboards each. Organize collections so that billboards with the same update frequency are in the same collection, i.e., billboards that do not change should be in one collection; billboards that change every frame should be in another collection; and so on.

Example
// Create a billboard collection with two billboards
var billboards = new BillboardCollection();
var atlas = context.createTextureAtlas({images : images});
billboards.setTextureAtlas(atlas);
billboards.add({
  position : { x : 1.0, y : 2.0, z : 3.0 },
  imageIndex : 0
});
billboards.add({
  position : { x : 4.0, y : 5.0, z : 6.0 },
  imageIndex : 1
});
Demo:
See:
Source:

Members

:Matrix4

The 4x4 transformation matrix that transforms each billboard in this collection from model to world coordinates. When this is the identity matrix, the billboards 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. This matrix is available to GLSL vertex and fragment shaders via czm_model and derived uniforms.
Example
var center = ellipsoid.cartographicToCartesian(Cartographic.fromDegrees(-75.59777, 40.03883));
billboards.modelMatrix = Transforms.eastNorthUpToFixedFrame(center);
billboards.add({ imageIndex: 0, position : new Cartesian3(0.0, 0.0, 0.0) }); // center
billboards.add({ imageIndex: 0, position : new Cartesian3(1000000.0, 0.0, 0.0) }); // east
billboards.add({ imageIndex: 0, position : new Cartesian3(0.0, 1000000.0, 0.0) }); // north
billboards.add({ imageIndex: 0, position : new Cartesian3(0.0, 0.0, 1000000.0) }); // up
]);
Default Value:
See:

Methods

Creates and adds a billboard with the specified initial properties to the collection. The added billboard is returned so it can be modified or removed from the collection later.

Performance:

Calling add is expected constant time. However, when BillboardCollection#update is called, the collection's vertex buffer is rewritten - an O(n) operation that also incurs CPU to GPU overhead. For best performance, add as many billboards as possible before calling update.

Parameters:
Name Type Argument Default Description
billboard Object <optional>
undefined A template describing the billboard's properties as shown in Example 1.
Throws:
DeveloperError : This object was destroyed, i.e., destroy() was called.
Returns:
Billboard The billboard that was added to the collection.
Example
// Example 1:  Add a billboard, specifying all the default values.
var b = billboards.add({
  show : true,
  position : Cartesian3.ZERO,
  pixelOffset : Cartesian2.ZERO,
  eyeOffset : Cartesian3.ZERO,
  horizontalOrigin : HorizontalOrigin.CENTER,
  verticalOrigin : VerticalOrigin.CENTER,
  scale : 1.0,
  imageIndex : 0,
  color : Color.WHITE
});

// Example 2:  Specify only the billboard's cartographic position.
var b = billboards.add({
  position : ellipsoid.cartographicToCartesian(new Cartographic(longitude, latitude, height))
});
See:

Check whether this collection contains a given billboard.

Parameters:
Name Type Description
billboard Billboard The billboard to check for.
Returns:
Boolean true if this collection contains the billboard, false otherwise.
See:

Destroys the WebGL resources held by this object. Destroying an object allows for deterministic release of WebGL resources, instead of relying on the garbage collector to destroy this object.

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

Returns the billboard in the collection at the specified index. Indices are zero-based and increase as billboards are added. Removing a billboard shifts all billboards after it to the left, changing their indices. This function is commonly used with BillboardCollection#getLength to iterate over all the billboards in the collection.

Performance:

Expected constant time. If billboards were removed from the collection and BillboardCollection#update was not called, an implicit O(n) operation is performed.

Parameters:
Name Type Description
index Number The zero-based index of the billboard.
Throws:
Returns:
Billboard The billboard at the specified index.
Example
// Toggle the show property of every billboard in the collection
var len = billboards.getLength();
for (var i = 0; i < len; ++i) {
  var b = billboards.get(i);
  b.setShow(!b.getShow());
}
See:

Returns true if the texture atlas is destroyed when the collection is destroyed; otherwise, false.

Throws:
DeveloperError : This object was destroyed, i.e., destroy() was called.
Returns:
true if the texture atlas is destroyed when the collection is destroyed; otherwise, false.
See:

Returns the number of billboards in this collection. This is commonly used with BillboardCollection#get to iterate over all the billboards in the collection.

Performance:

Expected constant time. If billboards were removed from the collection and BillboardCollection#update was not called, an implicit O(n) operation is performed.

Throws:
DeveloperError : This object was destroyed, i.e., destroy() was called.
Returns:
Number The number of billboards in this collection.
Example
// Toggle the show property of every billboard in the collection
var len = billboards.getLength();
for (var i = 0; i < len; ++i) {
  var b = billboards.get(i);
  b.setShow(!b.getShow());
}
See:

DOC_TBA

Throws:
DeveloperError : This object was destroyed, i.e., destroy() was called.
See:

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.

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

Removes a billboard from the collection.

Performance:

Calling remove is expected constant time. However, when BillboardCollection#update is called, the collection's vertex buffer is rewritten - an O(n) operation that also incurs CPU to GPU overhead. For best performance, remove as many billboards as possible before calling update. If you intend to temporarily hide a billboard, it is usually more efficient to call Billboard#setShow instead of removing and re-adding the billboard.

Parameters:
Name Type Description
billboard Billboard The billboard to remove.
Throws:
DeveloperError : This object was destroyed, i.e., destroy() was called.
Returns:
Boolean true if the billboard was removed; false if the billboard was not found in the collection.
Example
var b = billboards.add(...);
billboards.remove(b);  // Returns true
See:

Removes all billboards from the collection.

Performance:

O(n). It is more efficient to remove all the billboards from a collection and then add new ones than to create a new collection entirely.

Throws:
DeveloperError : This object was destroyed, i.e., destroy() was called.
Example
billboards.add(...);
billboards.add(...);
billboards.removeAll();
See:

Determines if the texture atlas is destroyed when the collection is destroyed. If the texture atlas is used by more than one collection, set this to false, and explicitly destroy the atlas to avoid attempting to destroy it multiple times.

Parameters:
Name Type Description
value Boolean Indicates if the texture atlas is destroyed when the collection is destroyed.
Throws:
DeveloperError : This object was destroyed, i.e., destroy() was called.
Example
// Destroy a billboard collection but not its texture atlas.

var atlas = context.createTextureAtlas({images : images});
billboards.setTextureAtlas(atlas);
billboards.setDestroyTextureAtlas(false);
billboards = billboards.destroy();
console.log(atlas.isDestroyed()); // False
See:

DOC_TBA

Throws:
DeveloperError : This object was destroyed, i.e., destroy() was called.
Example
// Assigns a texture atlas with two images to a billboard collection.
// Two billboards, each referring to one of the images, are then
// added to the collection.
var billboards = new BillboardCollection();
var images = [image0, image1];
var atlas = context.createTextureAtlas({images : images});
billboards.setTextureAtlas(atlas);
billboards.add({
  // ...
  imageIndex : 0
});
billboards.add({
  // ...
  imageIndex : 1
});
See: