cesium设置动态属性
中文文档地址
http://cesium.xin/cesium/cn/Documentation1.62/ColorMaterialProperty.html?classFilter=ColorMaterialProperty
点闪动
注意黄色代码部分,一定要加,否则属性会一直处于动态属性状态,一直处于计算状态
entity.billboard.scale = new Cesium.CallbackProperty(function () { const currentTime = Cesium.JulianDate.secondsDifference( store.viewer!.clock.currentTime, Cesium.JulianDate.fromDate(new Date(0)) ) flashingNum === 0 && (flashingNum = Math.floor(currentTime / Math.PI)) // console.log('flashingNum', flashingNum, 'currentTime / Math.PI', currentTime / Math.PI, 'Math.floor(currentTime / Math.PI) - flashingNum', Math.floor(currentTime / Math.PI) - flashingNum) const scale = Math.floor(currentTime / Math.PI) - flashingNum > 1 ? 1 : Math.abs(Math.sin(currentTime * 3)) console.log('currentTime', currentTime, 'flashingNum', flashingNum, 'scale', scale) if (scale >= 1 && entity.billboard) { entity.billboard.scale = 1.3 as any } return scale }, false)
闪动的线条
entity.polyline.material = new Cesium.ColorMaterialProperty( new Cesium.CallbackProperty(function () { const currentTime = Cesium.JulianDate.secondsDifference( store.viewer!.clock.currentTime, Cesium.JulianDate.fromDate(new Date(0)) ) flashingNum === 0 && (flashingNum = Math.floor(currentTime / Math.PI)) const alpha = Math.floor(currentTime / Math.PI) - flashingNum > 1 ? 1 : Math.abs(Math.sin(currentTime * 3)) // console.log('currentTime', currentTime, 'flashingNum', flashingNum, 'alpha', alpha) const color = Cesium.Color.fromCssColorString(`rgba(173,181,21,${alpha})`) if (alpha >= 1 && entity.polyline) { entity.polyline.material = new Cesium.ColorMaterialProperty(color) } return color }, false)