|
@@ -1,13 +1,40 @@
|
|
|
<template>
|
|
|
- <div class="ZTGlobal" style="width: 100%; padding: 1rem 1rem 0rem 1rem; color: white">
|
|
|
+ <div
|
|
|
+ class="ZTGlobal"
|
|
|
+ style="width: 100%; padding: 1rem 1rem 0rem 1rem; color: white"
|
|
|
+ >
|
|
|
<el-row :gutter="10">
|
|
|
- <el-col :span="6"><el-button size="mini" type="default" @click="getGCZ">添加观察点</el-button>
|
|
|
+ 观察者高度(米):
|
|
|
+ <el-input-number
|
|
|
+ size="small"
|
|
|
+ label="观察者高度:"
|
|
|
+ min="0"
|
|
|
+ max="50"
|
|
|
+ :step="0.5"
|
|
|
+ precision="1"
|
|
|
+ v-model="personH"
|
|
|
+ ></el-input-number>
|
|
|
+ </el-row>
|
|
|
+ <el-row :gutter="10">
|
|
|
+ <el-col :span="6"
|
|
|
+ ><el-button size="mini" type="default" @click="addGCD"
|
|
|
+ >添加观察点</el-button
|
|
|
+ >
|
|
|
+ </el-col>
|
|
|
+ <el-col :span="6"
|
|
|
+ ><el-button size="mini" type="default" @click="addTagget"
|
|
|
+ >添加目标点</el-button
|
|
|
+ >
|
|
|
</el-col>
|
|
|
<el-col :span="5.5">
|
|
|
- <el-button size="mini" type="default">切换视角</el-button>
|
|
|
+ <el-button size="mini" type="default" @click="changeView"
|
|
|
+ >切换视角</el-button
|
|
|
+ >
|
|
|
</el-col>
|
|
|
<el-col :span="4">
|
|
|
- <el-button size="mini" type="default" @click="clearScope">清除</el-button>
|
|
|
+ <el-button size="mini" type="default" @click="clearScope"
|
|
|
+ >清除</el-button
|
|
|
+ >
|
|
|
</el-col>
|
|
|
</el-row>
|
|
|
</div>
|
|
@@ -20,13 +47,18 @@ import {
|
|
|
mercator2lonLat,
|
|
|
undergroundMode,
|
|
|
} from "@/utils/MapHelper/MapHelper.js";
|
|
|
-import { point, distance } from "@turf/turf";
|
|
|
-let handlerLine = null; //绘制线
|
|
|
+// import { point, distance } from "@turf/turf";
|
|
|
+let handlerPoint = null; //绘制线
|
|
|
+var sightline;
|
|
|
export default {
|
|
|
data() {
|
|
|
return {
|
|
|
tooltip: createTooltip(document.body),
|
|
|
points: [],
|
|
|
+ addViewFlag: false, //当前点击状态是否是 添加观察点
|
|
|
+ addTargetFlag: false, //当前点击状态是否是 添加目标点,
|
|
|
+ personH: 1.8,
|
|
|
+ isFrom2To: true,
|
|
|
};
|
|
|
},
|
|
|
props: {
|
|
@@ -54,356 +86,233 @@ export default {
|
|
|
},
|
|
|
},
|
|
|
computed: {},
|
|
|
- mounted() { },
|
|
|
+ mounted() {
|
|
|
+ sightline = new Cesium.Sightline(scene);
|
|
|
+ sightline.lin;
|
|
|
+ handlerPoint = new Cesium.DrawHandler(viewer, Cesium.DrawMode.Point);
|
|
|
+ scene.undergroundMode = false;
|
|
|
+ },
|
|
|
methods: {
|
|
|
- getGCZ() {
|
|
|
+ /**
|
|
|
+ * 添加观察点
|
|
|
+ */
|
|
|
+ addGCD() {
|
|
|
let that = this;
|
|
|
- that.clearScope();
|
|
|
- handlerLine = new Cesium.DrawHandler(
|
|
|
- viewer,
|
|
|
- Cesium.DrawMode.Line,
|
|
|
- Cesium.ClampMode.Space
|
|
|
- );
|
|
|
- handlerLine.activate();
|
|
|
- handlerLine.activeEvt.addEventListener(function (isActive) {
|
|
|
- if (isActive == true) {
|
|
|
- // viewer.enableCursorStyle = false;
|
|
|
- // viewer._element.style.cursor = "";
|
|
|
- document.body.classList.add("drawCur");
|
|
|
- } else {
|
|
|
- // viewer.enableCursorStyle = true;
|
|
|
- document.body.classList.remove("drawCur");
|
|
|
- }
|
|
|
- });
|
|
|
- handlerLine.movingEvt.addEventListener((windowPosition) => {
|
|
|
- that.tooltip.showAt(
|
|
|
- windowPosition,
|
|
|
- "<p>点击鼠标左键开始绘制分析视角,右键结束</p>"
|
|
|
- );
|
|
|
- });
|
|
|
- handlerLine.drawEvt.addEventListener((result) => {
|
|
|
- that.tooltip.setVisible(false);
|
|
|
- var line = result.object;
|
|
|
- if (!line) {
|
|
|
- return;
|
|
|
- }
|
|
|
- // that.points = polygon.positions;
|
|
|
- //遍历多边形,取出所有点
|
|
|
- for (var i = 0, len = line.positions.length; i < len; i++) {
|
|
|
- let xyz = cartesian3ToWGS84(line.positions[i]);
|
|
|
- that.points.push([xyz.lng, xyz.lat, xyz.alt]);
|
|
|
- }
|
|
|
- that.ComputationalPerspective(that.points);
|
|
|
- });
|
|
|
+ sightline.removeAllTargetPoint();
|
|
|
+ that.addViewFlag = true;
|
|
|
+ that.addTargetFlag = false;
|
|
|
+ that.isFrom2To = true;
|
|
|
+ if (handlerPoint) handlerPoint.clear();
|
|
|
+ that.setInput();
|
|
|
},
|
|
|
/**
|
|
|
- * 计算方位角
|
|
|
- * @param {} points
|
|
|
+ * //笛卡尔转换为经纬度
|
|
|
+ * @param {*} position
|
|
|
*/
|
|
|
- ComputationalPerspective(points) {
|
|
|
- debugger
|
|
|
- // A点坐标
|
|
|
- var positionA = Cesium.Cartesian3.fromDegrees(
|
|
|
- points[0][0],
|
|
|
- points[0][1],
|
|
|
- points[0][2]
|
|
|
- );
|
|
|
- // B点坐标
|
|
|
- var positionB = Cesium.Cartesian3.fromDegrees(
|
|
|
- points[1][0],
|
|
|
- points[1][1],
|
|
|
- points[1][2]
|
|
|
- );
|
|
|
- console.log("相机Pitch"+ viewer.camera.pitch*180/Math.PI )
|
|
|
- console.log("相机heading"+ viewer.camera.heading *180/Math.PI )
|
|
|
- // var center = Cesium.Cartesian3.fromDegrees(points[1][0], points[1][1], points[1][2]);
|
|
|
- // var target = Cesium.Cartesian3.fromDegrees(points[1][0], points[1][1], points[1][2]);
|
|
|
- var datx = positionA.x - positionB.x;
|
|
|
- var daty = positionA.y - positionB.y;
|
|
|
- var datz = positionA.z - positionB.z;
|
|
|
-
|
|
|
-
|
|
|
- //获取相机方位角
|
|
|
- var heading = Math.atan2((points[1][1] - points[0][1]), (points[1][0] - points[0][0]))
|
|
|
- // if(heading < 0)
|
|
|
- // heading =Math.PI/2- heading
|
|
|
-
|
|
|
-
|
|
|
- heading=this.computeHeading(points[0][0], points[0][1], points[1][0], points[1][1])+Math.PI/2;
|
|
|
- var angle = heading * 180 / Math.PI
|
|
|
-
|
|
|
- console.log("计算角度" + angle)
|
|
|
- // heading=(position)
|
|
|
- //获取相机的俯仰角
|
|
|
- var len=Math.sqrt(Math.pow((points[1][1] - points[0][1]),2)+Math.pow((points[1][0] - points[0][0]),2))
|
|
|
- var pitch =Math.atan2(points[1][2]-points[0][2],len)
|
|
|
- //获取相机旋转角度
|
|
|
- var roll = 0.0;
|
|
|
- debugger
|
|
|
- viewer.camera.setView({
|
|
|
- destination: positionA,
|
|
|
- orientation: {
|
|
|
- heading: heading, // east, default value is 0.0 (north)
|
|
|
- pitch:0, // default value (looking down)
|
|
|
- roll: 0.0 // default value
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- // // 计算从A到B的向量
|
|
|
- // var subtract = Cesium.Cartesian3.subtract(
|
|
|
- // position2,
|
|
|
- // position,
|
|
|
- // new Cesium.Cartesian3()
|
|
|
- // );
|
|
|
- // var direction = Cesium.Cartesian3.normalize(
|
|
|
- // subtract,
|
|
|
- // new Cesium.Cartesian3()
|
|
|
- // ); // 转换为单位向量
|
|
|
-
|
|
|
- // // 计算朝向(假设Cesium.Cartesian3.UNIT_Z为上方,可能需要根据实际情况调整)
|
|
|
- // var heading = Cesium.Math.toDegrees(
|
|
|
- // Cesium.Cartesian3.angleBetween(direction, Cesium.Cartesian3.UNIT_X)
|
|
|
- // );
|
|
|
- // if (
|
|
|
- // Cesium.Cartesian3.dot(
|
|
|
- // direction,
|
|
|
- // Cesium.Cartesian3.cross(
|
|
|
- // Cesium.Cartesian3.UNIT_X,
|
|
|
- // Cesium.Cartesian3.UNIT_Z,
|
|
|
- // new Cesium.Cartesian3()
|
|
|
- // )
|
|
|
- // ) < 0
|
|
|
- // ) {
|
|
|
- // heading = (360 - heading) % 360; // 如果需要,调整heading到0-360度范围
|
|
|
- // }
|
|
|
-
|
|
|
- // // 计算倾斜
|
|
|
-
|
|
|
- // let heightDifference = points[0][2] - points[1][2];
|
|
|
- // var from = point([points[0][0], points[0][1]]);
|
|
|
- // var to = point([points[1][0], points[1][1]]);
|
|
|
- // var options = { units: "kilometers" };
|
|
|
-
|
|
|
- // var horizontalDistance = distance(from, to, options) * 1000;
|
|
|
- // var pitch = Cesium.Math.toDegrees(
|
|
|
- // Math.atan2(heightDifference, horizontalDistance)
|
|
|
- // );
|
|
|
-
|
|
|
- // 设置相机视角
|
|
|
- // viewer.camera.setView({
|
|
|
- // destination: positionB,
|
|
|
- // orientation: {
|
|
|
- // heading: heading,
|
|
|
- // pitch: pitch,
|
|
|
- // roll: 0.0,
|
|
|
- // },
|
|
|
- // });
|
|
|
+ Cartesian2toDegrees(position) {
|
|
|
+ var cartographic = Cesium.Cartographic.fromCartesian(position);
|
|
|
+ var longitude = Cesium.Math.toDegrees(cartographic.longitude);
|
|
|
+ var latitude = Cesium.Math.toDegrees(cartographic.latitude);
|
|
|
+ var height = cartographic.height;
|
|
|
+ return [longitude, latitude, height];
|
|
|
},
|
|
|
- caculHeading(p0, p1) {
|
|
|
- //计算p0位置的enu位置矩阵的旋转部分
|
|
|
- var defrotmat = Cesium.Matrix4.getRotation(Cesium.Transforms.eastNorthUpToFixedFrame(p0), new Cesium.Matrix3());
|
|
|
|
|
|
- //获取矩阵的三个坐标轴
|
|
|
- var xaxis = Cesium.Matrix3.getColumn(defrotmat, 0, new Cesium.Cartesian3());
|
|
|
- var yaxis = Cesium.Matrix3.getColumn(defrotmat, 1, new Cesium.Cartesian3());
|
|
|
- var zaxis = Cesium.Matrix3.getColumn(defrotmat, 2, new Cesium.Cartesian3());
|
|
|
-
|
|
|
- //两个位置点的射线方向
|
|
|
- var dir = Cesium.Cartesian3.subtract(p1, p0, new Cesium.Cartesian3());
|
|
|
-
|
|
|
- //计算在 enu 旋转矩阵上的 x y 平面上的投影向量
|
|
|
- dir = Cesium.Cartesian3.cross(dir, zaxis, dir);
|
|
|
- dir = Cesium.Cartesian3.cross(zaxis, dir, dir);
|
|
|
+ /**
|
|
|
+ * 添加目标点
|
|
|
+ */
|
|
|
+ addTagget() {
|
|
|
+ let that = this;
|
|
|
+ that.addViewFlag = false;
|
|
|
+ that.addTargetFlag = true;
|
|
|
|
|
|
- //归一化
|
|
|
- dir = Cesium.Cartesian3.normalize(dir, dir);
|
|
|
+ that.setInput();
|
|
|
+ },
|
|
|
+ setInput() {
|
|
|
+ var that = this;
|
|
|
+ handlerPoint = new Cesium.DrawHandler(viewer, Cesium.DrawMode.Point);
|
|
|
+ handlerPoint.activate();
|
|
|
+ handlerPoint.drawEvt.addEventListener(function (result) {
|
|
|
+ var point = result.object;
|
|
|
+ // point.show = false;
|
|
|
+ var position = result.object.position;
|
|
|
|
|
|
- //计算和x轴夹角 0 ~ pi
|
|
|
- var heading = Cesium.Cartesian3.angleBetween(xaxis, dir);
|
|
|
+ debugger;
|
|
|
|
|
|
- //和y轴夹角 判定在y轴的正方向还是负方向
|
|
|
- var ay = Cesium.Cartesian3.angleBetween(yaxis, dir);
|
|
|
+ //将获取的点的位置转化成经纬度
|
|
|
+ var cartographic = that.Cartesian2toDegrees(position);
|
|
|
+ if (cartographic[2] < 0) cartographic[2] = 0;
|
|
|
+ //添加观察点
|
|
|
+ if (that.addViewFlag) {
|
|
|
+ //设置观察点
|
|
|
+ cartographic[2] += that.personH;
|
|
|
+ sightline.viewPosition = cartographic;
|
|
|
+ that.addViewFlag = false;
|
|
|
|
|
|
- // 保证处于0~2PI
|
|
|
- // if (ay > Math.PI * 0.5) {
|
|
|
- // heading = Math.PI - heading;
|
|
|
- // }
|
|
|
+ var labelentity = new Cesium.Entity({
|
|
|
+ position: Cesium.Cartesian3.fromDegrees(
|
|
|
+ cartographic[0],
|
|
|
+ cartographic[1],
|
|
|
+ cartographic[2]
|
|
|
+ ),
|
|
|
+ point: {
|
|
|
+ // 点的大小(像素)
|
|
|
+ pixelSize: 10,
|
|
|
+ // 点位颜色,fromCssColorString 可以直接使用CSS颜色
|
|
|
+ color: Cesium.Color.RED,
|
|
|
+ // 边框颜色
|
|
|
+ outlineColor: Cesium.Color.fromCssColorString("#fff"),
|
|
|
+ // 边框宽度(像素)
|
|
|
+ outlineWidth: 2,
|
|
|
+ // 显示在距相机的距离处的属性,多少区间内是可以显示的
|
|
|
+ distanceDisplayCondition: new Cesium.DistanceDisplayCondition(
|
|
|
+ 0,
|
|
|
+ 1500
|
|
|
+ ),
|
|
|
+ // 是否显示
|
|
|
+ show: true,
|
|
|
+ },
|
|
|
+ label: {
|
|
|
+ show: true,
|
|
|
+ text: "观察点",
|
|
|
+ font: "15px sans-serif",
|
|
|
+ pixelOffset: new Cesium.Cartesian2(60, -100), //文字偏移
|
|
|
+ fillColor: Cesium.Color.RED,
|
|
|
+ // backgroundColor:new Cesium.Color(0, 0, 0, 1),
|
|
|
+ distanceDisplayCondition: new Cesium.DistanceDisplayCondition(
|
|
|
+ 0,
|
|
|
+ 1500
|
|
|
+ ), //达到一定高度隐藏
|
|
|
+ },
|
|
|
+ });
|
|
|
+ // that.points.push(entity)
|
|
|
+ // viewer.entities.add(entity);
|
|
|
+ that.points.push(labelentity);
|
|
|
+ viewer.entities.add(labelentity);
|
|
|
+ } else if (that.addTargetFlag) {
|
|
|
+ //添加目标点
|
|
|
+ //设置目标点
|
|
|
+ sightline.addTargetPoint({
|
|
|
+ position: cartographic,
|
|
|
+ name: "目标点",
|
|
|
+ });
|
|
|
|
|
|
- console.log("heading:" + Cesium.Math.toDegrees(heading).toFixed(5));
|
|
|
- return heading;
|
|
|
- },
|
|
|
- computeHeading(lng_a, lat_a, lng_b, lat_b) {
|
|
|
- //以a点为原点建立局部坐标系(东方向为x轴,北方向为y轴,垂直于地面为z轴),得到一个局部坐标到世界坐标转换的变换矩阵
|
|
|
- var localToWorld_Matrix = Cesium.Transforms.eastNorthUpToFixedFrame(new Cesium.Cartesian3.fromDegrees(lng_a, lat_a));
|
|
|
- //求世界坐标到局部坐标的变换矩阵
|
|
|
- var worldToLocal_Matrix = Cesium.Matrix4.inverse(localToWorld_Matrix, new Cesium.Matrix4());
|
|
|
- //a点在局部坐标的位置,其实就是局部坐标原点
|
|
|
- var localPosition_A = Cesium.Matrix4.multiplyByPoint(worldToLocal_Matrix, new Cesium.Cartesian3.fromDegrees(lng_a, lat_a), new Cesium.Cartesian3());
|
|
|
- //B点在以A点为原点的局部的坐标位置
|
|
|
- var localPosition_B = Cesium.Matrix4.multiplyByPoint(worldToLocal_Matrix, new Cesium.Cartesian3.fromDegrees(lng_b, lat_b), new Cesium.Cartesian3());
|
|
|
- //弧度
|
|
|
- var angle = Math.atan2((localPosition_B.y - localPosition_A.y), (localPosition_B.x - localPosition_A.x))
|
|
|
- // //角度
|
|
|
- // var theta = angle * (180 / Math.PI);
|
|
|
- // if (theta < 0) {
|
|
|
- // theta = theta + 360;
|
|
|
- // }
|
|
|
- return angle;
|
|
|
- },
|
|
|
- computePitch(lng_a, lat_a, alt_a, lng_b, lat_b, alt_b) {
|
|
|
- //以a点为原点建立局部坐标系(东方向为x轴,北方向为y轴,垂直于地面为z轴),得到一个局部坐标到世界坐标转换的变换矩阵
|
|
|
- var localToWorld_Matrix = Cesium.Transforms.eastNorthUpToFixedFrame(new Cesium.Cartesian3.fromDegrees(lng_a, lat_a, alt_a));
|
|
|
- //求世界坐标到局部坐标的变换矩阵
|
|
|
- var worldToLocal_Matrix = Cesium.Matrix4.inverse(localToWorld_Matrix, new Cesium.Matrix4());
|
|
|
- //a点在局部坐标的位置,其实就是局部坐标原点
|
|
|
- var localPosition_A = Cesium.Matrix4.multiplyByPoint(worldToLocal_Matrix, new Cesium.Cartesian3.fromDegrees(lng_a, lat_a, alt_a), new Cesium.Cartesian3());
|
|
|
- //B点在以A点为原点的局部的坐标位置
|
|
|
- var localPosition_B = Cesium.Matrix4.multiplyByPoint(worldToLocal_Matrix, new Cesium.Cartesian3.fromDegrees(lng_b, lat_b, alt_b), new Cesium.Cartesian3());
|
|
|
- //弧度
|
|
|
- var angle = Math.atan2((localPosition_B.z - localPosition_A.z), (localPosition_B.x - localPosition_A.x))
|
|
|
- //角度
|
|
|
- // var theta = angle * (180 / Math.PI);
|
|
|
- // if (theta < 0) {
|
|
|
- // theta = theta + 360;
|
|
|
- // }
|
|
|
- return angle;
|
|
|
+ var labelentity = new Cesium.Entity({
|
|
|
+ position: position,
|
|
|
+ point: {
|
|
|
+ // 点的大小(像素)
|
|
|
+ pixelSize: 10,
|
|
|
+ // 点位颜色,fromCssColorString 可以直接使用CSS颜色
|
|
|
+ color: Cesium.Color.RED,
|
|
|
+ // 边框颜色
|
|
|
+ outlineColor: Cesium.Color.fromCssColorString("#fff"),
|
|
|
+ // 边框宽度(像素)
|
|
|
+ outlineWidth: 2,
|
|
|
+ // 显示在距相机的距离处的属性,多少区间内是可以显示的
|
|
|
+ distanceDisplayCondition: new Cesium.DistanceDisplayCondition(
|
|
|
+ 0,
|
|
|
+ 1500
|
|
|
+ ),
|
|
|
+ // 是否显示
|
|
|
+ show: true,
|
|
|
+ },
|
|
|
+ label: {
|
|
|
+ show: true,
|
|
|
+ text: "目标点",
|
|
|
+ font: "15px sans-serif",
|
|
|
+ pixelOffset: new Cesium.Cartesian2(60, -20), //文字偏移
|
|
|
+ fillColor: Cesium.Color.WHITE,
|
|
|
+ // backgroundColor:new Cesium.Color(0, 0, 0, 1),
|
|
|
+ distanceDisplayCondition: new Cesium.DistanceDisplayCondition(
|
|
|
+ 0,
|
|
|
+ 1500
|
|
|
+ ), //达到一定高度隐藏
|
|
|
+ },
|
|
|
+ });
|
|
|
+ that.points.push(labelentity);
|
|
|
+ viewer.entities.add(labelentity);
|
|
|
+ that.addTargetFlag = false;
|
|
|
+ sightline.build();
|
|
|
+ that.ComputationalPerspective();
|
|
|
+ }
|
|
|
+ handlerPoint.deactivate();
|
|
|
+ handlerPoint.clear();
|
|
|
+ });
|
|
|
},
|
|
|
- updateOrientation(targetEntity) {
|
|
|
- debugger;
|
|
|
- var pathPosition = targetEntity;
|
|
|
- // 前一个坐标点
|
|
|
- var preIndex = 0;
|
|
|
+ /**
|
|
|
+ * 计算方位角
|
|
|
+ * @param {} points
|
|
|
+ */
|
|
|
+ ComputationalPerspective() {
|
|
|
+ var point1;
|
|
|
+ var point2;
|
|
|
+ if (this.isFrom2To) {
|
|
|
+ point1 = [
|
|
|
+ sightline.viewPosition[0],
|
|
|
+ sightline.viewPosition[1],
|
|
|
+ sightline.viewPosition[2],
|
|
|
+ ];
|
|
|
+ point2 = [
|
|
|
+ sightline._currentTargetPoint[0],
|
|
|
+ sightline._currentTargetPoint[1],
|
|
|
+ sightline._currentTargetPoint[2],
|
|
|
+ ];
|
|
|
+ } else {
|
|
|
+ point1 = [
|
|
|
+ sightline._currentTargetPoint[0],
|
|
|
+ sightline._currentTargetPoint[1],
|
|
|
+ sightline._currentTargetPoint[2],
|
|
|
+ ];
|
|
|
+ point2 = [
|
|
|
+ sightline.viewPosition[0],
|
|
|
+ sightline.viewPosition[1],
|
|
|
+ sightline.viewPosition[2],
|
|
|
+ ];
|
|
|
+ point1[2] += this.personH;
|
|
|
+ point2[2] -= this.personH;
|
|
|
+ }
|
|
|
|
|
|
- var prevPosition = Cesium.Cartesian3.fromDegrees(
|
|
|
- pathPosition[preIndex][0],
|
|
|
- pathPosition[preIndex][1],
|
|
|
- pathPosition[preIndex][2]
|
|
|
- );
|
|
|
- // 当前坐标点
|
|
|
- var currentIndex = 1;
|
|
|
- var currentPosition = Cesium.Cartesian3.fromDegrees(
|
|
|
- pathPosition[currentIndex][0],
|
|
|
- pathPosition[currentIndex][1],
|
|
|
- pathPosition[currentIndex][2]
|
|
|
+ var positionA = Cesium.Cartesian3.fromDegrees(
|
|
|
+ point1[0],
|
|
|
+ point1[1],
|
|
|
+ point1[2]
|
|
|
);
|
|
|
-
|
|
|
- // 计算a点和b点的角度(偏行角)
|
|
|
- var angle = this.courseAngle(
|
|
|
- pathPosition[preIndex][0],
|
|
|
- pathPosition[preIndex][1],
|
|
|
- pathPosition[currentIndex][0],
|
|
|
- pathPosition[currentIndex][1]
|
|
|
+ var positionB = Cesium.Cartesian3.fromDegrees(
|
|
|
+ point2[0],
|
|
|
+ point2[1],
|
|
|
+ point2[2]
|
|
|
);
|
|
|
- angle = 360 - Number(angle.toFixed(0));
|
|
|
- // 计算a点和b点的角度(俯仰角)
|
|
|
- var pitchAngle = this.coursePitchAngle(
|
|
|
- pathPosition[currentIndex][0],
|
|
|
- pathPosition[currentIndex][1],
|
|
|
- pathPosition[currentIndex][2],
|
|
|
- pathPosition[preIndex][0],
|
|
|
- pathPosition[preIndex][1],
|
|
|
- pathPosition[preIndex][2]
|
|
|
+ let finalPosition = new Cesium.Cartesian3();
|
|
|
+ let matrix4 = Cesium.Transforms.eastNorthUpToFixedFrame(positionA);
|
|
|
+ Cesium.Matrix4.inverse(matrix4, matrix4);
|
|
|
+ Cesium.Matrix4.multiplyByPoint(matrix4, positionB, finalPosition);
|
|
|
+ Cesium.Cartesian3.normalize(finalPosition, finalPosition);
|
|
|
+ const resultHead = Cesium.Math.toDegrees(
|
|
|
+ Math.atan2(finalPosition.x, finalPosition.y)
|
|
|
);
|
|
|
- pitchAngle = Number(pitchAngle.toFixed(0));
|
|
|
- if (pitchAngle > 180) {
|
|
|
- pitchAngle = 360 - pitchAngle;
|
|
|
- } else {
|
|
|
- pitchAngle = 180 + pitchAngle;
|
|
|
- }
|
|
|
- // 根据“俯仰角、偏行角、滚转角”得到目标方位
|
|
|
- var gheading = Cesium.Math.toRadians(angle);
|
|
|
- var gpitch = Cesium.Math.toRadians(pitchAngle);
|
|
|
- var groll = Cesium.Math.toRadians(0);
|
|
|
- // var hpr = new Cesium.HeadingPitchRoll(gheading, gpitch, groll);
|
|
|
- // var orientation = Cesium.Transforms.headingPitchRollQuaternion(
|
|
|
- // prevPosition,
|
|
|
- // hpr
|
|
|
- // );
|
|
|
- viewer.camera.flyTo({
|
|
|
- destination: prevPosition,
|
|
|
+ const resultPitch = Cesium.Math.toDegrees(Math.asin(finalPosition.z));
|
|
|
+ viewer.camera.setView({
|
|
|
+ destination: positionA,
|
|
|
orientation: {
|
|
|
- heading: gheading,
|
|
|
- pitch: gpitch,
|
|
|
- roll: groll,
|
|
|
+ heading: Cesium.Math.toRadians(resultHead), // east, default value is 0.0 (north)
|
|
|
+ pitch: Cesium.Math.toRadians(resultPitch), // default value (looking down)
|
|
|
+ roll: 0.0, // default value
|
|
|
},
|
|
|
});
|
|
|
},
|
|
|
- // 计算a点和b点的角度(偏行角:逆时针)
|
|
|
- courseAngle(lng_a, lat_a, lng_b, lat_b) {
|
|
|
- //以a点为原点建立局部坐标系(东方向为x轴,北方向为y轴,垂直于地面为z轴),得到一个局部坐标到世界坐标转换的变换矩阵
|
|
|
- var localToWorld_Matrix = Cesium.Transforms.eastNorthUpToFixedFrame(
|
|
|
- new Cesium.Cartesian3.fromDegrees(lng_a, lat_a)
|
|
|
- );
|
|
|
- //求世界坐标到局部坐标的变换矩阵
|
|
|
- var worldToLocal_Matrix = Cesium.Matrix4.inverse(
|
|
|
- localToWorld_Matrix,
|
|
|
- new Cesium.Matrix4()
|
|
|
- );
|
|
|
- //a点在局部坐标的位置,其实就是局部坐标原点
|
|
|
- var localPosition_A = Cesium.Matrix4.multiplyByPoint(
|
|
|
- worldToLocal_Matrix,
|
|
|
- new Cesium.Cartesian3.fromDegrees(lng_a, lat_a),
|
|
|
- new Cesium.Cartesian3()
|
|
|
- );
|
|
|
- //B点在以A点为原点的局部的坐标位置
|
|
|
- var localPosition_B = Cesium.Matrix4.multiplyByPoint(
|
|
|
- worldToLocal_Matrix,
|
|
|
- new Cesium.Cartesian3.fromDegrees(lng_b, lat_b),
|
|
|
- new Cesium.Cartesian3()
|
|
|
- );
|
|
|
- //弧度
|
|
|
- var angle = Math.atan2(
|
|
|
- localPosition_B.y - localPosition_A.y,
|
|
|
- localPosition_B.x - localPosition_A.x
|
|
|
- );
|
|
|
- //角度
|
|
|
- var theta = angle * (180 / Math.PI);
|
|
|
- if (theta < 0) {
|
|
|
- theta = theta + 360;
|
|
|
- }
|
|
|
- return theta;
|
|
|
- },
|
|
|
-
|
|
|
- // 计算a点和b点的角度(俯仰角:逆时针)
|
|
|
- coursePitchAngle(lng_a, lat_a, alt_a, lng_b, lat_b, alt_b) {
|
|
|
- //以a点为原点建立局部坐标系(东方向为x轴,北方向为y轴,垂直于地面为z轴),得到一个局部坐标到世界坐标转换的变换矩阵
|
|
|
- var localToWorld_Matrix = Cesium.Transforms.eastNorthUpToFixedFrame(
|
|
|
- new Cesium.Cartesian3.fromDegrees(lng_a, lat_a, alt_a)
|
|
|
- );
|
|
|
- //求世界坐标到局部坐标的变换矩阵
|
|
|
- var worldToLocal_Matrix = Cesium.Matrix4.inverse(
|
|
|
- localToWorld_Matrix,
|
|
|
- new Cesium.Matrix4()
|
|
|
- );
|
|
|
- //a点在局部坐标的位置,其实就是局部坐标原点
|
|
|
- var localPosition_A = Cesium.Matrix4.multiplyByPoint(
|
|
|
- worldToLocal_Matrix,
|
|
|
- new Cesium.Cartesian3.fromDegrees(lng_a, lat_a, alt_a),
|
|
|
- new Cesium.Cartesian3()
|
|
|
- );
|
|
|
- //B点在以A点为原点的局部的坐标位置
|
|
|
- var localPosition_B = Cesium.Matrix4.multiplyByPoint(
|
|
|
- worldToLocal_Matrix,
|
|
|
- new Cesium.Cartesian3.fromDegrees(lng_b, lat_b, alt_b),
|
|
|
- new Cesium.Cartesian3()
|
|
|
- );
|
|
|
- //弧度
|
|
|
- var angle = Math.atan2(
|
|
|
- localPosition_B.z - localPosition_A.z,
|
|
|
- localPosition_B.x - localPosition_A.x
|
|
|
- );
|
|
|
- //角度
|
|
|
- var theta = angle * (180 / Math.PI);
|
|
|
- if (theta < 0) {
|
|
|
- theta = theta + 360;
|
|
|
- }
|
|
|
- return theta;
|
|
|
+ /**
|
|
|
+ * 视角切换
|
|
|
+ */
|
|
|
+ changeView() {
|
|
|
+ this.isFrom2To = !this.isFrom2To;
|
|
|
+ this.ComputationalPerspective();
|
|
|
},
|
|
|
clearScope() {
|
|
|
- if (handlerLine) {
|
|
|
- handlerLine.clear();
|
|
|
- handlerLine.deactivate();
|
|
|
- handlerLine = null;
|
|
|
+ viewer.entities.removeAll();
|
|
|
+ this.points = [];
|
|
|
+ sightline.removeAllTargetPoint();
|
|
|
+ if (handlerPoint) {
|
|
|
+ handlerPoint.clear();
|
|
|
+ handlerPoint.deactivate();
|
|
|
}
|
|
|
this.tooltip.setVisible(false);
|
|
|
},
|