suerprisePlus
2024-10-23 559f0776123a2205863b5787d5b8e1e012d397d3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
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;
            this.regionWeather = null;
        }
        if (this.particle) {
            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);
 
        switch (response.type) {
            case 'rain':
                //  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;
        }
    },
    showFire(res) {
        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(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;
            this.regionWeather.regionAlpha = 0.9;
            this.regionWeather.regionGradientDistance = 300;
        }
    },
    getCoord(res) {
        const coord = res.point.split(',');
        return coord;
    },
    getRegionWather(res) {
        if (res.type == 'fire') return;
        const coord = this.getCoord(res);
        const model = mapServer.layerList.filter((item) => {
            if (item.name == config.baseModel.cnName + '_' + config.baseModel.id) {
                return item;
            }
        });
        if (model.length <= 0) return;
        this.regionWeather = earthCtrl.factory.createRegionWeather({
            primitive: model[0].layer.item,
            position: new SmartEarth.Cesium.Cartesian3.fromDegrees(coord[0], coord[1], 1),
            radius: 1000,
        });
    },
};
 
export default mapWeather;