From 02409bfbe15f22fc3b5dccadabfd860a660a49d9 Mon Sep 17 00:00:00 2001
From: 罗广辉 <guanghui.luo@foxmail.com>
Date: Sat, 11 Oct 2025 10:37:14 +0800
Subject: [PATCH] feat: 名称修改

---
 src/components/map-container/mapContainer.vue |  276 +++++++++++++++++++++---------------------------------
 1 files changed, 109 insertions(+), 167 deletions(-)

diff --git a/src/components/map-container/mapContainer.vue b/src/components/map-container/mapContainer.vue
index 5828a87..c88c75e 100644
--- a/src/components/map-container/mapContainer.vue
+++ b/src/components/map-container/mapContainer.vue
@@ -4,84 +4,69 @@
  * @LastEditors: shuishen 1109946754@qq.com
  * @LastEditTime: 2025-04-28 11:34:40
  * @FilePath: \drone-web-manage\src\components\map-container\mapContainer.vue
- * @Description: 
- * 
- * Copyright (c) 2024 by shuishen, All Rights Reserved. 
+ * @Description:
+ *
+ * Copyright (c) 2024 by shuishen, All Rights Reserved.
 -->
 <template>
-    <div class="map-container">
-        <div class="viewer-container" id="viewer-container">
-            <div class="content">
-                <slot name="content"></slot>
-            </div>
-        </div>
+  <div class="map-container">
+    <div class="viewer-container ztzf-cesium" id="viewer-container">
+      <div class="content">
+        <slot name="content"></slot>
+      </div>
+
+      <PlanarRouteLineList
+        :curRouteLineData="curRouteLineData"
+        @routeLineListClick="routeLineListClick"
+      />
     </div>
+  </div>
 </template>
 
 <script setup>
-import * as turf from '@turf/turf'
+import PlanarRouteLineList from '@/components/PlanarRouteLineList/PlanarRouteLineList.vue';
 
-import { nextTick, onMounted, onUnmounted } from 'vue'
-import { read } from 'xlsx'
+import * as Cesium from 'cesium';
+import { Cartesian3, Terrain, Viewer } from 'cesium';
+import { PublicCesium } from '@/utils/cesium/publicCesium';
+import ImageTrailMaterial from '@/utils/cesium/ImageTrailMaterial';
+import { flyVisual } from '@/utils/cesium/mapUtil';
+import * as turf from '@turf/turf';
 
-window.$viewer = null
-window.$Cesium = null
-let pointLayer = null
-let polylineLayer = null
+import { nextTick, onBeforeUnmount, onMounted, onUnmounted } from 'vue';
+import { read } from 'xlsx';
 
-const { VITE_APP_BASE } = import.meta.env
+import startPng from '@/assets/map_images/Startingpointicon.png';
+import endPng from '@/assets/map_images/EndPointicon.png';
+import rwqfdImg from '@/assets/images/task/arrow-right-blue.png';
+import newNumPoint from '@/assets/images/task/custom-point.png';
+
+import { useRouteLine } from '@/hooks/useRouteLine/useRouteLine.js';
+const viewInstance = shallowRef(null);
+// 加载航线hook
+const { curRouteLineData, routeLineListClick, initViewer, renderPreviewLine } = useRouteLine();
+
+let publicCesiumInstance = null;
+let viewer = null;
+
+const { VITE_APP_BASE } = import.meta.env;
 // import * as Cesium from 'cesium'
 // import 'cesium/Build/Cesium/Widgets/widgets.css'
-const isViewerReady = ref(false)
+const isViewerReady = ref(false);
 const { rowDetails } = defineProps({
-    rowDetails: {
-        type: Object,
-        default: () => ({}),
-    }
-})
+  rowDetails: {
+    type: Object,
+    default: () => ({}),
+  },
+});
 
