klren0312 / daliy_knowledge

知识积累,正确使用方式是watch
21 stars 4 forks source link

cesium 获取当前相机位置 #862

Open klren0312 opened 1 week ago

klren0312 commented 1 week ago
function getcameraPosInfo(){
  // 获取 相机姿态信息
  const head = viewer.scene.camera.heading 
  const pitch = viewer.scene.camera.pitch
  const roll  = viewer.scene.camera.roll
  const info ={'head': head ,'pitch': pitch ,'roll': roll};
  // 获取位置 wgs84的地心坐标系,x,y坐标值以弧度来表示
  const position = viewer.scene.camera.positionCartographic //with longitude and latitude expressed in radians and height in meters.

  // 弧度转经纬度
  const longitude = Cesium.Math.toDegrees(position.longitude).toFixed(6)
  const latitude =  Cesium.Math.toDegrees(position.latitude).toFixed(6)
  const height = position.height
  console.log({
    lng: longitude,
    lat:latitude,
    h:height,
    mat:info
  })
}