Spherical是cesiumjs中用来表示球面坐标系的类,包括经度、纬度、高度等属性。
导入Spherical类
import { Spherical } from 'cesium';
创建Spherical实例
const spherical = new Spherical(lon, lat, height);
参数说明:
获取和设置经度、纬度、高度
// 获取经度、纬度、高度
const lon = spherical.longitude;
const lat = spherical.latitude;
const height = spherical.height;
// 设置经度、纬度、高度
spherical.longitude = newLon;
spherical.latitude = newLat;
spherical.height = newHeight;
转换为笛卡尔坐标系
const cartesian3 = new Cesium.Cartesian3();
Cesium.Cartesian3.fromSpherical(spherical, cartesian3);
转换为字符串
const str = spherical.toString();
克隆Spherical实例
const newSpherical = spherical.clone();
import { Spherical, Cartesian3 } from 'cesium';
// 创建Spherical实例
const spherical = new Spherical(Math.PI, Math.PI / 2, 5000);
// 获取经度、纬度、高度
const { longitude, latitude, height } = spherical;
console.log(longitude, latitude, height);
// 设置经度、纬度、高度
spherical.longitude = 0;
spherical.latitude = Math.PI / 4;
spherical.height = 10000;
// 转换为笛卡尔坐标系
const cartesian3 = new Cartesian3();
Cartesian3.fromSpherical(spherical, cartesian3);
console.log(cartesian3.x, cartesian3.y, cartesian3.z);
// 转换为字符串
const str = spherical.toString();
console.log(str);
// 克隆Spherical实例
const newSpherical = spherical.clone();
console.log(newSpherical);