From 2b4ddd668550749813c4e02b5d5100842763e23b Mon Sep 17 00:00:00 2001
From: guonan <guonan201020@163.com>
Date: 星期四, 17 四月 2025 17:41:35 +0800
Subject: [PATCH] 划区域坡度分析

---
 src/utils/tools.js |  151 +++++++++++++++++++++++++++++++++-----------------
 1 files changed, 100 insertions(+), 51 deletions(-)

diff --git a/src/utils/tools.js b/src/utils/tools.js
index 6604c70..6b7c835 100644
--- a/src/utils/tools.js
+++ b/src/utils/tools.js
@@ -3,6 +3,7 @@
 // import cameraIconSel from "../assets/images/base/瑙嗛娴嬬偣sel.png"
 import { ElLoading, ElMessage } from "element-plus";
 import RainEffect from './rain'
+import SnowEffect from './snow'
 let layerIsOpen = false;
 const Cesium = SmartEarth.Cesium;
 const colorAll = {
@@ -21,6 +22,9 @@
   slopeArrow: null,
   elevationTool: null,
   rainEffect: null,
+  snowEffect: null, // 鏂板闆晥鏋滃疄渚�
+  regionTerrain: null,
+  polygonPosition: [],
 
   init(earthCtrl) {
     this.earthCtrl = earthCtrl;
@@ -33,7 +37,20 @@
     const b = parseInt(hex.substring(4, 6), 16) / 255;
     return new Cesium.Color(r, g, b, 1.0);
   },
-  // 澶╂皵
+  // 娓呴櫎澶╂皵鐗规晥
+  delRain() {
+    if (this.rainEffect) {
+      this.rainEffect.destroy()
+      this.rainEffect = null
+    }
+  },
+  delSnow() {
+    if (this.snowEffect) {
+      this.snowEffect.destroy();
+      this.snowEffect = null;
+    }
+  },
+  // 闆ㄥぉ妯℃嫙
   toggleRain(option, show) {
     console.log(option, 'option')
     // 鍏堥攢姣佹棫瀹炰緥
@@ -48,8 +65,81 @@
       color: this.hexToColor(option.rainColor)  // 闆ㄧ殑棰滆壊
     })
   },
