From ab8f3297f7c8243d486c9da0900e4f813b2ea2df Mon Sep 17 00:00:00 2001
From: suerprisePlus <15810472099@163.com>
Date: 星期三, 27 十一月 2024 17:16:46 +0800
Subject: [PATCH] 功能更新

---
 src/views/visualization/list/mapWeather.js |  291 +++++++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 265 insertions(+), 26 deletions(-)

diff --git a/src/views/visualization/list/mapWeather.js b/src/views/visualization/list/mapWeather.js
index 222f65f..088eefa 100644
--- a/src/views/visualization/list/mapWeather.js
+++ b/src/views/visualization/list/mapWeather.js
@@ -1,8 +1,40 @@
-import mapServer from '../../../assets/js/mapSdk/mapServe';
-
+import mapServer from '@/assets/js/mapSdk/mapServe.js';
+import * as turf from '@turf/turf';
 const mapWeather = {
     regionWeather: null,
     particle: null,
+    showRain: 'ShowRain',
+    wallLayer: null,
+    pathLayer: null,
+    listBiildBord: [],
+    listParticle: [],
+    getWearData(res) {
+        return {
+            name: res.address,
+            data: [
+                {
+                    name: '鍚嶇О',
+                    val: res.address,
+                },
+                {
+                    name: '姘旇薄绾у埆',
+                    val: res.level,
+                },
+                {
+                    name: '鎵�灞炵嚎璺�',
+                    val: res.line,
+                },
+                {
+                    name: '鏁版嵁鏉ユ簮',
+                    val: res.source,
+                },
+                {
+                    name: '鍙戝竷鏃堕棿',
+                    val: res.time,
+                },
+            ],
+        };
+    },
     closeRegionWeather() {
         if (this.regionWeather) {
             this.regionWeather.enableWeatherType = SmartEarth.Cesium.RegionWeather.TYPE_NONE;
@@ -12,51 +44,243 @@
             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]);
+            }
+        }
+        if (this.wallLayer) {
+            Viewer.entities.remove(this.wallLayer);
+            this.wallLayer = null;
+            // this.wallLayer.removeFromMap();
+            // this.wallLayer = null;
+        }
+        if (this.pathLayer) {
+            this.pathLayer.deleteObject();
+            this.pathLayer = null;
+        }
+        for (var i in this.listBiildBord) {
+            this.listBiildBord[i].removeFromMap();
+        }
+        this.listBiildBord = [];
+        for (var i in this.listParticle) {
+            this.listParticle[i].deleteObject();
+        }
+        this.listParticle = [];
     },
     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();
                 break;
+            case 'thunder':
+                this.showThunder(response);
+                break;
         }
     },