-
-async function initMap () {
-    if (window.$viewer) return
-
-    await DC.ready({
-        // Cesium: Cesium,
-        baseUrl: `${VITE_APP_BASE}/libs/dc-sdk/resources/`,
-    })
-
-    window.$Cesium = DC.getLib('Cesium')
-
-    // 天地图地图
-    const imageryProvider_standZh = new window.$Cesium.UrlTemplateImageryProvider({
-        url: 'https://t{s}.tianditu.gov.cn/DataServer?T=cva_w&x={x}&y={y}&l={z}&tk=e45274b0235bb913eceb393aabbf9c9c',
-        subdomains: ['0', '1', '2', '3', '4', '5', '6', '7'],
-        maximumLevel: 18,
-        credit: 'stand_zj',
-    })
-    const imageryProvider_stand = new window.$Cesium.UrlTemplateImageryProvider({
-        url: 'https://t{s}.tianditu.gov.cn/DataServer?T=vec_w&x={x}&y={y}&l={z}&tk=e45274b0235bb913eceb393aabbf9c9c',
-        subdomains: ['0', '1', '2', '3', '4', '5', '6', '7'],
-        // format: 'image/jpeg',
-        // show: true,
-        maximumLevel: 18,
-        credit: 'stand_tc',
-    })
-
-    window.$viewer = new DC.Viewer('viewer-container',)
-
-    window.$viewer.locationBar.enable = false
-
-    window.$viewer?.zoomToPosition(new DC.Position(115.892151, 28.676493, 1000000, 0, -90, 0))
-
-    window.$viewer?.imageryLayers.addImageryProvider(imageryProvider_stand)
-    window.$viewer?.imageryLayers.addImageryProvider(imageryProvider_standZh)
-
-    pointLayer = new DC.VectorLayer('pointLayer')
-    window.$viewer?.addLayer(pointLayer)
-    polylineLayer = new DC.VectorLayer('polylineLayer')
-    window.$viewer?.addLayer(polylineLayer)
-
-    isViewerReady.value = true
+async function initMap() {
+  if (viewer) return;
+  publicCesiumInstance = new PublicCesium({ dom: 'viewer-container', layerMode: 4 });
+  viewer = publicCesiumInstance.getViewer();
+  viewInstance.value = publicCesiumInstance;
+  initViewer(viewer);
+  isViewerReady.value = true;
 }
 
 /**
@@ -90,138 +75,95 @@
  * @param data 数据
  */
 const initAddEntity = (type, data) => {
-    watch(() => isViewerReady.value,
-        (ready) => {
-            if (ready) {
-                type === 'point' ? addPoint(data) : addPolyline(data)
-            }
-        },
-        { deep: true, immediate: true } // 初始化时立即执行
-    )
-}
+  watch(
+    () => isViewerReady.value,
+    ready => {
+      if (ready) {
+        viewer.entities.removeAll();
+        if (type === 'initPosition') {
+          viewInstance.value?.flyToContour();
+        } else {
+          type === 'point' ? addPoint(data) : addPolyline(data);
+        }
+      }
+    },
+    { deep: true, immediate: true } // 初始化时立即执行
+  );
+};
 
 /**
  * 添加点标注
  * @param data 数据  数据格式 [lng, lat]
  */
