EntityCollection
EntityCollection 是一个包含多个实体的实体集合,用于管理所有实体的添加、删除、更新等操作。
属性
id : String 该实体集合的唯一标识符,此属性通常在构造中设置。
length : Number 返回实体集合中实体的数量。
方法
add(entity) : void 将实体添加到实体集合中。
remove(entity) : void 从实体集合中删除实体。
removeAll() : void 从实体集合中删除所有实体。
contains(entity) : boolean 判断实体集合中是否包含指定的实体。
get(index) : Entity 返回实体集合中指定索引的实体。
getById(id) : Entity 返回实体集合中指定ID的实体。
raiseEvent(event, optionalArgument) : void 触发指定类型的事件,并附带可选参数。
事件
collectionChanged : 当实体集合中添加或删除实体时触发。
示例
var entityCollection = new Cesium.EntityCollection();
var entity1 = entityCollection.add({
position: Cesium.Cartesian3.fromDegrees(0, 0),
billboard: {
image: 'path/to/image.png'
}
});
var entity2 = entityCollection.get(0);
entityCollection.raiseEvent('collectionChanged');