-    showFire(res) {
-        const coord = this.getCoord(res);
+    showThunder(response) {
+        if (response.geom) {
+            this.addWatherGeom(response.geom, 'thunder2.png');
+        }
+        // const points = this.chunkArray(response.point.split(','), 2);
+
+        // for (var i in points) {
+        //     const billboardEntity = earthCtrl.factory.createBillboard({
+        //         name: '鏍囩鐐�',
+        //         id: earthCtrl.factory.createUUID(),
+        //         image: config.images + 'thunder.png', // 璐村浘,
+        //         width: 40,
+        //         height: 40,
+        //         lon: parseFloat(points[i][0]),
+        //         lat: parseFloat(points[i][1]),
+        //         alt: 1,
+        //         scale: 6,
+        //     });
+        //     this.listBiildBord.push(billboardEntity);
+        // }
+    },
+    addWatherGeom(response, image) {
+        if (response.ploygon) {
+            this.addWatherPloygon(this.chunkArray(response.ploygon, 2), image);
+        }
+        if (response.line) {
+            this.addWatherLine(this.chunkArray(response.line, 2));
+        }
+    },
+    addWatherLine(response) {
         const obj = {
-            x: coord[0],
-            y: coord[1],
-            z: 0,
+            type: 'FeatureCollection',
+            features: [
+                {
+                    type: 'Feature',
+                    geometry: {
+                        type: 'LineString',
+                        coordinates: response,
+                    },
+                },
+            ],
         };
-        this.particle = earthCtrl.factory.createParticleEffect(
-            'flame',
-            obj,
-            {
-                translation: SmartEarth.Cesium.Cartesian3.fromElements(0, 0, 0), //骞崇Щ
-                particleSize:10
+        this.pathLayer = earthCtrl.factory.createPathLayer({
+            url: obj,
+            color: '#ff0000', //绾跨殑棰滆壊
+            width: 5.0, //绾跨殑瀹藉害
+            pointColor: '#FFFFFF', //绉诲姩鐐圭殑棰滆壊
+            speed: 1,
+            far: 50000,
+        });
+    },
+    addWatherPloygon(response, image) {
+        response.push(response[0]);
+        const coord = this.getCentroid(response);
+        earthCtrl.camera.flyTo(coord[0], coord[1], 80000, 0, -90, 0, 0);
+        var geom = [];
+        for (var i = 0; i < response.length; i++) {
+            geom.push(response[i][0], response[i][1]);
+        }
+
+        this.wallLayer = Viewer.entities.add({
+            polygon: {
+                hierarchy: Cesium.Cartesian3.fromDegreesArray(geom),
+                material: new Cesium.ImageMaterialProperty({
+                    image: config.images + image,
+                    alpha: 0.2, // 璁剧疆閫忔槑搴︿负0.5
+                    repeat: Cesium.Cartesian2(1.0, 1.0), // 涓嶉噸澶�
+                    transparent: true, // 鍚敤png閫忔槑
+                    color: new Cesium.Color(1.0, 1.0, 1.0, 0.3), // 璁剧疆棰滆壊鍜岄�忔槑搴�
+                }),
+                stRotation: Cesium.Math.toRadians(0),
             },
-            function (data) {}
-        );
+        });
+        // this.wallLayer = earthCtrl.factory.createPolygon({
+        //     name: '闈�',
+        //     id: earthCtrl.factory.createUUID(),
+        //     material: Cesium.Color.fromCssColorString('rgba(128,128,128, .2)'),
+        //     outlineColor: Cesium.Color.fromCssColorString('rgba(128,128,128, .5)'),
+        //     lineWidth: 3,
+        //     height: 10,
+        //     outline: true,
+        //     outlineWidth: 2,
+        //     positions: SmartEarth.Cesium.Cartesian3.fromDegreesArrayHeights(geom),
+        // });
+
+        // const obj = { type: 'GeometryCollection', geometries: [{ type: 'LineString', coordinates: response }] };
+        // // 娴佸姩澧欏浘灞�
+        // this.wallLayer = earthCtrl.factory.createTrailWallLayer({
+        //     url: obj,
+        //     color: '#0000ff05', //棰滆壊
+        //     height: 20, //楂樺害
+        //     speed: 2,
+        // });
+    },
+    showFire(response) {
+        if (response.geom) {
+            this.addWatherGeom(response.geom, 'filre.png');
+        }
+        // const points = this.chunkArray(response.point.split(','), 2);
+        // for (var i in points) {
+        //     const particle = earthCtrl.factory.createParticleEffect(
+        //         'flame',
+        //         {
+        //             x: parseFloat(points[i][0]),
+        //             y: parseFloat(points[i][1]),
+        //             z: 0,
+        //         },
+        //         {
+        //             translation: SmartEarth.Cesium.Cartesian3.fromElements(0, 0, 0), //骞崇Щ
+        //             particleSize: 10,
+        //         },
+        //         function (data) {}
+        //     );
+
+        //     this.listParticle.push(particle);
+        // }
+        // const coord = this.getCoord(res);
+        // const obj = {
+        //     x: coord[0],
+        //     y: coord[1],
+        //     z: 0,
+        // };
+        // this.particle = earthCtrl.factory.createParticleEffect(
+        //     'flame',
+        //     obj,
+        //     {
+        //         translation: SmartEarth.Cesium.Cartesian3.fromElements(0, 0, 0), //骞崇Щ
+        //         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 += 2) {
+            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);
     },
+
     showSnow() {
         if (this.regionWeather) {
             this.regionWeather.enableWeatherType = SmartEarth.Cesium.RegionWeather.TYPE_SNOW;
@@ -65,10 +289,25 @@
         }
     },
     getCoord(res) {
-       const coord = res.point.split(',');
-       
-
+        const coord = res.point.split(',');
         return coord;
+    },
+    getCentroid(response) {
+        var centroid = turf.centroid(turf.polygon([response]));
+        return centroid.geometry.coordinates;
+    },
+    chunkArray(array, size) {
+        return array.reduce((chunks, current, index) => {
+            const chunkIndex = Math.floor(index / size);
+
+            if (!chunks[chunkIndex]) {
+                chunks[chunkIndex] = [];
+            }
+
+            chunks[chunkIndex].push(current);
+
+            return chunks;
+        }, []);
     },
     getRegionWather(res) {
         if (res.type == 'fire') return;
@@ -83,7 +322,7 @@
             primitive: model[0].layer.item,
             position: new SmartEarth.Cesium.Cartesian3.fromDegrees(coord[0], coord[1], 1),
             radius: 1000,
-        })
+        });
     },
 };
 

--
Gitblit v1.9.3