Cesium切换视角中心点不变

1. 倾斜

2. 回正

实现思路

在改变相机视角前,用相机高度和三角函数计算出一个偏移量,改变中心点的经纬度即可

javascript 复制代码
/**
     * 静态工具:根据俯仰角切换相机视角
     * @param {Cesium.Viewer} viewer Cesium Viewer
     * @param {number} lng   经度
     * @param {number} lat   纬度
     * @param {number} alt   高度(米)
     * @param {number} pitchDeg 俯仰角(角度制,-90 垂直向下)
     */
    static updateCameraByPerspective(viewer, lng, lat, alt, pitchDeg) {
        if (!viewer || typeof pitchDeg !== 'number') return;

        const pitch = Cesium.Math.toRadians(pitchDeg);
        let position = Cesium.Cartesian3.fromDegrees(lng, lat, alt);

        // 非 90° 俯视时修正位置
        const absPitch = Math.abs(pitchDeg);
        if (absPitch < 89) {
            const offset = alt / Math.tan(absPitch * Math.PI / 180);
            const heading = viewer.camera.heading;
            const offsetX = -offset * Math.sin(heading);
            const offsetY = -offset * Math.cos(heading);
            const enu = Cesium.Transforms.eastNorthUpToFixedFrame(position);
            const offsetVec = new Cesium.Cartesian3(offsetX, offsetY, 0);
            position = Cesium.Matrix4.multiplyByPoint(enu, offsetVec, new Cesium.Cartesian3());
        }

        viewer.camera.flyTo({
            destination: position,
            orientation: {
                heading: viewer.camera.heading,
                pitch,
                roll: 0
            }
        });
    }
相关推荐
用户61595868000222 天前
Cesium 入门系列(四):区域高亮显示的两种实现方案
cesium
用户61595868000222 天前
Cesium 入门(三):BaseLayerPicker 底图切换与国产地图接入
cesium
用户61595868000222 天前
Cesium 入门(二):Geocoder 搜索框参数详解与天地图搜索接入
cesium
灵境(虚幻知音)3 天前
Cesium动态轨迹性能瓶颈深度拆解:翼带与尾迹的底层优化实践
性能优化·cesium·3d引擎·afsim·翼带·尾迹·自定义着色器
fxshy5 天前
WebGIS 游戏化实践:基于 Cesium + Vue3 实现全球飞行模拟系统:从球体坐标、飞行动力学到地形碰撞实战
游戏·vue3·cesium·webgis·飞行模拟
用户83134859306986 天前
Cesium实现动态流动火烧云晚霞效果(可用slider调整火烧云浓度)
vue.js·webgl·cesium
CBX8 天前
Cesium 入门实战:GeoJSON 数据加载与地区边界可视化
cesium
毕安格 - BimAngle14 天前
国家电网 GIM 格式模型一键输出 3D Tiles (for Cesium) 和 glTF/glb 更新时间:2026-08-18
3d·gis·cesium·gltf·glb·3d tiles·gim
探索前端15 天前
3dtiles加载时被地形遮挡问题研究及处理思路
前端·3d·cesium
兔年鸿运Q小Q24 天前
cesium1.140以上版本加载地形
arcgis·cesium