//****************************三角测量 ************************************************//
var removeImageryLayers = []
var handler = null
var measureTriangle = function (viewer) {
let trianArr = [];
let distanceLineNum = 0;
let XLine;
let X, Y, H;
let MouseHeight, lat, lng
let A, B
handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
handler.setInputAction(function (movement) {
distanceLineNum++;
let cartesian = viewer.scene.pickPosition(movement.position);
let cartographic = Cesium.Cartographic.fromCartesian(cartesian);
lng = Cesium.Math.toDegrees(cartographic.longitude); // 经度
lat = Cesium.Math.toDegrees(cartographic.latitude); // 纬度
MouseHeight = cartographic.height; // 高度
console.log(lng, lat, MouseHeight);
if (distanceLineNum === 1) {
trianArr.push(lng, lat, MouseHeight);
XLine = viewer.entities.add({
id: 'triangleLine',
polyline: {
//由回调函数进行懒惰评估
positions: new Cesium.CallbackProperty(function () {
if (MouseHeight > trianArr[2]) {
return Cesium.Cartesian3.fromDegreesArrayHeights([trianArr[0], trianArr[1], trianArr[2], trianArr[0], trianArr[1], MouseHeight, A, B, MouseHeight, trianArr[0], trianArr[1], trianArr[2]]);
} else {
return Cesium.Cartesian3.fromDegreesArrayHeights([trianArr[0], trianArr[1], trianArr[2], A, B, trianArr[2], A, B, MouseHeight, trianArr[0], trianArr[1], trianArr[2]]);
}
//返回给定一组经度,纬度和高度值的Cartesian3位置数组,其中经度和纬度以度为单位给出。/Cartesian3返回笛卡尔坐标
//true当回调函
最新版本cesium+三角测量
最新推荐文章于 2024-06-28 09:26:13 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)