surprise
2023-12-29 18377dc5d61caf3a6a0835e17015ac2601f8709d
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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
var lineOfSight = [];
function CreateLineOfSight(height,callback) {
    let line = sgworld.drawObj = sgworld.Analysis.createlineOfSight({height}, function (Distance) {
        callback && callback();
    });
    lineOfSight.push(line);
}
 
function ClearLineOfSight() {
    lineOfSight.forEach(line => {
        line && line.deleteObject();
    })
    lineOfSight = [];
}
 
 
//视域分析
var viewshed = null;
var isFirstAddViewshed = true;
var SYFX_visible_color, SYFX_notVisible_color;
 
function addViewshed(height) {
    if (isFirstAddViewshed) {
        isFirstAddViewshed = false;
    } else {
        clearnViewshed();
    }
    // SmartEarthPopupData.layerContainer && SmartEarthPopupData.layerContainer.hide();
    viewshed = sgworld.drawObj = sgworld.Analysis.create3DViewshed({
        name: 'Viewshed On Frederick',
        height: height === undefined ? 0 : height,
        color: {
            Back: SYFX_notVisible_color,
            Fore: SYFX_visible_color,
            default: window.shadowMap_color
        },
        end: () => {
            setShadows('open');
            // SmartEarthPopupData.layerContainer && SmartEarthPopupData.layerContainer.show();
        }
    });
}
 
//删除视域分析
function clearnViewshed() {
    if (viewshed) {
        viewshed.close();
        viewshed = null;
    } else if (window.parent.viewshed) {
        window.parent.viewshed.close();
        window.parent.viewshed = null;
    }
    setShadows('close');
}
 
var default_shadows_value;
 
function setShadows(type) {
    switch (type) {
        case 'open':
            default_shadows_value = sgworld._Viewer.shadows;
            if (!default_shadows_value) {
                window.shadows = true;
                sgworld._Viewer.shadows = true;
            }
            break;
        case 'close':
            if (default_shadows_value !== undefined && sgworld._Viewer.shadows !== default_shadows_value) {
                sgworld._Viewer.shadows = !!default_shadows_value;
                window.shadows = !!default_shadows_value;
            }
            default_shadows_value = undefined;
            break;
    }
}
 
//画点
var buff;
var buffRadius = 100;
var DrawPointBuffer = function () {
    // SmartEarthPopupData.layerContainer && SmartEarthPopupData.layerContainer.hide();
    buff = sgworld.drawObj = sgworld.Analysis.DrawPointBuffer(buffRadius, function () {
        // SmartEarthPopupData.layerContainer && SmartEarthPopupData.layerContainer.show();
    });
}
 
//画线
var DrawPolylineBuffer = function () {
    // SmartEarthPopupData.layerContainer && SmartEarthPopupData.layerContainer.hide();
    buff = sgworld.drawObj = sgworld.Analysis.DrawPolylineBuffer(buffRadius, function () {
        // SmartEarthPopupData.layerContainer && SmartEarthPopupData.layerContainer.show();
    });
}
 
//画面
var DrawPolygonBuffer = function () {
    // SmartEarthPopupData.layerContainer && SmartEarthPopupData.layerContainer.hide();
    buff = sgworld.drawObj = sgworld.Analysis.DrawPolygonBuffer(buffRadius, function () {
        // SmartEarthPopupData.layerContainer && SmartEarthPopupData.layerContainer.show();
    });
}
 
//设置缓冲半径
var setBuff = function (num) {
    if (buff) {
        buff.changeBurr(num);
    }
    buffRadius = num;
}
 
//清除
var clearBuff = function () {
    if (buff) {
        buff.clearBuff();
    }
}
 
 
var default_depthTestAgainstTerrain_value;
 
