cesium 实现相机水平高度向东南西北方位移动

固定坐标系

var currentHeading = viewer.camera.heading;
    var currentPitch = viewer.camera.pitch;
    var currentRoll = viewer.camera.roll;
    var currentPosition = viewer.camera.position;
    // 在ENU坐标系中创建一个指向北的单位向量
    var northVectorENU = new window.Cesium.Cartesian3(0.0, 1.0, 0.0); // 向北移动
    var southVectorENU = new window.Cesium.Cartesian3(0.0, -1.0, 0.0); // 向南移动
    var eastVectorENU = new window.Cesium.Cartesian3(1.0, 0.0, 0.0); // 向东移动
    var westVectorENU = new window.Cesium.Cartesian3(-1.0, 0.0, 0.0); // 向西移动
    // 创建变换矩阵,用于从ENU坐标系到固定参考坐标系的转换
    var enuToFixedMatrix = window.Cesium.Transforms.eastNorthUpToFixedFrame(currentPosition, viewer.scene.globe.ellipsoid);
    let northVectorFixed: any
    // 使用变换矩阵将向量从ENU坐标系转换到固定参考坐标系
    switch (num) {
        case 1:
            northVectorFixed = window.Cesium.Matrix4.multiplyByPointAsVector(enuToFixedMatrix, northVectorENU, new window.Cesium.Cartesian3());    // 向北移动
            break;
        case 2:
            northVectorFixed = window.Cesium.Matrix4.multiplyByPointAsVector(enuToFixedMatrix, southVectorENU, new window.Cesium.Cartesian3());       // 向南移动
            break;
        case 3:
            northVectorFixed = window.Cesium.Matrix4.multiplyByPointAsVector(enuToFixedMatrix, eastVectorENU, new window.Cesium.Cartesian3());    // 向东移动
            break;
        case 4:
            northVectorFixed = window.Cesium.Matrix4.multiplyByPointAsVector(enuToFixedMatrix, westVectorENU, new window.Cesium.Cartesian3());    // 向西移动
            break;
    }
    // 将向量缩放到所需的距离
    northVectorFixed = window.Cesium.Cartesian3.multiplyByScalar(northVectorFixed, 1000, northVectorFixed);
    // 创建新位置
    var newPosition = window.Cesium.Cartesian3.add(currentPosition, northVectorFixed, new window.Cesium.Cartesian3());
    // 设置新的相机视图
    viewer.camera.setView({
        destination: newPosition,
        orientation: {
            heading: currentHeading,
            pitch: currentPitch,
            roll: currentRoll
        }
    });

经纬度

 var currentHeading = viewer.camera.heading;
  var currentPitch = viewer.camera.pitch;
  var currentRoll = viewer.camera.roll;
  var currentPosition = viewer.camera.position;
  // 创建一个Cartesian3 clone of the current position
  var newPosition = window.Cesium.Cartesian3.clone(currentPosition);
  // 将位置转换为地理坐标
  var ellipsoid = viewer.scene.globe.ellipsoid;
  var cartographic = ellipsoid.cartesianToCartographic(newPosition);
  // 向北 
  cartographic.latitude += window.Cesium.Math.toRadians(1);   //   向北 1 向南 -1
  // 增加经度(向东移动)
  // cartographic.longitude +=  window.Cesium.Math.toRadians(1); //    向东 1 向西 -1
  // 将新的地理坐标转换回Cartesian3
  newPosition = ellipsoid.cartographicToCartesian(cartographic);
  // 设置新的相机视图
  viewer.camera.setView({
    destination: newPosition,
    heading: currentHeading,
    pitch: currentPitch,
    roll: currentRoll
  });

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值