在Cesium中重新创建一个新的EntityCollection,而不是直接使用viewer.entities的对象。
首先要看viewer到entity的关系:
Viewer ==> DataSourceDisplay ==> DataSourceCollection ==> CustomDataSource ==> EntityCollection ==> Entity
也就是说直接添加一个EntityCollection在viewer是不会渲染的,必须指定数据源才行,否则无效。可以看出来这个类属于底层类,实用性不强,如果想加实体集群使用new Cesium.CustomDataSource(name)
官方例子:
const dataSource = new Cesium.CustomDataSource('myData'); const entity = dataSource.entities.add({//EntityCollection直接创建无效只能通过数据源添加 position : Cesium.Cartesian3.fromDegrees(1, 2, 0), billboard : { image : 'image.png' } }); viewer.dataSources.add(dataSource);