-function addPoint (data) {
-    if (pointLayer) pointLayer.clear()
+function addPoint(data) {
+  const [lng, lat] = data;
 
-    const [lng, lat] = data
+  if (!lng || !lat) return;
 
-    if (!lng || !lat) return
+  viewer.entities.add({
+    position: Cartesian3.fromDegrees(lng, lat),
+    point: {
+      pixelSize: 10,
+      color: Cesium.Color.BLUE,
+      outlineColor: Cesium.Color.WHITE,
+      outlineWidth: 2,
+    },
+  });
 
-    let [newLng, newLat] = DC.CoordTransform.GCJ02ToWGS84(lng, lat)
-
-    let point = new DC.Point(new DC.Position(newLng, newLat))
-    pointLayer.addOverlay(point)
-
-    window.$viewer?.zoomTo(pointLayer)
+  // 定位到点位
+  const points = [[lng, lat]]; // 确保格式为二维数组
+  flyVisual({ positionsData: points, viewer, multiple: 10 });
 }
 
 /**
  * 添加点标注
  * @param data 数据  数据格式 [[lng, lat], [lng, lat], [lng, lat]]
  */
-function addPolyline (data) {
-    if (polylineLayer) polylineLayer.clear()
-
-    if (data.length === 0) return
-
-    const positionStr = data.map(item => {
-        const [lng, lat] = item
-
-        let [newLng, newLat] = DC.CoordTransform.GCJ02ToWGS84(lng, lat)
-
-        return `${newLng}, ${newLat}`
-    }).join(';')
-
-    let polyline = new DC.Polyline(positionStr)
-    polyline.setStyle({
-        width: 4,
-        material: new DC.PolylineTrailMaterialProperty({
-            color: DC.Color.DEEPSKYBLUE,
-            speed: 10
-        }),
-        clampToGround: true
-    })
-    polylineLayer.addOverlay(polyline)
-
-    const line = turf.lineString(positionStr.split(';').map(i => i.split(',')))
-    const bbox = turf.bbox(line)
-    const bboxPolygon = turf.bboxPolygon(bbox)
-    const scaledPolygon = turf.transformScale(bboxPolygon, 3)
-    const newBbox = turf.bbox(scaledPolygon)
-
-    window.$viewer?.flyToBounds(
-        newBbox,
-        { heading: 0, pitch: -90, roll: 0 },
-        () => { },
-        0
-    )
+async function addPolyline(data) {
+  await renderPreviewLine(data.url, data.type, data.cb, data.infos);
 }
 
 onMounted(() => {
-    nextTick(() => {
-        initMap()
-    })
-})
+  nextTick(() => {
+    initMap();
+  });
+});
 
-onUnmounted(() => {
-    if (pointLayer) {
-        window.$viewer?.removeLayer(pointLayer)
-        pointLayer = null
-    }
+onBeforeUnmount(() => {
+  var cesiumContainer = document.getElementById('viewer-container');
+  if (cesiumContainer) {
+    cesiumContainer.remove(); // 移除与地图相关的DOM元素
+  }
 
-    if (polylineLayer) {
-        window.$viewer?.removeLayer(polylineLayer)
-        polylineLayer = null
-    }
-
-    window.$viewer?.entities.removeAll()
-    window.$viewer?.imageryLayers.removeAll()
-    window.$viewer?.dataSources.removeAll()
-    let gl = window.$viewer.scene.context._originalGLContext
-    gl.canvas.width = 1
-    gl.canvas.height = 1
-
-    window.$viewer && window.$viewer.setTerrain()
-    window.$viewer && window.$viewer.destroy()
-    window.$viewer = null
-    delete window.$viewer
-    window.$Cesium = null
-    delete window.$Cesium
-    var cesiumContainer = document.getElementById('viewer-container')
-    if (cesiumContainer) {
-        cesiumContainer.remove() // 移除与地图相关的DOM元素
-    }
-})
+  viewer.entities.removeAll();
+  publicCesiumInstance.viewerDestroy();
+  viewer = null;
+});
 
 defineExpose({
-    initAddEntity
-})
+  initAddEntity,
+});
 </script>
 
 <script>
 export default {
-    name: 'MapContainer'
-}
+  name: 'MapContainer',
+};
 </script>
 
 <style lang="scss" scoped>
 .map-container {
-    position: relative;
-    width: 100% !important;
-    height: 100% !important;
-    overflow: hidden;
+  position: relative;
+  width: 100% !important;
+  height: 100% !important;
+  overflow: hidden;
 }
 
 .viewer-container {
-    position: absolute;
-    top: 50%;
-    left: 50%;
-    width: 120%;
-    height: 120%;
-    transform: translate(-50%, -50%);
+  position: absolute;
+  top: 0%;
+  left: 0%;
+  width: 100%;
+  height: 100%;
 }
-</style>
\ No newline at end of file
+</style>

--
Gitblit v1.9.3