C1——cesium模拟建筑

需求:奔来有个建筑,换成其他建筑。特点是整个过程是动态的。

思路:

第一步:视角移动过去

第二部:隐藏原来建筑

第三步:显示新的建筑

特点:特点是整个过程是动态的; 每步之间有先后顺序。已经封装为类

封装的代码:

class ConstructSimul {
    constructor(viewer) {
        this.viewer = viewer,
        this.model = null
    }
}

// ConstructSimul.prototype.start这么些最好,只是在原型上加了方法,不会造成原型链断裂
ConstructSimul.prototype.start = ()=>{
    let _this = this;
    let viewer = this.viewer;
    let step0 = function(){
        setTimeout( ()=>{
            step1();
        },500)
    };
    let step1 = function(){
        viewer.camera.flyTo({
            destination: Cesium.Cartesian3.fromDegrees( 10*.***7267, 29.***2640, 4*5.1***9071292 ),
            orientation: {
                heading: Cesium.Math.toRadians(  1**.**274808139827 ),
                pitch: Cesium.Math.toRadians( -11.**085162 ),
                roll: 0
            },
            complete: function () {
                setTimeout( ()=>{
                    step2(step3);
                },500)
            }
        });
    };
    let step2 = function(fun){
        let layer = _this.viewer.scene.layers.find("原来的图层");
        if( layer){
            layer.visible = false;
        }
        fun();
    };
    let step3 = function(){
        _this.viewer.entities.add({
            id:"gltf",
            position: Cesium.Cartesian3.fromDegrees(10*.**77714216316,29.**15177926754, 209),
            orientation: Cesium.Transforms.headingPitchRollQuaternion( Cesium.Cartesian3.fromDegrees(106.***714216316,29.**5177926754,209),new Cesium.HeadingPitchRoll(0, 0, 0)),
            model: {
                uri: "static/gltf/scene1.gltf",
            }
        });
    };
    let step4 = function(){
        let layer = _this.viewer.scene.layers.find("原来的图层");
        if( layer){
            layer.visible = true;
        }
    };
    
    step0();
   
}
ConstructSimul.prototype.end = ()=>{
    let entity = this.viewer.entities.getById("gltf");
    if (entity) {
      this.viewer.entities.remove(entity);
    }
    let layer = this.viewer.scene.layers.find("原来的图层");
    if( layer){
        layer.visible = true;
    }
}
/*
// 这么写也不好因为ConstructSimul.prototype.__prot__指向Object,这么重新定义后原型链就断了,也就灭有toString等方法了。
ConstructSimul.prototype = {
    constructor: ConstructSimul,
    start: function(){
        let _this = this;
        let viewer = this.viewer;
        let step0 = function(){
            setTimeout( ()=>{
                step1();
            },500)
        };
        let step1 = function(){
            viewer.camera.flyTo({
                destination: Cesium.Cartesian3.fromDegrees( 10*.***7267, 29.***2640, 4*5.1***9071292 ),
                orientation: {
                    heading: Cesium.Math.toRadians(  1**.**274808139827 ),
                    pitch: Cesium.Math.toRadians( -11.**085162 ),
                    roll: 0
                },
                complete: function () {
                    setTimeout( ()=>{
                        step2(step3);
                    },500)
                }
            });
        };
        let step2 = function(fun){
            let layer = _this.viewer.scene.layers.find("原来的图层");
            if( layer){
                layer.visible = false;
            }
            fun();
        };
        let step3 = function(){
            _this.viewer.entities.add({
                id:"gltf",
                position: Cesium.Cartesian3.fromDegrees(10*.**77714216316,29.**15177926754, 209),
                orientation: Cesium.Transforms.headingPitchRollQuaternion( Cesium.Cartesian3.fromDegrees(106.***714216316,29.**5177926754,209),new Cesium.HeadingPitchRoll(0, 0, 0)),
                model: {
                    uri: "static/gltf/scene1.gltf",
                }
            });
        };
        let step4 = function(){
            let layer = _this.viewer.scene.layers.find("原来的图层");
            if( layer){
                layer.visible = true;
            }
        };
        
        step0();
       
    },
    end:function(){
        let entity = this.viewer.entities.getById("gltf");
        if (entity) {
          this.viewer.entities.remove(entity);
        }
        let layer = this.viewer.scene.layers.find("原来的图层");
        if( layer){
            layer.visible = true;
        }
    }
}
*/
/* 
// 这么写有问题ConstructSimul.prototype会让类的原型改变,需要用constrstor指回去
ConstructSimul.prototype = {
    start(){
        let _this = this;
        let viewer = this.viewer;
        let step0 = function(){
            setTimeout( ()=>{
                step1();
            },500)
        };
        let step1 = function(){
            viewer.camera.flyTo({
                destination: Cesium.Cartesian3.fromDegrees( 10*.***7267, 29.***2640, 4*5.1***9071292 ),
                orientation: {
                    heading: Cesium.Math.toRadians(  1**.**274808139827 ),
                    pitch: Cesium.Math.toRadians( -11.**085162 ),
                    roll: 0
                },
                complete: function () {
                    setTimeout( ()=>{
                        step2(step3);
                    },500)
                }
            });
        };
        let step2 = function(fun){
            let layer = _this.viewer.scene.layers.find("原来的图层");
            if( layer){
                layer.visible = false;
            }
            fun();
        };
        let step3 = function(){
            _this.viewer.entities.add({
                id:"gltf",
                position: Cesium.Cartesian3.fromDegrees(10*.**77714216316,29.**15177926754, 209),
                orientation: Cesium.Transforms.headingPitchRollQuaternion( Cesium.Cartesian3.fromDegrees(106.***714216316,29.**5177926754,209),new Cesium.HeadingPitchRoll(0, 0, 0)),
                model: {
                    uri: "static/gltf/scene1.gltf",
                }
            });
        };
        let step4 = function(){
            let layer = _this.viewer.scene.layers.find("原来的图层");
            if( layer){
                layer.visible = true;
            }
        };
        
        step0();
       
    },
    
    end(){
        let entity = this.viewer.entities.getById("gltf");
        if (entity) {
          this.viewer.entities.remove(entity);
        }
        let layer = this.viewer.scene.layers.find("原来的图层");
        if( layer){
            layer.visible = true;
        }
    }

} 
*/
export default ConstructSimul

调用:

this.constructSimul = new ConstructSimulCLASS( viewer );
//开始模拟建筑
this.constructSimul.start();
//删除模拟建筑
 this.constructSimul.end();

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值