function setDepthTest(type) {
    switch (type) {
        case 'open':
            default_depthTestAgainstTerrain_value = Viewer.scene.globe.depthTestAgainstTerrain;
            if (!default_depthTestAgainstTerrain_value) {
                Viewer.scene.globe.depthTestAgainstTerrain = true;
                window.depth = true;
            }
            break;
        case 'close':
            if (Viewer.scene.globe.depthTestAgainstTerrain !== default_depthTestAgainstTerrain_value) {
                Viewer.scene.globe.depthTestAgainstTerrain = default_depthTestAgainstTerrain_value;
                window.depth = default_depthTestAgainstTerrain_value;
            }
            default_depthTestAgainstTerrain_value = undefined;
            break;
    }
}
 
function fnLayerHauto(type, h) {
    //判断该类型弹出来是否存在
    autoH = true;
    var $layer = $('#layui-layer' + type, document.parent);
    if (!type || $layer.length == 0) return;
 
    $layer.css({
        'height': h + 'px'
    });
    $layer.find('iframe').css('height', h - 40 + 'px');
    $layer.find('iframe').contents().find('body').css({
        'height': h - 40 + 'px',
        'overflow': 'hidden'
    });
    $layer.find('iframe')[0].contentWindow.scrollStart ? $layer.find('iframe')[0].contentWindow.scrollStart() : '';
}
 
function getElevationTool() {
    !window._ElevationTool && (window._ElevationTool = new ElevationTool());
    return window._ElevationTool;
}
 
//等高线和坡度图工具
let ElevationTool = function () {
    function _() {
        this.contourUniforms = undefined;
        this.shadingUniforms = undefined;
        this.min = {
            'elevation': 10,
            'slope': 0
        };
        this.max = {
            'elevation': 2000,
            'slope': 70
        };
        this.width = 2;
        this.spacing = 150;
        this.tf = false;
        this.contourColor = undefined;
        this.type = 'none';
        this.Contour = undefined;
        this.colorArr = ['#0b0b88', '#2747E0', '#D33B7D', '#D33038', '#FF9742', '#ffd700', '#bbff00'];
        this.startColor = '#0b0b88';
        this.endColor = '#bbff00';
    }
 
    _.prototype.render = function () {
        if (this.type === 'slope') {
            Cesium.ExpandBySmartEarth.displaySlopeMap = true;
            // this.setShopeColor();
        } else {
            Cesium.ExpandBySmartEarth.displaySlopeMap = false;
        }
        this.Contour = sgworld.Analysis.createElevationContour(this.tf, this.type === 'slope' ? 'none' : this.type, {
            colorArr: this.colorArr,
            min: this.min[this.type],
            max: this.max[this.type],
            width: this.width,
            spacing: this.spacing,
            lineColor: this.contourColor
        });
        this.shadingUniforms = this.Contour.item.shadingUniforms;
        this.contourUniforms = this.Contour.item.contourUniforms;
    };
 
    _.prototype.setContourColor = function (color) {
        this.contourColor = color;
        this.Contour && this.Contour.setMaterialColor(this.contourColor);
    };
    _.prototype.setShopeColor = function () {
        let arr = [];
        let min = this.min.slope;
        let max = this.max.slope;
        let length = (max - min) / 7;
        this.colorArr.forEach((color, index) => {
            arr.push({
                val: 100 * Math.cos(Cesium.Math.toRadians(min + length * index)),
                color: color
            });
        });
        Cesium.ExpandBySmartEarth.SlopeMapPallete = arr;
        Cesium.ExpandBySmartEarth.isSlopeDirty = !0;
    };
 
    //等高线宽
    _.prototype.setWidth = function (num) {
        this.width = num;
        this.Contour && this.Contour.setWidth(this.width);
    };
 
    //等高线间距
    _.prototype.setSpacing = function (num) {
        this.spacing = num;
        this.Contour && this.Contour.setSpacing(this.spacing);
    };
 
    //起始颜色
    _.prototype.setStartColor = function (color) {
        this.startColor = color;
        this.colorArr = sgworld.Core.gradientColor(this.startColor, this.endColor, 7);
        this.render();
    };
 
    //终止颜色
    _.prototype.setEndColor = function (color) {
        this.endColor = color;
        this.colorArr = sgworld.Core.gradientColor(this.startColor, this.endColor, 7);
        this.render();
    };
 
    //最小值
    _.prototype.setMin = function (num) {
        this.min[this.type] = num;
        if (this.type === 'elevation') {
            this.shadingUniforms.minimumHeight = this.min[this.type];
        } else {
            this.render();
        }
    };
 
    //最大值
    _.prototype.setMax = function (num) {
        this.max[this.type] = num;
        if (this.type === 'elevation') {
            this.shadingUniforms.maximumHeight = this.max[this.type];
        } else {
            this.render();
        }
    };
 
    //最大值
    _.prototype.reset = function () {
        this.colorArr = ['#0b0b88', '#2747E0', '#D33B7D', '#D33038', '#FF9742', '#ffd700', '#bbff00'];
        this.render();
    };
 
    return _;
}();
 
