forked from drone/command-center-dashboard

chenyao
2025-04-14 b0ccd2d131b2e3df5d901385e38ed0077b8d0fbc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import * as Cesium from 'cesium';
import cesiumOperation from '@/utils/cesium-tsa';
import { analyzeKmzFile, XMLToJSON } from '@/utils/cesium/kmz.js'
import { cartesian3Convert, getCenterPoint, getLnglatDist } from '@/utils/cesium/mapUtil.js'
import { getLnglatAltitude, getPositionsHeight } from '@/utils/cesium/mapUtil'
 
const {
  addPoint,
  getEntityById,
  removeById,
  removeAllPoint,
  addLeftClickEvent,
  removeLeftClickEvent,
  addRightClickEvent,
  removeRightClickEvent,
  flyTo,
  pointInitEvent,
  pointUnInitEvent
} = cesiumOperation()
/**
 * 
 * @param { 单点航线 相关功能} url 
 */
export const initPointWayline = () => {
  
  let viewer = null;
  
 
  // 解析kmz文件
  const parsingFiles = async (url,viewer) => {
    viewer = viewer;
    console.log('initPointWayline', viewer);
    const res = await analyzeKmzFile(`${url}?_t=${new Date().getTime()}`)
        const waylinesXML = await res.fileInfoObj['wpmz/waylines.wpml']
        const xmlJson = XMLToJSON(waylinesXML)?.['Document'];
    if (xmlJson.Folder.Placemark.length) return;
    drawWayline(xmlJson)
  };
  // 在地图上画线
  const drawWayline = (xmlJson) => {
    let positions = [];
    // 获取点的位置
    const points = xmlJson.Folder.Placemark;
    console.log('points', points);
    getPositionsHeight(points, viewer, 100).then((result) => {
      console.log(result);
      positions = result.map((item) => {
        return Cesium.Cartesian3.fromDegrees(
          Number(item.longitude),
          Number(item.latitude),
          item.FinalHeight,
        )
      });
      result.forEach((item, index) => {
        let setting = {};
        setting = {
          id: 'route_point_' + index,
          position: positions[index],
 
          label: {
            text: `${index + 1}`,
            font: 'bold 14px serif',
            style: globalCesium.LabelStyle.FILL,
            verticalOrigin: globalCesium.VerticalOrigin.CENTER, // 垂直居中
            horizontalOrigin: globalCesium.HorizontalOrigin.CENTER, // 水平居中
            pixelOffset: new globalCesium.Cartesian2(0, 0), // 根据需要调整偏移量
            eyeOffset: new globalCesium.Cartesian3(0, 0, -10) // 使标签在点的上方
          },
 
          point: {
            pixelSize: 24,
            color: new globalCesium.Color.fromBytes(255, 186, 0, 255),
          },
        }
        viewer.entities.add(setting)
      });
    });
  };
 
  return { parsingFiles };
};