Entity flashes in cesium (point, surface and billboard)

The blinking of entity is mainly through the callback function CallbackPropertyto control the style change or whether to display

Insert picture description here

1. Flashing of dots

function f2(){
    
    
	var x=1;
	var flog=true;
	viewer.entities.add({
    
    
		name:"圆点point闪烁",
		position:Cesium.Cartesian3.fromDegrees(116.20+0.03,39.53+0.03,0),
		point : {
    
    
			show : true, // default
			color :new Cesium.CallbackProperty(function () {
    
    
				if(flog){
    
    
					x=x-0.05;
					if(x<=0){
    
    
						flog=false;
					}
					}else{
    
    
						x=x+0.05;
						if(x>=1){
    
    
						flog=true;
						}
					}
					return Cesium.Color.RED.withAlpha(x);
				},false),
			pixelSize : 10, // default: 1
			outlineWidth :0
		}
	});
}

2. The flickering of the face

function f1() {
    
    
    var x = 1;
    var flog = true;
    viewer.entities.add({
    
    
        name: "圆形区域闪烁",
        position: Cesium.Cartesian3.fromDegrees(116.20, 39.53, 0),
        ellipse: {
    
    
            semiMinorAxis: 2000.0,
            semiMajorAxis: 2000.0,
            height: 0,
            material: new Cesium.ColorMaterialProperty(new Cesium.CallbackProperty(function () {
    
    
                if (flog) {
    
    
                    x = x - 0.05;
                    if (x <= 0) {
    
    
                        flog = false;
                    }
                } else {
    
    
                    x = x + 0.05;
                    if (x >= 1) {
    
    
                        flog = true;
                    }
                }
                console.log(x)
                return Cesium.Color.RED.withAlpha(x);
            }, false))
        }
    });
}

3. Flashing of billboard pictures

function f1() {
    
    
var x = 1;
    var flog = true;
    viewer.entities.add({
    
    
        name: 'singleWarning',
        position: Cesium.Cartesian3.fromDegrees(116.20, 39.53),
        billboard: {
    
    
            image: '预警定位.png',
            name: 'singleWarning',
            show: new Cesium.CallbackProperty(function () {
    
    
                if (flog) {
    
    
                    x = x - 0.05;
                    if (x <= 0) {
    
    
                        flog = false;
                    }
                } else {
    
    
                    x = x + 0.05;
                    if (x >= 1) {
    
    
                        flog = true;
                    }
                }
                return x >= 0.5;
            },false),
            width: 100,
            height: 100,
            distanceDisplayCondition: new Cesium.DistanceDisplayCondition(0, 6.8e10)
        },
    })
}

The method here is actually to control show as true or false through CallbackProperty, if x>=0.5, it is true, otherwise it is false

Guess you like

Origin blog.csdn.net/KaiSarH/article/details/108680470