Cesium Note15:放大缩小

Cesium Note15:放大缩小

缩放

  • 这种直接方法,效果很突然
const zoomin = () => { // 获取当前镜头位置的笛卡尔坐标 let cameraPos = proxy.viewer.camera.position; // 获取当前坐标系标准 let ellipsoid = proxy.viewer.scene.globe.ellipsoid; // 根据坐标系标准,将笛卡尔坐标转换为地理坐标 let cartographic = ellipsoid.cartesianToCartographic(cameraPos); // 获取镜头的高度 let height = cartographic.height; // if (height < 40) { // return // } // 镜头拉近 proxy.viewer.camera.zoomIn(height / 1.8); } const zoomin = () => { // 获取当前镜头位置的笛卡尔坐标 let cameraPos = proxy.viewer.camera.position; // 获取当前坐标系标准 let ellipsoid = proxy.viewer.scene.globe.ellipsoid; // 根据坐标系标准,将笛卡尔坐标转换为地理坐标 let cartographic = ellipsoid.cartesianToCartographic(cameraPos); // 获取镜头的高度 let height = cartographic.height; // if (height < 40) { // return // } // 镜头拉近 proxy.viewer.camera.zoomIn(height * 1.2); }

缩放优化

镜头拉近、远离
const zoomin = () => { // 获取当前镜头位置的笛卡尔坐标 let cameraPos = proxy.viewer.camera.position; // 获取当前坐标系标准 let ellipsoid = proxy.viewer.scene.globe.ellipsoid; // 根据坐标系标准,将笛卡尔坐标转换为地理坐标 let cartographic = ellipsoid.cartesianToCartographic(cameraPos); let lon = Cesium.Math.toDegrees(cartographic.longitude); let lat = Cesium.Math.toDegrees(cartographic.latitude); // 获取镜头的高度 let height = cartographic.height; proxy.viewer.camera.flyTo({ destination: Cesium.Cartesian3.fromDegrees(lon, lat, height / 1.8), duration: 1.0 }) const zoomout = () => { // 获取当前镜头位置的笛卡尔坐标 let cameraPos = proxy.viewer.camera.position; // 获取当前坐标系标准 let ellipsoid = proxy.viewer.scene.globe.ellipsoid; // 根据坐标系标准,将笛卡尔坐标转换为地理坐标 let cartographic = ellipsoid.cartesianToCartographic(cameraPos); let lon = Cesium.Math.toDegrees(cartographic.longitude); let lat = Cesium.Math.toDegrees(cartographic.latitude); // 获取镜头的高度 let height = cartographic.height; proxy.viewer.camera.flyTo({ destination: Cesium.Cartesian3.fromDegrees(lon, lat, height * 1.2), duration: 1.0 })