cesium-CallbackProperty是干啥的?

CallbackProperty就是属性回调函数,对于实体来说,比如一条线,如果我想改变其线宽,或者改变其颜色,但又不想重新绘制,那CallbackProperty就派上了用场。
请看如下示例:

    let viewer = new Cesium.Viewer('cesiumContainer');
    let entity = viewer.entities.add({
        polyline: {
            positions: new Cesium.CallbackProperty(changePosition, false),
            width: new Cesium.CallbackProperty(changeWidth, false),
            material: new Cesium.ColorMaterialProperty(new Cesium.CallbackProperty(changeColor, false)),
        }
    });

    function changePosition(time, isConstant) {
        let lat = 20;
        let lon = 100;
        return Cesium.Cartesian3.fromDegreesArray(
            [lon, lat, lon - Math.floor(Math.random() * 1000), lat - Math.floor(Math.random() * 100)],
            Cesium.Ellipsoid.WGS84,
            isConstant
        );

    }
    function changeWidth(time, isConstant) {
        return Math.floor(Math.random() * 10);
    }
    function changeColor(time, isConstant) {
        return Cesium.Color.fromRandom({
            minimumRed: 0.1,
            minimumGreen: 0.1,
            minimumBlue: 0.1,
            alpha: 1.0
        });
    }
move.gif
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容