1.获取相机参数
function getcameraPosInfo () {
let head = viewer.scene.camera.heading
let pitch = viewer.scene.camera.pitch
let roll = viewer.scene.camera.roll
let info = { head: head, pitch: pitch, roll: roll }
// 获取位置 wgs84的地心坐标系,x,y坐标值以弧度来表示
let position = viewer.scene.camera.positionCartographic // with longitude and latitude expressed in radians and height in meters.
// 以下方式也可以获取相机位置只是返回的坐标系不一样
// var position = viewer.scene.camera.position //cartesian3 空间直角坐标系
// var ellipsoid = scene.globe.ellipsoid;
=ellipsoid.cartesianToCartographic(viewer.scene.camera.position)//
let longitude = Cesium.Math.toDegrees(position.longitude)
let latitude = Cesium.Math.toDegrees(position.latitude)
let height = position.height
return { lng: longitude, lat: latitude, h: height, mat: info }
2.获取相机中心点坐标
let ellipsoid = scene.globe.ellipsoid
let height = ellipsoid.cartesianToCartographic(viewer.camera.position).height
function getCenterPosition () {
let result = viewer.camera.pickEllipsoid(new Cesium.Cartesian2(viewer.canvas.clientWidth / 2, viewer.canvas.clientHeight / 2))
let curPosition = Cesium.Ellipsoid.WGS84.cartesianToCartographic(result)
let lon = curPosition.longitude * 180 / Math.PI
let lat = curPosition.latitude * 180 / Math.PI
3.锁定和解除锁定相机视角
let center = Cesium.Cartesian3.fromDegrees(prosition.lon, prosition.lat)
let heading = Cesium.Math.toRadians(parseFloat(heading_show.value))
let pitch = Cesium.Math.toRadians(-45.0)
let range = prosition.height
viewer.camera.lookAt(center, new Cesium.HeadingPitchRange(heading, pitch, range))
viewer.camera.lookAtTransform(Cesium.Matrix4.IDENTITY)
4.3D场景和2D场景切换
viewer.scene.mode = Cesium.SceneMode.SCENE3D
viewer.scene.mode = Cesium.SceneMode.SCENE2D
5.获取相机位置,姿态
function getcameraPosInfo () {
let head = viewer.scene.camera.heading
let pitch = viewer.scene.camera.pitch
let roll = viewer.scene.camera.roll
let info = { head: head, pitch: pitch, roll: roll }
let position = viewer.scene.camera.positionCartographic
let longitude = Cesium.Math.toDegrees(position.longitude)
let latitude = Cesium.Math.toDegrees(position.latitude)
let height = position.height
return { lon: longitude, lat: latitude, height: height, mat: info }