Class: PrimitiveCollection

PrimitiveCollection

new PrimitiveCollection()

The container class used to manage multiple Primitives is typically used in conjunction with Scene # primitives, but PrimitiveCollection itself is also a primitive, so collections can be added to a collection to form a hierarchical structure.

Name Type Default Description
options.show Boolean true optional

Determine whether to display the primitives in the collection.

options.destroyPrimitives Boolean true optional

Determine whether to destroy the primitives in the collection when deleting them.

Example
var billboards = new SuperMap3D.BillboardCollection();
var labels = new SuperMap3D.LabelCollection();

var collection = new SuperMap3D.PrimitiveCollection();
collection.add(billboards);

scene.primitives.add(collection);  // Add collection
scene.primitives.add(labels);      // Add regular primitive

Members

destroyPrimitivesBoolean

Determine whether to destroy the primitives in the collection when using PrimitiveCollection # destroy or PrimitiveCollection # remove, or implicitly remove the primitives in the collection using PrimitiveCollection # removeAll.

Default Value:
true
Examples
// Example 1. Primitives are destroyed by default.
var primitives = new SuperMap3D.PrimitiveCollection();
var labels = primitives.add(new SuperMap3D.LabelCollection());
primitives = primitives.destroy();
var b = labels.isDestroyed(); // true
// Example 2. Do not destroy primitives in a collection.
var primitives = new SuperMap3D.PrimitiveCollection();
primitives.destroyPrimitives = false;
var labels = primitives.add(new SuperMap3D.LabelCollection());
primitives = primitives.destroy();
var b = labels.isDestroyed(); // false
labels = labels.destroy();    // explicitly destroy

readonly lengthNumber

Get the number of primitives in the collection.

readonly primitiveAddedEvent

When a primitive is added to a collection, an event is triggered. The event handler will receive the added primitives.

readonly primitiveRemovedEvent

When a primitive is removed from a collection, an event is triggered. The event handler will receive the removed primitive.

Note: Depending on the option of the destructroPrimitives constructor, the primitive may have been destroyed.

showBoolean

Determine whether to display the primitives in the set.

Default Value:
true

Methods

add(primitive){Object}

Add a primitive to the collection.

Name Type Description
primitive Object

Supplementary raw data.

Throws:

The object is destroyed by calling destroy().

Type
DeveloperError
Returns:
Type Description
Object Primitives added to the collection.
Example
var billboards = scene.primitives.add(new SuperMap3D.BillboardCollection());

contains(primitive){Boolean}

Determine whether the set contains a primitive.

Name Type Description
primitive Object optional

The raw data that needs to be checked.

See:
Throws:

The object has been destroyed, i.e. destroy() has been called.

Type
DeveloperError
Returns:
Type Description
Boolean If the primitive is in the set, it is true; If the primitive is undefined or cannot be found in the collection, it is false.

destroy(){undefined}

Destroy the WebGL resources held by each primitive in the set. Explicitly destroying the collection can release WebGL resources deterministically, rather than relying on garbage collectors to destroy the collection. Since destroying a set destroys all contained primitives, the set can only be destroyed when it is determined that no other code is still using any contained primitives. Once the collection is destroyed, it should no longer be used; Calling any function other than isDestroyed will result in a Developer Error exception. Therefore, please assign the return value (undefined) to the object using the method shown in the example.

See:
Throws:

The object has been destroyed, i.e. destroy() has been called.

Type
DeveloperError
Returns:
Type Description
undefined
Example
primitives = primitives && primitives.destroy();

get(index){Object}

Returns the primitives in the collection at the specified index.

Name Type Description
index Number

The zero base index of the primitive to be returned.

See:
Throws:

The object has been destroyed, i.e. destroy() has been called.

Type
DeveloperError
Returns:
Type Description
Object The primitive located in the index.
Example
// Toggle the show property of every primitive in the collection.
var primitives = scene.primitives;
var length = primitives.length;
for (var i = 0; i < length; ++i) {
  var p = primitives.get(i);
  p.show = !p.show;
}

isDestroyed(){Boolean}

If the object has been destroyed, return true; Otherwise, return false. If the object has been destroyed, it should not be used; Calling any function other than isDestroyed will result in a Developer Error exception.

See:
Returns:
Type Description
Boolean If the object has been destroyed, it is true; Otherwise, it is false.

lower(primitive)

Move the primitive down one in the set. If all the primitives in the set are drawn on a sphere, the prototype will be moved downwards by one.

Name Type Description
primitive Object optional

The elements that need to be lowered.

See:
Throws:
  • Primitive is not in the collection.

    Type
    DeveloperError
  • The object has been destroyed, i.e. destroy() has been called.

    Type
    DeveloperError

lowerToBottom(primitive)

Lower the primitive to the 'bottom' of the set. If all the primitives in the set are drawn on a sphere, they will be moved to the bottom.

Name Type Description
primitive Object optional

To lower the base element.

See:
Throws:
  • The primitive is not in this set.

    Type
    DeveloperError
  • The object has been destroyed, i.e. destroy() has been called.

    Type
    DeveloperError

raise(primitive)

Move the primitives in the set up one level. If all the primitives in the set are drawn on a sphere, the primitive will be moved up one level.

Name Type Description
primitive Object optional

The basic elements to be triggered.

See:
Throws:
  • Primitive is not in the collection.

    Type
    DeveloperError
  • The object has been destroyed, i.e. destroy() has been called.

    Type
    DeveloperError

raiseToTop(primitive)

Raise the primitive to the 'top' of the set. If all primitives in the collection are drawn on a sphere, the primitive will be moved to the top.

Name Type Description
primitive Object optional

Raise the primitive to the 'top'.

See:
Throws:
  • Primitive is not in the collection.

    Type
    DeveloperError
  • The object is destroyed by calling destroy().

    Type
    DeveloperError

remove(primitive){Boolean}

Remove primitives from the collection.

Name Type Description
primitive Object optional

The primitive to be removed.

See:
Throws:

The object has been destroyed, i.e. destroy() has been called.

Type
DeveloperError
Returns:
Type Description
Boolean If the primitive has been removed, it is true; If the primitive is undefined or cannot be found in the collection, it is false.
Example
var billboards = scene.primitives.add(new SuperMap3D.BillboardCollection());
scene.primitives.remove(p);  // Returns true

removeAll()

Delete all primitives in the collection.

See:
Throws:

The object has been destroyed, i.e. destroy() has been called.

Type
DeveloperError