From 977e332a5338942df338728dbfb77a359e35bd0b Mon Sep 17 00:00:00 2001
From: riku <risaku@163.com>
Date: 星期五, 09 五月 2025 12:25:21 +0800
Subject: [PATCH] 添加动态溯源相关逻辑(待完成)

---
 src/views/historymode/HistoryMode.vue |   23 +++++++----
 src/model/FactorDatas.js              |   15 +++++++
 src/utils/map/3dLayer.js              |   48 ++++++++++++++++--------
 3 files changed, 62 insertions(+), 24 deletions(-)

diff --git a/src/model/FactorDatas.js b/src/model/FactorDatas.js
index eba6446..f285080 100644
--- a/src/model/FactorDatas.js
+++ b/src/model/FactorDatas.js
@@ -1,6 +1,7 @@
 import { Factor } from './Factor';
 import calculate from '@/utils/map/calculate';
 import { Legend } from './Legend';
+import moment from 'moment';
 
 /**
  *
@@ -200,6 +201,20 @@
     });
   },
 
+  getByDate(s, e) {
+    const sTime = moment(s).format('YYYY-MM-DD HH:mm:ss');
+    const eTime = moment(e).format('YYYY-MM-DD HH:mm:ss');
+    const sIndex = this.times.findIndex((v) => {
+      return v == sTime;
+    });
+    const eIndex = this.times.findIndex((v) => {
+      return v == eTime;
+    });
+    if (sIndex != -1 && eIndex != -1) {
+      return this.getByIndex(sIndex, eIndex);
+    }
+  },
+
   // 鑾峰彇鏁版嵁闀垮害
   length: function () {
     return this.lnglats_GD.length;
diff --git a/src/utils/map/3dLayer.js b/src/utils/map/3dLayer.js
index 5f8c16f..5222ed4 100644
--- a/src/utils/map/3dLayer.js
+++ b/src/utils/map/3dLayer.js
@@ -30,6 +30,16 @@
   const fDatas = _factorDatas;
   const factor = _factor;
   drawMesh(fDatas, factor);
+
+  if (_polFactorDatasList.length > 0) {
+    _polCylinderList.forEach((p) => {
+      object3Dlayer.remove(p);
+    });
+    _polCylinderList = [];
+    _polFactorDatasList.forEach((e, i) => {
+      drawHighLight3DLayer(e, _polFactorList[i]);
+    });
+  }
   // console.log(map.getZoom());
 }
 
@@ -169,16 +179,12 @@
 /**
  * 缁樺埗楂樹寒鐨勬薄鏌撳尯鍩�3D绔嬮潰
  */
-var _polCylinder = undefined;
-var _polFactorDatas = {
-    lnglats: [],
-    heights: [],
-    type: ''
-  },
+var _polCylinderList = [];
+var _polFactorDatasList = [],
   //褰撳墠閫変腑鐨勭洃娴嬪洜瀛愭暟鎹�
-  _polFactor = {};
+  _polFactorList = [];
 function drawHighLight3DLayer(fDatas, factor) {
-  const offsetH = 40;
+  const offsetH = 100;
 
   const lnglats_GD = fDatas.lnglats_GD;
   const coors = fDatas.coors_GD;
@@ -221,21 +227,23 @@
       }
     }
 
-    // const color = [1, 1, 1, 0.75]
-    const color = [1, 0, 0, 0.75];
+    const color = [1, 1, 1, 1];
+    // const color = [1, 0, 0, 0.75];
     geometry.vertexColors.push.apply(geometry.vertexColors, color); //搴曢儴椤剁偣棰滆壊
     geometry.vertexColors.push.apply(geometry.vertexColors, color); //椤堕儴椤剁偣棰滆壊
   }
 
   // 7.鏍规嵁鍚堝苟閫夐」閲嶇疆鎴栨柊澧炲綋鍓嶇紦瀛樻暟鎹�
-  _polFactorDatas = fDatas;
-  _polFactor = factor;
-  if (_polCylinder != undefined) {
-    object3Dlayer.remove(_polCylinder);
-  }
+  _polFactorDatasList.push(fDatas);
+  _polFactorList.push(factor);
+  // if (_polCylinderList.length > 0) {
+  //   _polCylinderList.forEach((p) => {
+  //     object3Dlayer.remove(p);
+  //   });
+  // }
   object3Dlayer.add(cylinder);
 
-  _polCylinder = cylinder;
+  _polCylinderList.push(cylinder);
 }
 
 export default {
@@ -244,6 +252,14 @@
     if (_cylinder != undefined) {
       object3Dlayer.remove(_cylinder);
     }
+    if (_polCylinderList.length > 0) {
+      _polCylinderList.forEach((p) => {
+        object3Dlayer.remove(p);
+      });
+      _polCylinderList = [];
+    }
+    _polFactorDatasList = [];
+    _polFactorList = [];
   },
 
   drawMesh: drawMesh,
diff --git a/src/views/historymode/HistoryMode.vue b/src/views/historymode/HistoryMode.vue
index 1772dfd..10673f9 100644
--- a/src/views/historymode/HistoryMode.vue
+++ b/src/views/historymode/HistoryMode.vue
@@ -92,6 +92,8 @@
       factorType: defaultOptions(TYPE0).value,
       // 鐩戞祴鏁版嵁
       factorDatas: new FactorDatas(),
+      // 姹℃煋婧簮缁撴灉
+      pollutionData: undefined,
       // 鍐冲畾缁樺埗3D鍥惧舰鏃舵槸鍚︿笌鍘熷浘鍍忓悎骞�
       merge: false,
       // 鍐冲畾缁樺埗瀹�3D鍥惧舰鍚庡湴鍥捐瑙掓槸鍚﹁嚜鍔ㄥ洖涓�
@@ -110,7 +112,9 @@
   watch: {
     factorType(nValue, oValue) {
       if (nValue != oValue && this.status == 0) {
+        Layer.clear();
         this.draw();
+        this.drawHighlightPollution();
       }
     }
   },
@@ -194,12 +198,21 @@
         }
       );
     },
+    drawHighlightPollution() {
+      this.pollutionData.forEach((e) => {
+        if (this.factorType == e.factorId + '') {
+          const fDatas = this.factorDatas.getByDate(e.startDate, e.endDate);
+          Layer.drawHighLight3DLayer(fDatas, fDatas.factor[this.factorType]);
+        }
+      });
+    },
     onFetchData(deviceType, data) {
       if (this.isUnmounted) return;
       // todo 鏍规嵁璁惧绫诲瀷鍒囨崲鍦板浘鐩戞祴鍥犲瓙灞曠ず鍗曢�夋銆佹姌绾垮浘澶嶉�夋銆佹暟鎹〃鏍煎閫夋鐨勫洜瀛愮被鍨�
       this.deviceType = deviceType;
       this.factorDatas.setData(data, this.drawMode, () => {
         this.factorDatas.refreshHeight(this.factorType);
+        Layer.clear();
         this.draw();
       });
     },
@@ -227,14 +240,8 @@
     handleClick() {
       const { missionCode } = this.mission;
       dataAnalysisApi.pollutionTrace(missionCode).then((res) => {
-        res.data.forEach((e) => {
-          const fDatas = new FactorDatas();
-          fDatas.setData(e.dataVoList, this.drawMode, () => {
-            fDatas.refreshHeight(this.factorType);
-            Layer.drawHighLight3DLayer(fDatas, fDatas.factor[this.factorType]);
-            console.log(e.dataVoList);
-          });
-        });
+        this.pollutionData = res.data;
+        this.drawHighlightPollution();
       });
     }
   },

--
Gitblit v1.9.3