From e4c7bca105e64c047fbcd6bbb53ff5d32b0c5fd6 Mon Sep 17 00:00:00 2001
From: 张含笑 <zhx18749296735@163.com>
Date: Tue, 10 Jun 2025 14:19:29 +0800
Subject: [PATCH] feat:日历去掉今日

---
 src/components/map-container/mapContainer.vue |  218 +++++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 157 insertions(+), 61 deletions(-)

diff --git a/src/components/map-container/mapContainer.vue b/src/components/map-container/mapContainer.vue
index f3238d2..d51ae86 100644
--- a/src/components/map-container/mapContainer.vue
+++ b/src/components/map-container/mapContainer.vue
@@ -2,15 +2,15 @@
  * @Author: shuishen 1109946754@qq.com
  * @Date: 2024-10-25 15:07:51
  * @LastEditors: shuishen 1109946754@qq.com
- * @LastEditTime: 2025-04-10 13:04:30
- * @FilePath: \drone-web-manage\src\components\map-container\MapContainer.vue
+ * @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. 
 -->
 <template>
     <div class="map-container">
-        <div class="viewer-container" id="viewer-container">
+        <div class="viewer-container ztzf-cesium" id="viewer-container">
             <div class="content">
                 <slot name="content"></slot>
             </div>
@@ -19,11 +19,27 @@
 </template>
 
 <script setup>
+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'
+
 import { nextTick, onMounted, onUnmounted } from 'vue'
+import { read } from 'xlsx'
+
+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'
 
 window.$viewer = null
 window.$Cesium = null
 let pointLayer = null
+let polylineLayer = null
+let pointHtmlLayer = null
+
 const { VITE_APP_BASE } = import.meta.env
 // import * as Cesium from 'cesium'
 // import 'cesium/Build/Cesium/Widgets/widgets.css'
@@ -36,71 +52,142 @@
 })
 
 
-watch(
-    [() => isViewerReady.value, () => rowDetails],
-    ([ready, detail]) => {
-        if (ready && detail?.location) {
-            const [lng, lat] = detail.location
-            if (!lng || !lat) return
-            window.$viewer?.zoomToPosition(new DC.Position(
-                lng,
-                lat,
-                1000,
-                0,
-                -90,
-                0
-            ), () => {
-            })
-
-            let point = new DC.Point(new DC.Position(lng, lat))
-            pointLayer.addOverlay(point)
-        }
-    },
-    { deep: true, immediate: true } // 初始化时立即执行
-)
-
-function initMap () {
+async function initMap () {
     if (window.$viewer) return
+    window.$Cesium = new PublicCesium({ dom: 'viewer-container' }).getViewer()
+    isViewerReady.value = true
+}
 
-    nextTick(() => {
-        DC.ready({
-            // Cesium: Cesium,
-            baseUrl: `${VITE_APP_BASE}/libs/dc-sdk/resources/`,
-        }).then(() => {
-            window.$Cesium = DC.getLib('Cesium')
+/**
+ * 初始化标注添加
+ * @param type 类型
+ * @param data 数据
+ */
+const initAddEntity = (type, data) => {
+    watch(() => isViewerReady.value,
+        (ready) => {
+            if (ready) {
+                type === 'point' ? addPoint(data) : addPolyline(data)
+            }
+        },
+        { deep: true, immediate: true } // 初始化时立即执行
+    )
+}
 
-            // 天地图地图
-            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',
-            })
+/**
+ * 添加点标注
+ * @param data 数据  数据格式 [lng, lat]
+ */
+function addPoint (data) {
 
-            window.$viewer = new DC.Viewer('viewer-container')
-            window.$viewer.locationBar.enable = false
+    const [lng, lat] = data
 
-            window.$viewer?.imageryLayers.addImageryProvider(imageryProvider_stand)
-            window.$viewer?.imageryLayers.addImageryProvider(imageryProvider_standZh)
+    if (!lng || !lat) return
 
-            pointLayer = new DC.VectorLayer('pointLayer')
-            window.$viewer?.addLayer(pointLayer)
-
-            isViewerReady.value = true
-        })
+    window.$Cesium.entities.add({
+        position: Cartesian3.fromDegrees(lng, lat),
+        point: {
+            pixelSize: 10,
+            color: Cesium.Color.BLUE,
+            outlineColor: Cesium.Color.WHITE,
+            outlineWidth: 2
+        }
     })
+
+    // 定位到点位
+    const points = [[lng, lat]]  // 确保格式为二维数组
+    flyVisual(points, window.$Cesium, 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)
 }
 
 onMounted(() => {
-    initMap()
+    nextTick(() => {
+        initMap()
+    })
 })
 
 onUnmounted(() => {
@@ -109,12 +196,17 @@
         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
+    // 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()
@@ -127,6 +219,10 @@
         cesiumContainer.remove() // 移除与地图相关的DOM元素
     }
 })
+
+defineExpose({
+    initAddEntity
+})
 </script>
 
 <script>

--
Gitblit v1.9.3