一切都在3D模式下很好用,但是我切换到2d模式,globe继续转换。我想在实例中使用fly或者我必须使用Rectangle方法。当我点击2d我想留在当前位置。有任何想法吗?添加更多代码,以便你们可以找出问题所在。
private getCurrentCameraState(){
if (this.map.scene.mode === 3) {
return {
x: this.map.camera.position.x,
y: this.map.camera.position.y,
z: this.map.camera.position.z,
heading: this.map.camera.heading,
pitch: this.map.camera.pitch,
roll: this.map.camera.roll
};
} else {
return {
x: this.map.camera.position.x,
y: this.map.camera.position.y,
z: this.map.camera.position.z
};
}
}
private applyCameraState(cameraState: ICameraState) {
if (
cameraState && this.map.scene.mode === 2) {
console.log('2d');
const destination = new Cesium.Cartesian3(
cameraState.x,
cameraState.y,
cameraState.z
);
// this.globeDispatcher.setCameraTransition(true);
this.map.camera.cancelFlight();
this.map.camera.flyTo({
destination: destination,
complete: () => this.globeDispatcher.setCameraTransition(false)
});
} else if (cameraState &&
!isEqual(cameraState, this.getCurrentCameraState()) && this.map.scene.mode === 3) {
console.log('3d')
const destination = new Cesium.Cartesian3(
cameraState.x,
cameraState.y,
cameraState.z
);
this.globeDispatcher.setCameraTransition(true);
this.map.camera.cancelFlight();
this.map.camera.flyTo({
destination: destination,
orientation: {
heading: cameraState.heading,
pitch: cameraState.pitch,
roll: cameraState.roll
},
pitchAdjustHeight: this.globeConfig.flyToPitchAdjustHeight, // Point Towards the Earth during flight
duration: this.globeConfig.flyToDuration,
complete: () => this.globeDispatcher.setCameraTransition(false)
})
} else if (cameraState === undefined) {
console.log('undefined')
// Initialize camera state if undefined
this.globeDispatcher.setCesiumCameraState(
this.getCurrentCameraState()
);
}
}
你有没有尝试添加一个小的超时:
scene.morphComplete.addEventListener(function() {
setTimeout(function() {
camera.flyTo({
destination: Cesium.Cartesian3.fromDegrees(-74.0, 41.0, 15000.0)
});
}, 300);
});