找回密码
 立即注册
首页 资源区 代码 Cesium 无人机巡检三维效果实现

Cesium 无人机巡检三维效果实现

路逸思 昨天 10:41
uavInspection.js代码
  1. /**
  2. * 无人机巡检
  3. */
  4. import * as mars3d from "mars3d"
  5. import * as Cesium from 'mars3d-cesium'
  6. import * as turf from "@turf/turf"
  7. import { getMap } from '@/components/mars3dMap/js/index.js'
  8. import { getHeightByLngLat } from '@/components/mars3dMap/js/utils.js'
  9. import GlowLineMaterialProperty from '@/components/mars3dMap/js/material/GlowLineMaterialProperty.js'
  10. import iamge from "@/components/mars3dMap/images/路径撒点.png";
  11. import iamge2 from "@/components/mars3dMap/images/路径撒点2.png";
  12. let graphicLayer;
  13. let uavInspectionMap = new Map();
  14. let pointCallback; // 无人机经过点位回调
  15. let UavInspection = (function () {
  16.     /**
  17.      * 无人机巡检
  18.      */
  19.     function UavInspection(id, positions) {
  20.         this.id = id;
  21.         this.positions = positions || [];
  22.         this.graphicMap = new Map();
  23.         this.step = 20;
  24.         this.callbackPointSet = new Set(); // 回调点位集合
  25.         if (positions && positions.length > 0) {
  26.             this.segmentPositions = this.divideLine(positions, this.step);
  27.         }
  28.         if (!graphicLayer) {
  29.             let map = getMap();
  30.             graphicLayer = new mars3d.layer.GraphicLayer()
  31.             map.addLayer(graphicLayer);
  32.         }
  33.     }
  34.     UavInspection.prototype.finishLabels = function (index) {
  35.         for (let i = 1; i <= index; i++) {
  36.             this.finishLabel(i);
  37.         }
  38.     }
  39.     UavInspection.prototype.finishLabel = function (index) {
  40.         let id = `label-${index}`;
  41.         if (this.graphicMap.has(id)) {
  42.             let data = this.graphicMap.get(id);
  43.             data.graphic.setStyle({ image: iamge2 });
  44.         }
  45.     }
  46.     UavInspection.prototype.addLabels = function () {
  47.         for (let [i, pos] of this.positions.entries()) {
  48.             let samePos = false; // 第1个点和最后一个点位置是否相同
  49.             if (this.positions.length > 0) {
  50.                 let lastPos1 = this.positions[0];
  51.                 let lastPos2 = this.positions[this.positions.length - 1];
  52.                 let distance = Cesium.Cartesian3.distance(Cesium.Cartesian3.fromDegrees(lastPos1[0], lastPos1[1], lastPos1[2]),
  53.                     Cesium.Cartesian3.fromDegrees(lastPos2[0], lastPos2[1], lastPos2[2]));
  54.                 if (distance < 5) {
  55.                     samePos = true;
  56.                 }
  57.             }
  58.             if (i < (samePos ? this.positions.length - 1 : this.positions.length)) {
  59.                 this.addLabel(i + 1, pos[0], pos[1], pos[2]);
  60.             }
  61.         }
  62.     }
  63.     UavInspection.prototype.addLabel = function (index, lng, lat, height) {
  64.         let id = `label-${index}`;
  65.         let data;
  66.         if (this.graphicMap.has(id)) {
  67.             return;
  68.         } else {
  69.             data = { id: id, type: 'label' };
  70.             this.graphicMap.set(id, data);
  71.         }
  72.         data.graphic = new mars3d.graphic.BillboardEntity({
  73.             id: id,
  74.             position: [lng, lat, height],
  75.             style: {
  76.                 image: iamge,
  77.                 scale: 0.5,
  78.                 horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
  79.                 verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
  80.                 clampToGround: false,
  81.                 pixelOffsetY: 30,
  82.                 label: {
  83.                     text: `${index}`,
  84.                     pixelOffsetY: -31,
  85.                     visibleDepth: false
  86.                 }
  87.             },
  88.         })
  89.         graphicLayer.addGraphic(data.graphic);
  90.     }
  91.     UavInspection.prototype.clear = function () {
  92.         for (let id of this.graphicMap.keys()) {
  93.             let data = this.graphicMap.get(id);
  94.             this.graphicMap.delete(id);
  95.             graphicLayer.removeGraphic(data.graphic);
  96.             data.graphic = undefined;
  97.             if (data.type == 'drone') {
  98.                 data.positionProperty = undefined;
  99.             }
  100.         }
  101.         this.callbackPointSet.clear();
  102.     }
  103.     UavInspection.prototype.createPath = function () {
  104.         return { // 实时轨迹显示
  105.             show: true,
  106.             leadTime: 0, // 飞机将要经过的路径,路径存在的时间
  107.             trailTime: 60, // 飞机已经经过的路径,路径存在的时间
  108.             width: 8, // 线宽度
  109.             resolution: 1,
  110.             // color: 'rgba(255, 193, 37, 1)',
  111.             /* material: new Cesium.PolylineGlowMaterialProperty({
  112.                 glowPower: 0.25, // 轨迹线的发光强度
  113.                 color: new Cesium.Color(255 / 255, 193 / 255, 37 / 255, 1) // 颜色
  114.             }) */
  115.             material: new GlowLineMaterialProperty({
  116.                 color: new Cesium.Color(255 / 255, 255 / 255, 0 / 255, 1),
  117.                 power: 0.2
  118.             })
  119.         };
  120.     }
  121.     UavInspection.prototype.createModel = function () {
  122.         return new mars3d.graphic.ModelEntity({
  123.             position: [0, 0, 0], // 默认值
  124.             style: {
  125.                 url: 'gltf/四旋翼无人机1.glb',
  126.                 scale: 6,
  127.                 minimumPixelSize: 100,
  128.                 heading: 0
  129.             },
  130.             path: this.createPath()
  131.         });
  132.     }
  133.     UavInspection.prototype.createDrone = function () {
  134.         let id = this.id;
  135.         let data;
  136.         if (this.graphicMap.has(id)) {
  137.             return;
  138.         } else {
  139.             data = { id: id, type: 'drone' };
  140.             this.graphicMap.set(id, data);
  141.             data.positionProperty = new Cesium.SampledPositionProperty();
  142.             data.positionProperty.forwardExtrapolationType = Cesium.ExtrapolationType.HOLD; // 后续时段保持末位置
  143.         }
  144.         if (!data.graphic) {
  145.             data.graphic = this.createModel();
  146.             graphicLayer.addGraphic(data.graphic);
  147.             data.graphic.position = data.positionProperty;
  148.             this.addDashLine();
  149.         }
  150.     }
  151.     UavInspection.prototype.updateDronePosition = function (lng, lat, height) {
  152.         let id = this.id;
  153.         if (this.graphicMap.has(id)) {
  154.             let data = this.graphicMap.get(id);
  155.             if (data.graphic) {
  156.                 this.lastTime = new Date().getTime();
  157.                 data.position = [lng, lat, height];
  158.                 let position = Cesium.Cartesian3.fromDegrees(lng, lat, height);
  159.                 let delay = 2000; // 延迟(单位:毫秒)
  160.                 let time = Cesium.JulianDate.fromDate(new Date(new Date().getTime() + delay));
  161.                 data.positionProperty.addSample(time, position);
  162.                 setTimeout(() => {
  163.                     this.updateDashLine(lng, lat, height);
  164.                     this.drawBlocks(lng, lat);
  165.                 }, delay);
  166.             }
  167.         }
  168.         // 无人机经纬标签时标签变色
  169.         for (let [i, pos] of this.positions.entries()) {
  170.             if (i < this.positions.length) {
  171.                 let distance = Cesium.Cartesian3.distance(Cesium.Cartesian3.fromDegrees(lng, lat, 0), Cesium.Cartesian3.fromDegrees(pos[0], pos[1], 0));
  172.                 if (distance < 10) {
  173.                     this.finishLabels(i + 1);
  174.                 }
  175.             }
  176.         }
  177.         // 指定点位回调
  178.         for (let [i, pos] of this.positions.entries()) {
  179.             let distance = Cesium.Cartesian3.distance(Cesium.Cartesian3.fromDegrees(lng, lat, 0), Cesium.Cartesian3.fromDegrees(pos[0], pos[1], 0));
  180.             if (distance < 10) {
  181.                 if (pointCallback && !this.callbackPointSet.has(i + 1)) {
  182.                     let map = getMap();
  183.                     const screenPoint = map.scene.cartesianToCanvasCoordinates(Cesium.Cartesian3.fromDegrees(lng, lat, height));
  184.                     this.callbackPointSet.add(i + 1);
  185.                     setTimeout(() => {
  186.                         pointCallback(i + 1, screenPoint);
  187.                     }, 100);
  188.                 }
  189.             }
  190.         }
  191.     }
  192.     UavInspection.prototype.addDashLine = function () {
  193.         let id = `dashline-${this.id}`;
  194.         let data;
  195.         if (this.graphicMap.has(id)) {
  196.             return;
  197.         } else {
  198.             data = { id: id, type: 'dashline' };
  199.             this.graphicMap.set(id, data);
  200.         }
  201.         if (!data.graphic) {
  202.             data.graphic = new mars3d.graphic.PolylineEntity({
  203.                 positions: undefined,
  204.                 style: {
  205.                     width: 2,
  206.                     clampToGround: false,
  207.                     materialType: mars3d.MaterialType.PolylineDash,
  208.                     materialOptions: {
  209.                         color: '#ff0000',
  210.                         dashLength: 16.0
  211.                     }
  212.                 }
  213.             })
  214.             graphicLayer.addGraphic(data.graphic)
  215.         }
  216.     }
  217.     UavInspection.prototype.updateDashLine = function (lng, lat, height) {
  218.         let id = `dashline-${this.id}`;
  219.         if (this.graphicMap.has(id)) {
  220.             let data = this.graphicMap.get(id);
  221.             (async () => {
  222.                 let h = await getHeightByLngLat(getMap(), lng, lat);
  223.                 if (data.graphic) {
  224.                     data.graphic.setCallbackPositions([[lng, lat, height], [lng, lat, h]]);
  225.                 }
  226.             })();
  227.         }
  228.     }
  229.     /**
  230.      * 计算正方形在三维空间中的四个顶点坐标
  231.      */
  232.     UavInspection.prototype.calculateSquareVertices = function (lng, lat, angle, step) {
  233.         let centerPoint = Cesium.Cartesian3.fromDegrees(lng, lat, 0);
  234.         // 获取中心点处的ENU坐标系基向量(东、北、天)
  235.         const matrix = Cesium.Transforms.eastNorthUpToFixedFrame(centerPoint);
  236.         const east = new Cesium.Cartesian3();
  237.         const north = new Cesium.Cartesian3();
  238.         Cesium.Matrix4.getColumn(matrix, 0, east);  // 东方向单位向量
  239.         Cesium.Matrix4.getColumn(matrix, 1, north); // 北方向单位向量
  240.         const halfLen = step / 2;
  241.         const angleRad = Cesium.Math.toRadians(angle);  // 转为弧度
  242.         // 1. 计算目标方向向量(θ方向)在ENU坐标系的投影分量
  243.         const cosTheta = Math.cos(angleRad);
  244.         const sinTheta = Math.sin(angleRad);
  245.         // 计算主方向单位向量 (基于东和北分量)
  246.         const dirX = cosTheta;
  247.         const dirY = -sinTheta; // 负号用于处理顺时针旋转
  248.         // 构造三维空间中的方向向量
  249.         const directionVector = new Cesium.Cartesian3();
  250.         Cesium.Cartesian3.multiplyByScalar(east, dirX, directionVector);
  251.         Cesium.Cartesian3.add(
  252.             directionVector,
  253.             Cesium.Cartesian3.multiplyByScalar(north, dirY, new Cesium.Cartesian3()),
  254.             directionVector
  255.         );
  256.         // 2. 计算垂直方向向量 (θ+90°) 的分量
  257.         const perpX = -sinTheta;
  258.         const perpY = -cosTheta;
  259.         // 构造三维空间中的垂直向量
  260.         const perpendicularVector = new Cesium.Cartesian3();
  261.         Cesium.Cartesian3.multiplyByScalar(east, perpX, perpendicularVector);
  262.         Cesium.Cartesian3.add(
  263.             perpendicularVector,
  264.             Cesium.Cartesian3.multiplyByScalar(north, perpY, new Cesium.Cartesian3()),
  265.             perpendicularVector
  266.         );
  267.         // 3. 计算四个顶点
  268.         const result = [];
  269.         const scratch = new Cesium.Cartesian3();
  270.         // 顶点计算函数 (避免重复代码)
  271.         const calculatePoint = (xFactor, yFactor) => {
  272.             const point = scratch;
  273.             // point = centerPoint + (directionVector * xFactor * halfLen) + (perpendicularVector * yFactor * halfLen)
  274.             Cesium.Cartesian3.multiplyByScalar(directionVector, xFactor * halfLen, point);
  275.             Cesium.Cartesian3.add(
  276.                 point,
  277.                 Cesium.Cartesian3.multiplyByScalar(perpendicularVector, yFactor * halfLen, new Cesium.Cartesian3()),
  278.                 point
  279.             );
  280.             return Cesium.Cartesian3.add(centerPoint, point, new Cesium.Cartesian3());
  281.         };
  282.         // 生成4个顶点(顺时针顺序)
  283.         result.push(calculatePoint(1, -1));  // 起点:右下
  284.         result.push(calculatePoint(1, 1));  // 右上
  285.         result.push(calculatePoint(-1, 1));  // 左上
  286.         result.push(calculatePoint(-1, -1));  // 左下
  287.         return result;
  288.     }
  289.     UavInspection.prototype.getSquareVertices = function (pos, pos1, pos2, step) {
  290.         let angle = this.calculateBearingFromEast(pos1, pos2);
  291.         let r = this.calculateSquareVertices(pos[0], pos[1], angle, step);
  292.         let result = { center: pos, positions: [] };
  293.         for (let i = 0; i < r.length; i++) {
  294.             const cartographic = Cesium.Cartographic.fromCartesian(r[i]);
  295.             let position = [Cesium.Math.toDegrees(cartographic.longitude), Cesium.Math.toDegrees(cartographic.latitude), cartographic.height];
  296.             result.positions.push(position);
  297.         }
  298.         return result;
  299.     }
  300.     UavInspection.prototype.getRectangleVertices = function (pos1, pos2, step) {
  301.         let mid1 = Cesium.Cartesian3.fromDegrees(pos1[0], pos1[1], 0);
  302.         let mid2 = Cesium.Cartesian3.fromDegrees(pos2[0], pos2[1], 0);
  303.         const { Cartesian3, Ellipsoid, Cartographic } = Cesium;
  304.         const ellipsoid = Ellipsoid.WGS84;
  305.         // 计算中点连线方向向量
  306.         const v1 = Cartesian3.subtract(mid2, mid1, new Cartesian3());
  307.         const distance = Cartesian3.magnitude(v1);
  308.         Cartesian3.normalize(v1, v1);
  309.         // 计算垂直方向向量
  310.         const center = Cartesian3.midpoint(mid1, mid2, new Cartesian3());
  311.         const normal = ellipsoid.geodeticSurfaceNormal(center, new Cartesian3());
  312.         const v2 = Cartesian3.cross(normal, v1, new Cartesian3());
  313.         Cartesian3.normalize(v2, v2);
  314.         // 缩放垂直向量到指定长度
  315.         const halfWidth = Cartesian3.multiplyByScalar(v2, step / 2.0, new Cartesian3());
  316.         // 计算四个顶点的笛卡尔坐标
  317.         const cornersCartesian = [
  318.             Cartesian3.add(mid1, Cartesian3.negate(halfWidth, new Cartesian3()), new Cartesian3()), // SW
  319.             Cartesian3.add(mid1, halfWidth, new Cartesian3()),  // NW
  320.             Cartesian3.add(mid2, halfWidth, new Cartesian3()),   // NE
  321.             Cartesian3.add(mid2, Cartesian3.negate(halfWidth, new Cartesian3()), new Cartesian3())  // SE
  322.         ];
  323.         // 转换为经纬度(弧度)坐标
  324.         const cornersRadians = cornersCartesian.map(cartesian => {
  325.             return Cartographic.fromCartesian(cartesian);
  326.         });
  327.         // 转换为度数
  328.         return cornersRadians.map(rad => {
  329.             return [Cesium.Math.toDegrees(rad.longitude), Cesium.Math.toDegrees(rad.latitude), rad.height];
  330.         });
  331.     }
  332.     UavInspection.prototype.divideSegment = function (pos1, pos2, step) {
  333.         let p1 = Cesium.Cartesian3.fromDegrees(pos1[0], pos1[1], 0);
  334.         let p2 = Cesium.Cartesian3.fromDegrees(pos2[0], pos2[1], 0);
  335.         let result = [];
  336.         let lastPos = pos1;
  337.         let currentPos;
  338.         let distance = Cesium.Cartesian3.distance(p1, p2);
  339.         let d = step;
  340.         while (d < distance - 0.1) {
  341.             let t = d / distance;
  342.             const interpolatedCartesian = new Cesium.Cartesian3();
  343.             Cesium.Cartesian3.lerp(p1, p2, t, interpolatedCartesian);
  344.             const cartographic = Cesium.Cartographic.fromCartesian(interpolatedCartesian);
  345.             currentPos = [Cesium.Math.toDegrees(cartographic.longitude), Cesium.Math.toDegrees(cartographic.latitude), cartographic.height];
  346.             result.push({
  347.                 pos1: lastPos,
  348.                 pos2: currentPos,
  349.                 positions: this.getRectangleVertices(lastPos, currentPos, step)
  350.             });
  351.             lastPos = currentPos;
  352.             d += step;
  353.         }
  354.         result.push({
  355.             pos1: currentPos,
  356.             pos2: pos2,
  357.             positions: this.getRectangleVertices(currentPos, pos2, step)
  358.         });
  359.         return result;
  360.     }
  361.     UavInspection.prototype.divideLine = function (positions, step) {
  362.         let result = [];
  363.         for (let i = 0; i < positions.length - 1; i++) {
  364.             let pos1 = positions[i];
  365.             let pos2 = positions[i + 1];
  366.             let array = this.divideSegment(pos1, pos2, step);
  367.             result.push(...array);
  368.         }
  369.         return result.slice(0, -1);
  370.     }
  371.     UavInspection.prototype.drawBlocks = function (lng, lat) {
  372.         if (this.segmentPositions && this.segmentPositions.length > 0) {
  373.             let index = -1;
  374.             for (let [i, pos] of this.segmentPositions.entries()) {
  375.                 let distance1 = Cesium.Cartesian3.distance(Cesium.Cartesian3.fromDegrees(pos.pos1[0], pos.pos1[1], 0), Cesium.Cartesian3.fromDegrees(pos.pos2[0], pos.pos2[1], 0));
  376.                 let distance2 = Cesium.Cartesian3.distance(Cesium.Cartesian3.fromDegrees(lng, lat, 0), Cesium.Cartesian3.fromDegrees(pos.pos1[0], pos.pos1[1], 0));
  377.                 let distance3 = Cesium.Cartesian3.distance(Cesium.Cartesian3.fromDegrees(lng, lat, 0), Cesium.Cartesian3.fromDegrees(pos.pos2[0], pos.pos2[1], 0));
  378.                 if (distance1 - (distance2 + distance3) > -0.1) {
  379.                     index = i;
  380.                 }
  381.             }
  382.             for (let i = 0; i <= index; i++) {
  383.                 let pos = this.segmentPositions[i];
  384.                 let pos2
  385.                 if (i + 1 < this.segmentPositions.length) {
  386.                     pos2 = this.segmentPositions[i + 1];
  387.                 } else {
  388.                     pos2 = this.segmentPositions[i - 1];
  389.                 }
  390.                 this.drawBlock(i, pos);
  391.             }
  392.         } else {
  393.             if (!this.lastBlockPos) {
  394.                 this.lastBlockPos = [lng, lat, 0];
  395.                 this.blockIndex = 0;
  396.             } else {
  397.                 let distance = Cesium.Cartesian3.distance(Cesium.Cartesian3.fromDegrees(this.lastBlockPos[0], this.lastBlockPos[1], 0), Cesium.Cartesian3.fromDegrees(lng, lat, 0));
  398.                 if (distance >= this.step) {
  399.                     let pos2 = [lng, lat, 0];
  400.                     let vertices = this.getRectangleVertices(this.lastBlockPos, pos2, this.step);
  401.                     this.drawBlock(this.blockIndex++, { positions: vertices });
  402.                     this.lastBlockPos = [lng, lat, 0];
  403.                 }
  404.             }
  405.         }
  406.     }
  407.     UavInspection.prototype.drawBlock = function (i, pos) {
  408.         let id = `block-${i}`;
  409.         let data;
  410.         if (this.graphicMap.has(id)) {
  411.             return;
  412.         } else {
  413.             data = { id: id, type: 'block' };
  414.             this.graphicMap.set(id, data);
  415.         }
  416.         if (!data.graphic) {
  417.             data.graphic = new mars3d.graphic.PolygonPrimitive({
  418.                 positions: pos.positions,
  419.                 style: {
  420.                     color: "#ff0000",
  421.                     opacity: 0.3,
  422.                     clampToGround: true
  423.                 }
  424.             })
  425.             graphicLayer.addGraphic(data.graphic)
  426.         }
  427.     }
  428.     /**
  429.      * 计算两点间方向(正东为0°,顺时针到360°)
  430.      * @returns {number} 方向角度(0°到360°,正东方向为0°)
  431.      */
  432.     UavInspection.prototype.calculateBearingFromEast = function (pos1, pos2) {
  433.         const point1 = Cesium.Cartographic.fromDegrees(pos1[0], pos1[1]);
  434.         const point2 = Cesium.Cartographic.fromDegrees(pos2[0], pos2[1]);
  435.         const lon1 = point1.longitude;
  436.         const lat1 = point1.latitude;
  437.         const lon2 = point2.longitude;
  438.         const lat2 = point2.latitude;
  439.         // 经度差(考虑跨日期变更线)
  440.         const dLon = lon2 - lon1;
  441.         // 计算Y分量(与正北相关)
  442.         const y = Math.sin(dLon) * Math.cos(lat2);
  443.         // 计算X分量(与正北相关)
  444.         const x = Math.cos(lat1) * Math.sin(lat2) -
  445.             Math.sin(lat1) * Math.cos(lat2) * Math.cos(dLon);
  446.         // 计算初始方位角(0°为正北,顺时针)
  447.         const bearingRad = Math.atan2(y, x);
  448.         let bearingDeg = Cesium.Math.toDegrees(bearingRad);
  449.         // 转换为0°~360°范围
  450.         if (bearingDeg < 0) {
  451.             bearingDeg += 360;
  452.         }
  453.         // 坐标系转换:正北0° → 正东0°
  454.         // 转换公式: (bearingDeg + 90) % 360
  455.         return (bearingDeg + 90) % 360;
  456.     }
  457.     return UavInspection;
  458. })()
  459. function createUavInspection(id, positions) {
  460.     if (!uavInspectionMap.has(id)) {
  461.         let uavInspection = new UavInspection(id, positions);
  462.         uavInspection.createDrone();
  463.         uavInspection.addLabels();
  464.         uavInspectionMap.set(id, uavInspection);
  465.     }
  466. }
  467. function uavInspectionExists(id) {
  468.     return uavInspectionMap.has(id);
  469. }
  470. function updateUavInspectionPosition(id, lng, lat, height) {
  471.     if (uavInspectionMap.has(id)) {
  472.         let uavInspection = uavInspectionMap.get(id);
  473.         uavInspection.updateDronePosition(lng, lat, height);
  474.     }
  475. }
  476. function clearUavInspections() {
  477.     for (let id of uavInspectionMap.keys()) {
  478.         let uavInspection = uavInspectionMap.get(id);
  479.         uavInspectionMap.delete(id);
  480.         uavInspection.clear();
  481.     }
  482.     graphicLayer = undefined;
  483. }
  484. // 定时清理
  485. setInterval(() => {
  486.     for (let id of uavInspectionMap.keys()) {
  487.         let uavInspection = uavInspectionMap.get(id);
  488.         if (new Date().getTime() - uavInspection.lastTime > 20 * 1000) {
  489.             uavInspectionMap.delete(id);
  490.             uavInspection.clear();
  491.         }
  492.     }
  493. }, 1000);
  494. // 无人机经过点位回调
  495. function registerPointCallback(callback) {
  496.     pointCallback = callback;
  497. }
  498. export { uavInspectionExists, createUavInspection, updateUavInspectionPosition, clearUavInspections, registerPointCallback }
