How to create dataSource from entities?

1. A concise explanation of the problem you’re experiencing.

I have created some billboards and some labels, and I’d like to put them in a cluster to control their visibility through pixelRange.

I’ve read that I need to create a dataSource, but how to create a dataSource from entities?

2. A minimal code example. If you’ve found a bug, this helps us reproduce and repair it.

viewer.entities.add({

position: Cesium.Cartesian3.fromDegrees(longitude, latitude),

billboard: {

image: ‘images/pin_icon.svg’,

width: 16.3,

height: 21.3,

verticalOrigin: Cesium.VerticalOrigin.BOTTOM,

heightReference: Cesium.HeightReference.RELATIVE_TO_GROUND,

}

/// now I should put this entity in a dataSource / cluster

3. Context. Why do you need to do this? We might know a better way to accomplish your goal.

to control their visibility through pixelRange.

4. The Cesium version you’re using, your operating system and browser.

1.61

This is the solution

var dataSource = new Cesium.CustomDataSource('myData');

var entity = dataSource.entities.add({
   position : Cesium.Cartesian3.fromDegrees(1, 2, 0),
   billboard : {
       image : 'image.png'
   }
});

viewer.dataSources.add(dataSource);