From 62819ed2a4e2c109c08e1925712fc7f0907b6b56 Mon Sep 17 00:00:00 2001
From: 罗广辉 <guanghui.luo@foxmail.com>
Date: Wed, 09 Apr 2025 11:46:20 +0800
Subject: [PATCH] feat: 轮廓线未重置

---
 src/views/Home/useMapAggregation/useMapAggregation.js |  122 +++++++++++++++++++++++-----------------
 1 files changed, 71 insertions(+), 51 deletions(-)

diff --git a/src/views/Home/useMapAggregation/useMapAggregation.js b/src/views/Home/useMapAggregation/useMapAggregation.js
index eb59787..442c9d5 100644
--- a/src/views/Home/useMapAggregation/useMapAggregation.js
+++ b/src/views/Home/useMapAggregation/useMapAggregation.js
@@ -198,12 +198,27 @@
     const outlineGJson = await getOutLine(jsonPathPre, hierarchy)
     scalingJudgment.forEach(item => item.show && (item.outline = outlineGJson))
     const [longitude, latitude] = outlineGJson.features[0].properties.centroid
-    flyTo({ longitude, latitude }, 0, scalingJudgment[(hierarchy.length - 3) * (-1)].height)
+    const height = scalingJudgment[(hierarchy.length - 3) * (-1)].height
+    setCenterPosition({longitude, latitude,height})
+    flyTo({ longitude, latitude }, 0, height)
   }