+  // 闆ぉ妯℃嫙
+  toggleSnow(option = {}, show = true) {
+    console.log(option, 'option');
+    const defaultOption = {
+      snowSize: 0.02, // 榛樿闆殑澶у皬
+      snowSpeed: 100.0, // 榛樿闆殑閫熷害
+      snowColor: "#ffffff", // 榛樿棰滆壊锛氱櫧鑹�
+    };
+    option = { ...defaultOption, ...option };
+    if (this.snowEffect) {
+      this.snowEffect.destroy();
+      this.snowEffect = null;
+    }
+    this.snowEffect = new SnowEffect(earthCtrl.viewer, {
+      snowSize: option.snowSize, // 闆殑澶у皬
+      snowSpeed: option.snowSpeed, // 闆殑閫熷害
+      snowColor: this.hexToColor(option.snowColor), // 闆殑棰滆壊
+    });
+
+    // 鎺у埗鏄剧ず/闅愯棌
+    if (this.snowEffect) {
+      this.snowEffect.show(show);
+    }
+  },
+  // 鍖哄煙鍒掑垎宸ュ叿
+  hfqy() {
+    // 鍒濆鍖栧尯鍩熷湴褰�
+    this.regionTerrain = earthCtrl.factory.createRegionTerrain({});
+    this.polygonPosition = [];
+
+    // 鍒涘缓缁樺埗宸ュ叿
+    const drawTool = earthCtrl.shapeTool.createDrawShapeTool((e) => {
+      try {
+        if (!e || !e.result) {
+          throw new Error('Invalid drawing result');
+        }
+
+        // 杞崲鍧愭爣骞跺瓨鍌�
+        const polygonI = [];
+        for (const point of e.result) {
+          const cartographic = earthCtrl.coreMap.scene.globe.ellipsoid.cartesianToCartographic(point);
+          const lon = Cesium.Math.toDegrees(cartographic.longitude);
+          const lat = Cesium.Math.toDegrees(cartographic.latitude);
+
+          polygonI.push(lon, lat, 0);
+          this.polygonPosition.push(lon, lat);
+        }
+
+        // 璁剧疆鍖哄煙鍦板舰
+        this.regionTerrain.setPositions(this.polygonPosition);
+        this.regionTerrain.setRegionEnabled(true);
+
+        // 娓呴櫎缁樺埗宸ュ叿
+        drawTool.removeFromMap();
+      } catch (error) {
+        console.error('Error during region drawing:', error);
+        drawTool.removeFromMap();
+      }
+    });
+
+    return drawTool;
+  },
+  // 鍧″悜绠ご
+  pxjt(colors, angles) {
+    this.hfqy()
+    this.slopeArrow = earthCtrl.factory.createSlopeArrow({});
+    this.slopeArrow.setColorsAndAngles(colors, angles);
+    this.regionTerrain.setPositions(this.polygonPosition);
+    this.regionTerrain.setRegionEnabled(true);
+    this.slopeArrow.setSlopeType(1);
+  },
+
   // 鍧″害鍒嗘瀽
   pdfx(option) {
+    this.hfqy()
     this.elevationTool = new SmartEarth.ElevationTool(earthCtrl)
     if (option.terrainRender == '1') {
       this.elevationTool.type = 'slope'
@@ -61,63 +151,22 @@
     this.elevationTool.setWidth(option.lineWidth)
     this.elevationTool.setContourColor(option.color);
     this.elevationTool.render();
-    console.log(this.elevationTool, 'eleelelelelelelel')
   },
-  // 鍧″悜绠ご
-  pxjt(colors, angles) {
-    this.slopeArrow = earthCtrl.factory.createSlopeArrow({});
-    this.slopeArrow.setColorsAndAngles(colors, angles);
 
-    // 鍒涘缓缁樺埗宸ュ叿
-    const drawTool = earthCtrl.shapeTool.createDrawShapeTool((e) => {
-      const polygonI = [];
-      const polygonPosition = [];
-      for (const i of e.result) {
-        const ellipsoid = earthCtrl.coreMap.scene.globe.ellipsoid;
-        const cartographic = ellipsoid.cartesianToCartographic(i);
-
-        const lon = Cesium.Math.toDegrees(cartographic.longitude);
-        const lat = Cesium.Math.toDegrees(cartographic.latitude); // 绾害
-        polygonI.push(lon, lat, 0);
-        polygonPosition.push(lon, lat);
-      }
-      const PolygonArr = [];
-      PolygonArr.push({
-        id: earthCtrl.factory.createUUID(),
-        polygon: polygonI,
-      });
-
-      // 娓呴櫎缁樺埗宸ュ叿
-      drawTool.removeFromMap();
-      // 璁剧疆鍧″害绠ご鐨勪綅缃拰绫诲瀷
-      this.slopeArrow.setPositions(polygonPosition);
-      this.slopeArrow.setSlopeType(1);
-      this.slopeArrow.setRegionEnabled(true);
-      console.log(this.slopeArrow, 'slope')
-    });
-  },
-  // 鍏抽棴鍧″悜绠ご
-  gbpxjt() {
+  // 娓呯悊鎵�鏈夊垎鏋愬伐鍏�
+  cleanupAnalysisTools() {
+    // 鍧″悜绠ご
     if (this.slopeArrow) {
       this.slopeArrow.setSlopeType(0);
+      this.slopeArrow = null;
     }
-  },
-
-
-  toggleSnow(weather = "snow", show) {
-    if (show) {
-      earthCtrl.environment.showEffect(weather);
-    } else {
-      let snowValue = {
-        test1: 2,
-        test2: 1.0,
-        test3: 0.5,
-        test4: 0.5,
-      };
-      earthCtrl.environment.disableEffect(weather);
+    // 閫夋嫨鍖哄煙
+    if (this.regionTerrain) {
+      this.regionTerrain.setRegionEnabled(false);
+      this.regionTerrain = null;
     }
+    this.polygonPosition = [];
   },
-
   // 鏍囩粯
   CreateLabel(pic, show) {
     if (show) {

--
Gitblit v1.9.3