From 559f0776123a2205863b5787d5b8e1e012d397d3 Mon Sep 17 00:00:00 2001
From: suerprisePlus <15810472099@163.com>
Date: 星期三, 23 十月 2024 15:29:34 +0800
Subject: [PATCH] 灾害效果修改

---
 src/views/visualization/list/mapWeather.js |   91 +++++++++++++++++++++++++++++++++++++++------
 1 files changed, 78 insertions(+), 13 deletions(-)

diff --git a/src/views/visualization/list/mapWeather.js b/src/views/visualization/list/mapWeather.js
index 222f65f..21f8beb 100644
--- a/src/views/visualization/list/mapWeather.js
+++ b/src/views/visualization/list/mapWeather.js
@@ -1,8 +1,9 @@
 import mapServer from '../../../assets/js/mapSdk/mapServe';
-
+import * as turf from '@turf/turf';
 const mapWeather = {
     regionWeather: null,
     particle: null,
+    showRain: 'ShowRain',
     closeRegionWeather() {
         if (this.regionWeather) {
             this.regionWeather.enableWeatherType = SmartEarth.Cesium.RegionWeather.TYPE_NONE;
@@ -12,23 +13,34 @@
             this.particle.deleteObject();
             this.particle = null;
         }
+        for (var i in Viewer.scene.primitives._primitives) {
+            const name = Viewer.scene.primitives._primitives[i].name;
+            if (name && name == this.showRain) {
+                Viewer.scene.primitives.remove(Viewer.scene.primitives._primitives[i]);
+            }
+        }
     },
     setRegionWeatherType(response) {
         this.closeRegionWeather();
         if (!this.regionWeather) {
             this.getRegionWather(response);
         }
+
         const coord = this.getCoord(response);
-        earthCtrl.camera.flyTo(coord[0], coord[1], 1000, 0, -90, 0, 0);
+
         switch (response.type) {
             case 'rain':
-                this.showRain();
+                //  earthCtrl.camera.flyTo(coord[0], coord[1], 8000, 0, -90, 0, 0);
+                this.showRain(response);
+
                 break;
             case 'fire':
                 this.showFire(response);
+                earthCtrl.camera.flyTo(coord[0], coord[1], 1000, 0, -90, 0, 0);
                 break;
             case 'snow':
                 this.showSnow();
+                earthCtrl.camera.flyTo(coord[0], coord[1], 1000, 0, -90, 0, 0);
                 break;
         }
     },
@@ -44,19 +56,74 @@
             obj,
             {
                 translation: SmartEarth.Cesium.Cartesian3.fromElements(0, 0, 0), //骞崇Щ
-                particleSize:10
+                particleSize: 10,
             },
             function (data) {}
         );
     },
 
-    showRain() {
-        if (this.regionWeather) {
-            this.regionWeather.enableWeatherType = SmartEarth.Cesium.RegionWeather.TYPE_RAIN;
-            this.regionWeather.regionAlpha = 0.6;
-            this.regionWeather.regionGradientDistance = 300;
+    showRain(res) {
+        var area = [];
+        var std =[];
+        for (var i = 0; i < res.area.length; i += 3) {
+            area.push(res.area[i]);
+            area.push(res.area[i + 1]);
+            std.push([res.area[i],res.area[i + 1]])
         }
+        std.push(std[0])
+ 
+        
+        const polygon = turf.polygon([std]);
+
+        const centerPoint = turf.center(polygon);
+        const coord= centerPoint.geometry.coordinates;
+        earthCtrl.camera.flyTo(coord[0], coord[1], 8000, 0, -90, 0, 0);
+
+        const geometry = new Cesium.PolygonGeometry({
+            polygonHierarchy: new Cesium.PolygonHierarchy(Cesium.Cartesian3.fromDegreesArray(area)),
+            height: 0, // 搴曢潰楂樺害
+            extrudedHeight: 0.2, // 姘撮潰楂樺害
+            ellipsoid: Cesium.Ellipsoid.WGS84,
+        });
+
+        // 2. 鍒涘缓GeometryInstance
+        const geometryInstances = new Cesium.GeometryInstance({ geometry });
+
+        // 3. 鍒涘缓material
+        const material = new Cesium.Material({
+            fabric: {
+                type: 'Water',
+                uniforms: {
+                    baseWaterColor: new Cesium.Color(0.25, 0.6, 0.9, 0.5), // 姘撮潰棰滆壊
+                    normalMap: config.images + 'waterNormals.jpg', // 璐村浘
+                    frequency: 5000, // 姘存尝绾规暟閲�
+                    animationSpeed: 0.02, // 姘存祦閫�
+                    amplitude: 30, // 姘存尝绾规尟鍔ㄥ箙搴�
+                    specularIntensity: 5, // 闀滈潰鍙嶅皠寮哄害
+                },
+            },
+        });
+        // 4. 鍒涘缓Appearance
+        const appearance = new Cesium.EllipsoidSurfaceAppearance({
+            aboveGround: true,
+            material,
+        });
+        // 5. 鍒涘缓primitive
+        var primitive = new Cesium.Primitive({
+            geometryInstances,
+            appearance,
+        });
+        primitive.name = this.showRain;
+        Viewer.scene.primitives.add(primitive);
+
+        // Viewer.camera.lookAt(primitive.boundingSphere.center, new Cesium.HeadingPitchRange(0.0, Cesium.Math.toRadians(-90), 5000));
+        // if (this.regionWeather) {
+        //     this.regionWeather.enableWeatherType = SmartEarth.Cesium.RegionWeather.TYPE_RAIN;
+        //     this.regionWeather.regionAlpha = 0.6;
+        //     this.regionWeather.regionGradientDistance = 300;
+        // }
     },
+
     showSnow() {
         if (this.regionWeather) {
             this.regionWeather.enableWeatherType = SmartEarth.Cesium.RegionWeather.TYPE_SNOW;
@@ -65,9 +132,7 @@
         }
     },
     getCoord(res) {
-       const coord = res.point.split(',');
-       
-
+        const coord = res.point.split(',');
         return coord;
     },
     getRegionWather(res) {
@@ -83,7 +148,7 @@
             primitive: model[0].layer.item,
             position: new SmartEarth.Cesium.Cartesian3.fromDegrees(coord[0], coord[1], 1),
             radius: 1000,
-        })
+        });
     },
 };
 

--
Gitblit v1.9.3