Cesium JS -Disable resizing of billboard labels and provide a fixed size

Viewed 221

How can we disable resizing of billboard labels ? I have restricted the resizing of the image itself by using the sizeInMeters property. However when I zoom in or out the label associated with the billboard still scales dynamically. Is there any way to disable this.

Sandcastle link

Code copied from link above:

var viewer = new Cesium.Viewer('cesiumContainer');

var image = new Image();
var entity;
image.onload = function() {
    entity = viewer.entities.add({
        position : Cesium.Cartesian3.fromDegrees(-75.1641667, 39.9522222),
        billboard : {
            position : Cesium.Cartesian3.fromDegrees(-75.1641667, 39.9522222),
            scaleByDistance : undefined,
          sizeInMeters:true,
          width:100,
          height:100,
            image : image
        },
        label : {
            text : 'Label on top of scaling billboard',
            font : '20px sans-serif',
            showBackground : true,
            horizontalOrigin : Cesium.HorizontalOrigin.CENTER,
            pixelOffset : new Cesium.Cartesian2(0.0, -image.height),
            pixelOffsetScaleByDistance : new Cesium.NearFarScalar(1.5e2, 3.0, 1.5e7, 0.5)
        }
    });
    viewer.zoomTo(viewer.entities);
};
image.src = '../images/facility.gif';

var counter = 0;
viewer.scene.postUpdate.addEventListener(function(){
    if(!Cesium.defined(entity)) {
        return;
    }
    counter += 0.04;
    if(Math.cos(counter) > 0){
        entity.label.text = "On";
    } else {
        entity.label.text = "Off";
    }
});
2 Answers

You have to set "sizeInMeters" to false.

I think you have misunderstood the meaning of "sizeInMeters". Let's think of a building on the map. Actually, the real size of the building in the world is constant. But whenever we zoom in or out, the size of the building on the map(pixel coordinate) changes. In another word, the building is drawn with different pixel sizes based on the map's scale. This is the same in your case.

Related