From c832bf2e80ac465e71b7a1c1f7a59d4252030989 Mon Sep 17 00:00:00 2001
From: 张含笑 <zhx18749296735@163.com>
Date: Tue, 05 Aug 2025 17:33:08 +0800
Subject: [PATCH] feat:事件工单滚动条

---
 src/components/map-container/mapContainer.vue |  153 +++++++++++----------------------------------------
 1 files changed, 33 insertions(+), 120 deletions(-)

diff --git a/src/components/map-container/mapContainer.vue b/src/components/map-container/mapContainer.vue
index d51ae86..839228b 100644
--- a/src/components/map-container/mapContainer.vue
+++ b/src/components/map-container/mapContainer.vue
@@ -14,11 +14,15 @@
             <div class="content">
                 <slot name="content"></slot>
             </div>
+
+            <PlanarRouteLineList :curRouteLineData="curRouteLineData" @routeLineListClick="routeLineListClick" />
         </div>
     </div>
 </template>
 
 <script setup>
+import PlanarRouteLineList from '@/components/PlanarRouteLineList/PlanarRouteLineList.vue'
+
 import * as Cesium from 'cesium'
 import { Cartesian3, Terrain, Viewer } from 'cesium'
 import { PublicCesium } from '@/utils/cesium/publicCesium'
@@ -26,7 +30,7 @@
 import { flyVisual } from '@/utils/cesium/mapUtil'
 import * as turf from '@turf/turf'
 
-import { nextTick, onMounted, onUnmounted } from 'vue'
+import { nextTick, onBeforeUnmount, onMounted, onUnmounted } from 'vue'
 import { read } from 'xlsx'
 
 import startPng from '@/assets/map_images/Startingpointicon.png'
@@ -34,11 +38,13 @@
 import rwqfdImg from '@/assets/images/task/arrow-right-blue.png'
 import newNumPoint from '@/assets/images/task/custom-point.png'
 
-window.$viewer = null
-window.$Cesium = null
-let pointLayer = null
-let polylineLayer = null
-let pointHtmlLayer = null
+import { useRouteLine } from '@/hooks/useRouteLine/useRouteLine.js'
+
+// 加载航线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'
@@ -51,10 +57,12 @@
     }
 })
 
-
 async function initMap () {
-    if (window.$viewer) return
-    window.$Cesium = new PublicCesium({ dom: 'viewer-container' }).getViewer()
+    if (viewer) return
+    publicCesiumInstance = new PublicCesium({ dom: 'viewer-container' })
+    viewer = publicCesiumInstance.getViewer()
+
+    initViewer(viewer)
     isViewerReady.value = true
 }
 
@@ -67,6 +75,8 @@
     watch(() => isViewerReady.value,
         (ready) => {
             if (ready) {
+                viewer.entities.removeAll()
+
                 type === 'point' ? addPoint(data) : addPolyline(data)
             }
         },
@@ -79,12 +89,11 @@
  * @param data 数据  数据格式 [lng, lat]
  */
 function addPoint (data) {
-
     const [lng, lat] = data
 
     if (!lng || !lat) return
 
-    window.$Cesium.entities.add({
+    viewer.entities.add({
         position: Cartesian3.fromDegrees(lng, lat),
         point: {
             pixelSize: 10,
@@ -96,92 +105,15 @@
 
     // 定位到点位
     const points = [[lng, lat]]  // 确保格式为二维数组
-    flyVisual(points, window.$Cesium, 4)
+    flyVisual(points, viewer, 4)
 }
 
 /**
  * 添加点标注
  * @param data 数据  数据格式 [[lng, lat], [lng, lat], [lng, lat]]
  */
-function addPolyline (data) {
-    if (polylineLayer) polylineLayer.clear()
-    if (pointHtmlLayer) pointHtmlLayer.clear()
-
-    if (data.length === 0) return
-
-    const positionStr = data.map(item => {
-        const [lng, lat] = item
-
-        return Cartesian3.fromDegrees(Number(lng), Number(lat))
-    })
-    // 路径线
-	window.$Cesium.entities.add({
-		id: `polyline`,
-		polyline: {
-			width: 4,
-			positions: positionStr,
-			material: new ImageTrailMaterial({
-                image: rwqfdImg,  // 使用导入的图片
-                repeat: {
-                    x: 10,  // 调整图片重复次数
-                    y: 1
-                },
-                speed: 10,  // 调整速度
-                color: Cesium.Color.WHITE  // 可以调整图片的颜色混合
-            }),
-			clampToGround: false,
-		},
-	})
-    positionStr.forEach((point, index) => {
-		let setting = {}
-		if (index === 0) {
-			setting = {
-				position: point,
-				billboard: {
-					image: startPng,
-					outlineWidth: 0,
-					width: 30,
-					height: 30,
-					scale: 1.0,
-				},
-			}
-		} else if (index === positionStr.length - 1) {
-			setting = {
-				position: point,
-				id: `point_${index}`,
-				billboard: {
-					image: endPng,
-					outlineWidth: 0,
-					width: 30,
-					height: 30,
-					scale: 1.0,
-					verticalOrigin: Cesium.VerticalOrigin.TOP, // 添加这行确保图标正确显示
-					pixelOffset: new Cesium.Cartesian2(0, -20), // 根据需要调整偏移量
-				},
-			}
-		} else {
-			setting = {
-				position: point,
-				id: `point_${index}`,
-				label: {
-					text: `${index}`,
-					font: 'bold 14px serif',
-					fillColor: Cesium.Color.WHITE,
-					pixelOffset: new Cesium.Cartesian2(1, 0), // 根据需要调整偏移量
-					eyeOffset: new Cesium.Cartesian3(0, 0, -10), // 使标签在点的上方
-				},
-				billboard: {
-					image: new Cesium.ConstantProperty(newNumPoint),
-					width: 30,
-					height: 30,
-				},
-				offset: new Cesium.Cartesian2(10, 30),
-			}
-		}
-		window.$Cesium.entities.add(setting)
-	})
-    // 定位到点位
-    flyVisual(data, window.$Cesium, 4)
+async function addPolyline (data) {
+    await renderPreviewLine(data.url, data.type, data.cb, data.infos)
 }
 
 onMounted(() => {
@@ -190,34 +122,16 @@
     })
 })
 
-onUnmounted(() => {
-    if (pointLayer) {
-        window.$viewer?.removeLayer(pointLayer)
-        pointLayer = null
-    }
-
-    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
+onBeforeUnmount(() => {
     var cesiumContainer = document.getElementById('viewer-container')
     if (cesiumContainer) {
         cesiumContainer.remove() // 移除与地图相关的DOM元素
     }
+
+    viewer.entities.removeAll()
+    publicCesiumInstance.viewerDestroy()
+    viewer = null
+
 })
 
 defineExpose({
@@ -241,10 +155,9 @@
 
 .viewer-container {
     position: absolute;
-    top: 50%;
-    left: 50%;
-    width: 120%;
-    height: 120%;
-    transform: translate(-50%, -50%);
+    top: 0%;
+    left: 0%;
+    width: 100%;
+    height: 100%;
 }
 </style>
\ No newline at end of file

--
Gitblit v1.9.3