What is "document.getElementByID" for Cesium Entities?

How can I find the label id and change its background color? This is same to HTML concept of “document.getElementById”. What is the “document.getElementByID” for cesium entity-label? I would like to use it function two in this example.

                          id: "1234",
                          orientation: new Cesium.HeadingPitchRoll(0, 0, 0),
                          position: Cesium.Cartesian3.fromDegrees(parseFloat(lon), parseFloat(lat), 30),
                          label: {
                              text: "hello",
                              verticalOrigin: Cesium.VerticalOrigin.TOP,
                              font: '20px sans-serif',
                              fillColor: Cesium.Color.BLACK,
                              backgroundColor: Cesium.Color.WHITE,
                              backgroundPadding : new Cesium.Cartesian2(30, 15),
                              style : Cesium.LabelStyle.FILL_AND_OUTLINE,
                              showBackground: true

 var onevalue="";

function one(){
    viewer.screenSpaceEventHandler.setInputAction(function(mouse) {
                      var pickedObject = viewer.scene.pick(mouse.position);

                      if (Cesium.defined(pickedObject)) {
                          onevalue = pickedObject.id.id;

                    }, Cesium.ScreenSpaceEventType.RIGHT_CLICK);

function two(){
//how can change the label properties in this function. i.e. I want to change the background color.

entity = viewer.entities.getById(onevalue);  // is this the document.getElementById?
    entity.label.backgroundColor = Cesium.Color.SKYBLUE;

Hi @lawyongwei

Try this to find the label id:


You can also refer to Pick Entity logic at:

Hi @lawyongwei

Please refer section Managing Entity section at the following link to learn more on Cesium entity

In case it isn’t clear from the other replies, Cesium Entities are not added to the DOM. You probably knew that, but I wanted to make sure.

The Viewer has a DataSource called entities that you can add an Entity to, or you can make your own DataSource and add it to viewer.dataSources. When you call viewer.entities.getById(id), you’re getting back an instance of Entity. You will notice in that second link that someEntity.label is an instance of LabelGraphics which has a backgroundColor property.

1 Like