复制代码
实时接收WebSocket数据,展示无人机、航线、地面色块

部分代码如下
  1. import { uavInspectionExists, createUavInspection, updateUavInspectionPosition } from '@/components/mars3dMap/js/uavInspection.js'
  2. async function processWebSocketData(json) {
  3.     if (json.method && json.method == "FLIGHT" && json.data) {
  4.         let data = json.data;
  5.         let id = data.droneSN;
  6.         let model = data.model; // 飞机型号
  7.         let lng = data.longitude;
  8.         let lat = data.latitude;
  9.         let alt = data.altitude; // 海拔高度
  10.         let heading = data.heading; // 朝向(度)
  11.         let pitch = data.pitch; // 俯仰角(度)
  12.         let roll = data.roll; // 翻转角(度)
  13.         let groundSpeed = data.groundSpeed; // 地面速度,单位m/s
  14.         if (!uavInspectionExists(id)) {
  15.             let positions;
  16.             if (id == config.droneSN) {
  17.                 positions = config.passingPoints;
  18.             } else {
  19.                 positions = [];
  20.             }
  21.             createUavInspection(id, positions)
  22.         }
  23.         updateUavInspectionPosition(id, lng, lat, alt);
  24.     }
  25. }
复制代码
效果截图

截图说明:由于测试笔记本比较卡,所以红虚线、红色块和无人机的位置不同步
1.png


来源:程序园用户自行投稿发布,如果侵权,请联系站长删除
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!
您需要登录后才可以回帖 登录 | 立即注册