设置初始视角
var homeCameraView = {
destination : new Cesium.Cartesian3(1332761.6877998516, -4662399.913291841, 4137888.8927274314), //世界坐标系下的一个坐标点
orientation : {//旋转角度
heading : 0.6068261546578739,
pitch : -0.6663290837739155,
roll : 0.0
}
};
// viewer.scene.camera.setView(homeCameraView);
// viewer.camera.setView(homeCameraView);
设置默认视角
在cesium.js中大约十四万一千五百行左右中,更改 camera的 Camera.DEFAULT_VIEW_RECTANGLE 属性
Camera.DEFAULT_VIEW_RECTANGLE = new Cesium.Rectangle.fromDegrees(119.79711769553197, 31.48090108132136,121.10322965960965, 30.611922615196686);//homebutton默认跳转位置
// new Cesium.Rectangle.fromDegrees(point1[0],point1[1],point2[0],point2[1])
获取当前视野边界
var pt1 = new Cesium.Cartesian2(0,0);
var pt2 = new Cesium.Cartesian2(500,500);
var pick1 = viewer.scene.globe.pick(viewer.camera.getPickRay(pt1), viewer.scene);
var pick2 = viewer.scene.globe.pick(viewer.camera.getPickRay(pt2), viewer.scene);
//将三维坐标转成地理坐标
var geoPt1 = viewer.scene.globe.ellipsoid.cartesianToCartographic(pick1);
var geoPt2 = viewer.scene.globe.ellipsoid.cartesianToCartographic(pick2);
//地理坐标转换为经纬度坐标
var point1 = [geoPt1.longitude / Math.PI * 180,geoPt1.latitude / Math.PI * 180];
var point2 = [geoPt2.longitude / Math.PI * 180,geoPt2.latitude / Math.PI * 180];