需求:奔来有个建筑,换成其他建筑。特点是整个过程是动态的。
思路:
第一步:视角移动过去
第二部:隐藏原来建筑
第三步:显示新的建筑
特点:特点是整个过程是动态的; 每步之间有先后顺序。已经封装为类了
封装的代码:
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();