cesium SceneModePicker工具切换哥伦布视图 2D 3D时摄像机定位指定位置
1.设置动画延时
viewer.sceneModePicker.viewModel.duration = 0;
Cesium.Camera.DEFAULT_VIEW_RECTANGLE = Cesium.Rectangle.fromDegrees(80, 22, 130, 50);
Cesium.Camera.DEFAULT_VIEW_FACTOR = 0.1; // 摄像机到地图的距离放大倍数
viewer.camera.flyHome(0);
viewer.sceneModePicker.viewModel.duration = 0.0;//去掉二三维切换动画效果
设置这个参数,二三维切换的时候位置就会保持原来的了
原理: cesium底层的代码做了一个判断,如果延时参数大于0,就缩放到全球显示一个切换动画,设成0就没这个动画了
2.结合sceneModePicker事件
Command
viewer.sceneModePicker.viewModel.morphTo2D.beforeExecute.addEventListener(function(a) {
viewer.camera.setView({
destination: Cesium.Cartesian3.fromDegrees(105, 33, 10000000)
});
});
viewer.sceneModePicker.viewModel.morphToColumbusView.beforeExecute.addEventListener(function(a) {
viewer.camera.setView({
destination: Cesium.Cartesian3.fromDegrees(105, 33, 10000000)
});
});
viewer.sceneModePicker.viewModel.morphTo3D.beforeExecute.addEventListener(function(a) {
viewer.camera.setView({
destination: Cesium.Rectangle.fromDegrees(80, 22, 130, 50),
});
});