nnnjjj123
2020-11-17 1b2c1edb61190eeb19f465ff031eaa3b2a1b8dbc
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
///////////////////////////////////////////////////////////////////////////
// Copyright © 2019 zhongsong. All Rights Reserved.
// 模块描述:水位淹没分析
///////////////////////////////////////////////////////////////////////////
define(['dojo/_base/declare', 'dojo/_base/lang', 'dojo/_base/array', 'dojo/_base/html', 'dojo/topic', 'jimu/BaseWidget'], function (declare, lang, array, html, topic, BaseWidget) {
    return declare([BaseWidget], {
        baseClass: 'jimu-widget-SubmergenceAnalysis',
        name: 'SubmergenceAnalysis',
        _waterPrimitive: null,
        _rowData: null,
        _netWorkEntity: null,
        _netWorkEntityId: null,
        startup: function startup() {
            // this.inherited(arguments);
            this.init();
            topic.subscribe("loadWater", lang.hitch(this, this.loadWater));
        },
        init: function init(evt) {
            var self = this;
 
            $('.roaming-tool li').click(function () {
                //流域漫游1-赣江
                if ($(this).index() == 0) {
                    topic.publish("autoRoam", "赣江");
                }
                //流域漫游2-章水
                else if ($(this).index() == 1) {
                        topic.publish("autoRoam", "章水");
                    }
                    //手动漫游
                    else if ($(this).index() == 2) {
                            $('#tz').trigger("click");
                        }
                        //自动漫游
                        else if ($(this).index() == 3) {
                                if (self._rowData != null) {
                                    topic.publish("autoRoam", self._rowData.name);
                                }
                            }
            });
 
            //水位文本框回车事件
            $("#mnsw").keypress(function (e) {
                if (e.which == 13) {
                
                    self.drawWater(self._rowData.surfaceWater, Number($("#mnsw").val()) + self._rowData.offsetwaterHeight);
                    self.netWorkEntity(Number($("#mnsw").val()) + self._rowData.offsetwaterHeight, self._rowData.longitude, self._rowData.latitude);
                }
            });
        },
 
        loadWater: function loadWater(evt) {
            topic.publish("stopflay", evt);
            var self = this;
            if (this._netWorkEntity && this._netWorkEntity != null) {
                this.map.entities.remove(this._netWorkEntity);
                this._netWorkEntity = null;
            }
            if (this._waterPrimitive && this._waterPrimitive != null) {
                this.map.scene.primitives.remove(this._waterPrimitive);
                this._waterPrimitive = null;
            }
            
            self._rowData = evt;
            if (evt != null) {
                if (evt.sitecode == "") {
                    $("#mnsw").val(self._rowData.defaultWaterLevel);
                    setTimeout(function () {
                        self.drawWater(self._rowData.surfaceWater, self._rowData.defaultWaterLevel + self._rowData.offsetwaterHeight);
                        self.netWorkEntity(self._rowData.defaultWaterLevel + self._rowData.offsetwaterHeight, self._rowData.longitude, self._rowData.latitude);
                    }, 2000);
                } else {
                    $.ajax({
                        url: 'http://www.sw797.com:82/blade-ycreal/riverr/rthyinfo?parttype=sw',
                        type: 'post',
                        dataType: "json",
                        success: function success(json) {
                            var waterLevel = null;
                            json.data.forEach(function (item, index) {
                                if (item.list && evt.sitecode == item.list.STCD) {
                                    waterLevel = item.list.Z;
                                }
                            });  
                            if (waterLevel == "" || waterLevel == null || waterLevel == 0) {
                                waterLevel = self._rowData.defaultWaterLevel;
                            }
                            $("#mnsw").val(waterLevel);
                            self.netWorkEntity(waterLevel + self._rowData.offsetwaterHeight, self._rowData.longitude, self._rowData.latitude);
                            self.drawWater(self._rowData.surfaceWater, Number(waterLevel) + self._rowData.offsetwaterHeight);
                        },
                        error: function error(msg) {}
                    });
                }
            }
        },
 
        netWorkEntity: function netWorkEntity(height, lgt, ltt) {
            if (this._netWorkEntity && this._netWorkEntity != null) {
                this.map.entities.remove(this._netWorkEntity);
                this._netWorkEntity = null;
            }
            this._netWorkEntity = this.map.entities.add({
                position: Cesium.Cartesian3.fromDegrees(Number(lgt), Number(ltt), Number(height)),
                label: {
                    show: true,
                    text: (height - this._rowData.offsetwaterHeight).toFixed(2) + "M", // text 与实体相关的文字
                    font: "700 16px '黑体'",
                    fillColor: Cesium.Color.fromBytes(255, 255, 255),
                    style: Cesium.LabelStyle.FILL_AND_OUTLINE,
                    outlineWidth: 2,
                    outlineColor: Cesium.Color.fromBytes(46, 202, 255), // 文字轮廓的颜色
                    verticalOrigin: Cesium.VerticalOrigin.CENTER, //垂直位置
                    horizontalOrigin: Cesium.HorizontalOrigin.center, //水平位置
                    pixelOffset: new Cesium.Cartesian2(0, -12), // 文字位置
                    disableDepthTestDistance: Number.POSITIVE_INFINITY
                },
                point: {
                    show: true,
                    pixelSize: 4,
                    color: Cesium.Color.fromBytes(255, 255, 255),
                    outlineColor: Cesium.Color.fromBytes(46, 202, 255),
                    outlineWidth: 1,
                    disableDepthTestDistance: Number.POSITIVE_INFINITY
                }
            });
        },
 
        //绘制水面波浪效果
        drawWater: function drawWater(surfaceWater, waterLevel) {
 
            var importantPoints = [];
            for (var i = 0; i < surfaceWater.length; i++) {
                var longitude = surfaceWater[i][0];
                var latitude = surfaceWater[i][1];
                importantPoints.push(new Cesium.Cartesian3.fromDegrees(longitude, latitude, waterLevel));
            }
 
            if (this._waterPrimitive && this._waterPrimitive != null) {
                this.map.scene.primitives.remove(this._waterPrimitive);
                this._waterPrimitive = null;
            }
 
            this._waterPrimitive = new Cesium.Primitive({
                show: true, // 默认隐藏
                allowPicking: false,
                geometryInstances: new Cesium.GeometryInstance({
                    geometry: new Cesium.PolygonGeometry({
                        polygonHierarchy: new Cesium.PolygonHierarchy(importantPoints),
                        //extrudedHeight: 0,//注释掉此属性可以只显示水面
                        perPositionHeight: true //注释掉此属性水面就贴地了
                    })
                }),
                // 可以设置内置的水面shader
                appearance: new Cesium.EllipsoidSurfaceAppearance({
                    material: new Cesium.Material({
                        fabric: {
                            type: 'Water',
                            uniforms: {
                                //baseWaterColor:new Cesium.Color(0.0, 0.0, 1.0, 0.5),
                                //blendColor: new Cesium.Color(0.0, 0.0, 1.0, 0.5),
                                //specularMap: 'gray.jpg',
                                //normalMap: '../assets/waterNormals.jpg',
                                normalMap: 'widgets/SubmergenceAnalysis/images/water.jpg',
                                frequency: 1000.0,
                                animationSpeed: 0.01,
                                amplitude: 10.0
                            }
                        }
                    }),
                    fragmentShaderSource: 'varying vec3 v_positionMC;\nvarying vec3 v_positionEC;\nvarying vec2 v_st;\nvoid main()\n{\nczm_materialInput materialInput;\nvec3 normalEC = normalize(czm_normal3D * czm_geodeticSurfaceNormal(v_positionMC, vec3(0.0), vec3(1.0)));\n#ifdef FACE_FORWARD\nnormalEC = faceforward(normalEC, vec3(0.0, 0.0, 1.0), -normalEC);\n#endif\nmaterialInput.s = v_st.s;\nmaterialInput.st = v_st;\nmaterialInput.str = vec3(v_st, 0.0);\nmaterialInput.normalEC = normalEC;\nmaterialInput.tangentToEyeMatrix = czm_eastNorthUpToEyeCoordinates(v_positionMC, materialInput.normalEC);\nvec3 positionToEyeEC = -v_positionEC;\nmaterialInput.positionToEyeEC = positionToEyeEC;\nczm_material material = czm_getMaterial(materialInput);\n#ifdef FLAT\ngl_FragColor = vec4(material.diffuse + material.emission, material.alpha);\n#else\ngl_FragColor = czm_phong(normalize(positionToEyeEC), material,czm_lightDirectionEC);\gl_FragColor.a=0.7;\n#endif\n}\n' //重写shader,修改水面的透明度
                })
            });
 
            this.map.scene.primitives.add(this._waterPrimitive);
        },
 
        onOpen: function onOpen() {
            //面板打开的时候触发 (when open this panel trigger)
        },
 
        onClose: function onClose() {
            //面板关闭的时候触发 (when this panel is closed trigger)
        },
 
        onMinimize: function onMinimize() {
            this.resize();
        },
 
        onMaximize: function onMaximize() {
            this.resize();
        },
 
        resize: function resize() {},
 
        destroy: function destroy() {
            //销毁的时候触发
            //todo
            //do something before this func
            this.inherited(arguments);
        }
 
    });
});