+
+  const userAreaPosition = computed(() => store.state.home.userAreaPosition);
+
+  const setCenterPosition = (position) => {
+    store.commit('setCurrentAreaPosition', position)
+		if (!userAreaPosition.value.longitude){
+			store.commit('setUserAreaPosition', position)
+		}
+  }
+
+
+  let needFly = true
 
   watch(
     selectedAreaCode,
     async (newValue, oldValue) => {
+      needFly = true
       if (!viewer) return
       viewer.scene.postRender.removeEventListener(determineScaling)
       initMapData(newValue).then(() => {
@@ -247,32 +262,28 @@
   // 渲染轮廓
   const renderOutline = item => {
     item.outline &&
-      Cesium.GeoJsonDataSource.load(item.outline).then(dataSource => {
-        viewer.dataSources.add(dataSource)
-        const entities = dataSource.entities.values
-        entities.forEach(entity => {
-          // 隐藏多边形填充
-          entity.polygon.material = Cesium.Color.TRANSPARENT
-          entity.polygon.outline = false // 关闭原生轮廓
-          // 创建独立折线作为轮廓
-          const positions = entity.polygon.hierarchy.getValue().positions
-          viewer.entities.add({
-            polyline: {
-              positions: positions,
-              width: 5, // 直接设置宽度
-              material: new Cesium.PolylineGlowMaterialProperty({
-                glowPower: 0.5,
-                color: Cesium.Color.AQUA,
-              }),
-              clampToGround: true, // 贴地显示
-            },
-          })
+    Cesium.GeoJsonDataSource.load(item.outline).then(dataSource => {
+      const entities = dataSource.entities.values
+      entities.forEach((entity,index) => {
+        // 创建独立折线作为轮廓
+        const positions = entity.polygon.hierarchy.getValue().positions
+        viewer.entities.add({
+          id: `aggregation-outline-${index}`,
+          polyline: {
+            positions: positions,
+            width: 5, // 直接设置宽度
+            material: new Cesium.PolylineGlowMaterialProperty({
+              glowPower: 0.5,
+              color: Cesium.Color.AQUA,
+            }),
+          },
         })
       })
+    })
   }
 
   // 聚合机巢
-  const aggregation = (item, flyTo) => {
+  const aggregation = (item) => {
     if (!item.gJson) return
     const featuresList = item.gJson.features.map(item1 => {
       // const {lng,lat} = getCenterPoint(item1.geometry.coordinates[0][0])
@@ -286,7 +297,7 @@
     // 遍历特征并添加实体
     featuresList.forEach((feature, index) => {
       if (!feature.position) return
-      const position = Cesium.Cartesian3.fromDegrees(feature.position[0], feature.position[1])
+      const position = Cesium.Cartesian3.fromDegrees(feature.position[0], feature.position[1],12000)
       viewer.entities.add({
         position: position,
         id: `aggregation-name-${index}`,
@@ -333,10 +344,10 @@
       return arrColor[++index % arrColor.length]
     }
 
-    // 加载新的 GeoJSON 数据
+    // 加载边界
     Cesium.GeoJsonDataSource.load(item.gJson).then(dataSource => {
       viewer.dataSources.add(dataSource)
-      item.dataSource = dataSource // 保存数据源以便后续删除
+      item.BJDataSource = dataSource // 保存数据源以便后续删除
       // 获取数据源中的实体
       const entities = dataSource.entities.values
 
@@ -353,7 +364,7 @@
         entity.polygon.outline = false // 显示边框
       })
 
-      flyTo && viewer.flyTo(dataSource, {
+      needFly && viewer.flyTo(dataSource, {
         offset: new Cesium.HeadingPitchRange(
           0, // heading: 0 (朝向不变)
           Cesium.Math.toRadians(-60), // pitch: -90° (垂直向下)
@@ -361,6 +372,7 @@
         ),
         duration: 0.5,
       })
+      needFly = false
     })
   }
 
@@ -394,29 +406,33 @@
   // 左键单机事件
   const singleMachineEvent = async click => {
     const pickedObject = viewer.scene.pick(click.position)
-    if (Cesium.defined(pickedObject) && pickedObject.id) {
-      const entity = pickedObject.id
-      currentEntity = entity
-      positionC3 = entity?.position?._value
-      if (!positionC3) return
-      removeLabel()
-      const customData = entity.properties.customData._value.data
-      console.log('customData', customData)
-      switch (customData.type) {
-        case 'deviceAggregation':
-          viewer.scene.postRender.addEventListener(labelBoxRender)
-          break
-        case 'device':
-          store.commit('setSingleUavHome', { id: '123' })
-          break
-        case 'eventAggregation':
-          break
-        case 'event':
-          viewer.scene.postRender.addEventListener(labelBoxRender)
-          break
-        default:
-          break
-      }
+    if (!(Cesium.defined(pickedObject) && pickedObject.id)) return
+    const entity = pickedObject.id
+    currentEntity = entity
+    const entityPosition = entity?.position?._value
+    if (!entityPosition) return
+    if (entityPosition){
+      positionC3 = entityPosition
+    }
+    removeLabel()
+    const customData = entity?.properties?.customData?._value?.data
+    if (!customData) return
+    console.log('customData', customData)
+    switch (customData.type) {
+      case 'deviceAggregation':
+        viewer.scene.postRender.addEventListener(labelBoxRender)
+        break
+      // todo 待对接
+      case 'device':
+        store.commit('setSingleUavHome', { id: '123' })
+        break
+      case 'eventAggregation':
+        break
+      case 'event':
+        viewer.scene.postRender.addEventListener(labelBoxRender)
+        break
+      default:
+        break
     }
   }
 
@@ -429,8 +445,12 @@
 
   // 移除 点 和 gjson 实体
   const removeEntities = () => {
-    viewer.dataSources?.removeAll(true)
-    // viewer.entities?.removeAll();
+    // dataSources移除
+    scalingJudgment.forEach(item => {
+      item.BJDataSource && viewer.dataSources.remove(item.BJDataSource)
+      item.BJDataSource = null
+    })
+    // entities移除
     const entitiesIDs = viewer.entities.values.map(i => i.id)
     entitiesIDs.forEach(item => {
       item.includes('aggregation-') && viewer.entities.removeById(item)

--
Gitblit v1.9.3