function SunshineAnalysis(data) {
    // SmartEarthPopupData.layerContainer && SmartEarthPopupData.layerContainer.hide();
    window._AnalysisSunshine = sgworld.drawObj = sgworld.Analysis.SunshineAnalysisPolygon({
        start: data.start,
        end: data.end,
        interval: data.interval,
        spacing: data.spacing,
        addHeight: data.addHeight
    }, () => {
        // SmartEarthPopupData.layerContainer && SmartEarthPopupData.layerContainer.show();
    });
}
 
//清除分析
function clearAnalyse() {
    //淹没
    window._AnalysisFlood && window._AnalysisFlood.forEach(item => {
        item.endWater();
    });
    window._AnalysisFlood = [];
    //通视
    ClearLineOfSight();
    //视域
    clearnViewshed();
    //缓冲区
    clearBuff();
    //天际线
    sgworld.Analysis.clearSkylineAnalysis();
    //剖面
    // window._AnalysisDXPM && window._AnalysisDXPM.deleteObject();
    //开挖
    window.Excavation && window.Excavation.clear();
    window.Excavation = undefined;
    //地形压平
    sgworld.TerrainFlattening && sgworld.TerrainFlattening.remove();
    sgworld.TerrainFlattening = undefined;
    sgworld.Analysis.skyline = false;
    //日照
    window._AnalysisSunshine && window._AnalysisSunshine.remove();
    window._AnalysisSunshine = undefined;
    //模型压平
    sgworld.ModelFlattening && sgworld.ModelFlattening.remove();
    sgworld.ModelFlattening = undefined;
 
    //结束之前操作
    sgworld.drawObj &&
        (sgworld.drawObj.drawHandler && sgworld.drawObj.drawHandler.destroy(),
            sgworld.drawObj.end && sgworld.drawObj.end());
}
 
function showDXPMResult() {
    layerOpen("地形剖面分析", {
        width: '80%',
        offset: 'b',
        height: 280,
        url: "./static/html/AnalysisResultEchartLine.html",
        fn: {
            end: () => {
                //剖面
                window._AnalysisDXPM.flyPoint && Viewer.entities.remove(window._AnalysisDXPM.flyPoint);
                window._AnalysisDXPM && window._AnalysisDXPM.deleteObject();
                window._AnalysisDXPM = undefined;
            }
        },
    })
}
 
function addDXPMFlyPoint(position) {
    window._AnalysisDXPM.flyPoint && Viewer.entities.remove(window._AnalysisDXPM.flyPoint);
    window._AnalysisDXPM.flyPoint = Viewer.entities.add({
        position: position,
        billboard: {
            verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
            scale: 1,
            image: window.SmartEarthRootUrl + "/Workers/image/mark.png",
            heightReference: 1,
            disableDepthTestDistance: Number.POSITIVE_INFINITY,
        },
    });
}