1
Surpriseplus
2022-09-16 a7e5110ef3f5fe3c9205f7d1a526b9fbbb55d826
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
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
const { Cartesian2, PostProcessStage, PostProcessStageComposite, PostProcessStageSampleMode } = Cesium;
export default {
    /**
     *
     * 地图参数
     *
     */
    mapOption: {},
    /**
     *
     * 初始化地图
     *
     */
    initMap() {
        let option = {
            url: SmartEarthRootUrl + "Workers/image/earth.jpg",
            fullscreenButton: true,
            contextOptions: {
                failIfMajorPerformanceCaveat: false,
                webgl: {
                    alpha: true,
                    preserveDrawingBuffer: true,
                },
            },
        };
 
        window.sgworld = new SmartEarth.SGWorld("sdkContainer", Cesium, option, null, function() {});
        var dx = {
            url: "https://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer",
            enablePickFeatures: false,
        };
        sgworld.Creator.createArcGisImageryLayer("ARCGIS", dx, "0", undefined, true, "");
 
        window.Viewer = sgworld._Viewer;
        Viewer.shadows = false;
        //fps
        Viewer.scene.debugShowFramesPerSecond = false;
    },
    /**
     *
     * 切换对象状态
     *
     */
    toggleObject(object) {},
    /**
     *
     * 隐藏对象
     *
     */
    hideObject() {},
    /**
     *
     * 显示对象
     *
     */
    showObject() {},
    /**
     *
     * 创建WMS
     *
     */
    createWMS() {},
    /**
     *
     * 创建WFS
     *
     */
    createWFS() {},
    parseDefines(shader) {
        let defines = [];
        for (const key in shader.defines) {
            if (shader.defines.hasOwnProperty(key)) {
                const val = shader.defines[key];
                defines.push("#define " + key + " " + val);
            }
        }
        defines = defines.join("\n") + "\n";
        if (shader.fragmentShader) {
            shader.fragmentShader = defines + shader.fragmentShader;
        }
        if (shader.vertexShader) {
            shader.vertexShader = defines + shader.vertexShader;
        }
        return shader;
    },
    kernelblur(name, sigma, radius, textureScale) {
        let kernelFShader = `varying vec2 v_textureCoordinates;
                            uniform sampler2D colorTexture;
                            uniform vec2 colorTextureDimensions;
                            uniform vec2 direction;
 
                            float gaussianPdf(in float x, in float sigma) {
                                return 0.39894 * exp( -0.5 * x * x/( sigma * sigma))/sigma;
                            }
                            void main() {
                                
                                vec2 invSize = 1.0 / colorTextureDimensions;
                                float fSigma = float(SIGMA);
                                float weightSum = gaussianPdf(0.0, fSigma);
                                vec3 diffuseSum = texture2D( colorTexture, v_textureCoordinates).rgb * weightSum;
                                for( int i = 1; i < KERNEL_RADIUS; i ++ ) {
                                    float x = float(i);
                                    float w = gaussianPdf(x, fSigma);
                                    vec2 uvOffset = direction * invSize * x;
                                    vec3 sample1 = texture2D( colorTexture, v_textureCoordinates + uvOffset).rgb;
                                    vec3 sample2 = texture2D( colorTexture, v_textureCoordinates - uvOffset).rgb;
                                    diffuseSum += (sample1 + sample2) * w;
                                    weightSum += 2.0 * w;
                                }
                                gl_FragColor = vec4(diffuseSum/weightSum, 1.0);
                            }`;
 
        let blurDirectionX = new Cartesian2(1.0, 0.0);
        let blurDirectionY = new Cartesian2(0.0, 1.0);
 
        let separableBlurShader = {
            defines: {
                KERNEL_RADIUS: radius,
                SIGMA: sigma,
            },
            fragmentShader: kernelFShader,
        };
        this.parseDefines(separableBlurShader);
        let blurX = new PostProcessStage({
            name: name + "X",
            textureScale: textureScale,
            fragmentShader: separableBlurShader.fragmentShader,
            forcePowerOfTwo: true,
            uniforms: {
                direction: blurDirectionX,
            },
            sampleMode: PostProcessStageSampleMode.LINEAR,
        });
        let blurY = new PostProcessStage({
            name: name + "Y",
            textureScale: textureScale,
            fragmentShader: separableBlurShader.fragmentShader,
            forcePowerOfTwo: true,
            uniforms: {
                direction: blurDirectionY,
            },
            sampleMode: PostProcessStageSampleMode.LINEAR,
        });
        let separableBlur = new PostProcessStageComposite({
            name: name,
            stages: [blurX, blurY],
            inputPreviousStageTexture: true,
        });
        return separableBlur;
    },
    loadHighlight() {
        let name = "light";
        let fShader = `uniform sampler2D colorTexture;
        uniform vec3 defaultColor;
        uniform float defaultOpacity;
        uniform float luminosityThreshold;
        uniform float smoothWidth;
 
        varying vec2 v_textureCoordinates;
        void main() {
            vec4 texel = texture2D(colorTexture, v_textureCoordinates);
 
            #ifdef CZM_SELECTED_FEATURE
                if(!czm_selected()) {
                    texel = vec4(0.);
                }
            #endif
 
            vec3 luma = vec3(0.299, 0.587, 0.114);
            float v = dot(texel.xyz, luma);
            vec4 outputColor = vec4(defaultColor.rgb, defaultOpacity);
            float alpha = smoothstep(luminosityThreshold, luminosityThreshold + smoothWidth, v);
            gl_FragColor = mix(outputColor, texel, alpha);
        }`;
 
        let highlight = new PostProcessStage({
            name: "highlight",
            fragmentShader: fShader,
            uniforms: {
                defaultColor: [0.3, 0.3, 0.3],
                luminosityThreshold: 0.6,
                defaultOpacity: 0.1,
                smoothWidth: 0.01,
            },
        });
 
        const blurStage1 = this.kernelblur(name + "Blur1", 3, 3, 1.0);
        const blurStage2 = this.kernelblur(name + "Blur2", 5, 5, 0.5);
        const blurStage3 = this.kernelblur(name + "Blur3", 7, 7, 0.25);
        const blurStage4 = this.kernelblur(name + "Blur4", 9, 9, 0.125);
        const blurStage5 = this.kernelblur(name + "Blur5", 11, 11, 0.0625);
        const blurCompositeStage = new PostProcessStageComposite({
            name: name + "BlurComposite",
            stages: [highlight, blurStage1, blurStage2, blurStage3, blurStage4, blurStage5],
            inputPreviousStageTexture: true,
        });
 
        let blendFShader = `varying vec2 v_textureCoordinates;
        uniform sampler2D blurTexture1;
        uniform sampler2D blurTexture2;
        uniform sampler2D blurTexture3;
        uniform sampler2D blurTexture4;
        uniform sampler2D blurTexture5;
        uniform sampler2D colorTexture;
 
        float lerpBloomFactor(const in float factor) {
            float mirrorFactor = 1.2 - factor;
            return mix(factor, mirrorFactor, 0.1);
        }
 
        void main() {
 
            vec4 color = texture2D(colorTexture, v_textureCoordinates);
            vec4 bloomTintColor = vec4(1.,1.,1.,1.);
            vec4 bloomColor = 1. * (
                lerpBloomFactor(1.0) * bloomTintColor * texture2D(blurTexture1, v_textureCoordinates) +
                lerpBloomFactor(0.8) * bloomTintColor * texture2D(blurTexture2, v_textureCoordinates) +
                lerpBloomFactor(0.6) * bloomTintColor * texture2D(blurTexture3, v_textureCoordinates) +
                lerpBloomFactor(0.4) * bloomTintColor * texture2D(blurTexture4, v_textureCoordinates) +
                lerpBloomFactor(0.2) * bloomTintColor * texture2D(blurTexture5, v_textureCoordinates)
            );
 
            gl_FragColor = bloomColor + color;
        }`;
 
        const addStage = new PostProcessStage({
            name: name + "Additive",
            uniforms: {
                blurTexture1: blurStage1.name,
                blurTexture2: blurStage2.name,
                blurTexture3: blurStage3.name,
                blurTexture4: blurStage4.name,
                blurTexture5: blurStage5.name,
            },
            fragmentShader: blendFShader,
        });
        const compositeStage = new PostProcessStageComposite({
            name: name + "Composite",
            stages: [blurCompositeStage, addStage],
            inputPreviousStageTexture: false,
        });
        return compositeStage;
    },
    /**
     *
     * 创建发光
     *
     */
    setLuminosity() {
        return this.loadHighlight();
        //window.sceneObj.highlight =
 
        //sgworld._Viewer.scene.postProcessStages.add(compositeStage);
    },
    /**
     *
     * 创建热力图
     *
     */
    createHeatMap(response, attr, nameAttr) {
        let that = this;
 
        let features = response.data.features;
        let heatmapData = [];
        for (let i = 0; i < features.length; i++) {
            let geom = features[i].geometry.coordinates;
            let pre = features[i].properties;
            //var position = { X: geom[0], Y: geom[1], Altitude: 100 };
            let value = pre[attr] ? pre[attr] : 1;
            value = Math.sqrt(value);
            // value = 1;
            heatmapData.push({
                x: geom[0],
                y: geom[1],
                value: value,
            });
        }
        let heatmapLayer = sgworld.Creator.addHeatMap("热力图1", {
            type: "Heatmap3D", // 热力图类型
            sourceData: heatmapData,
            radius: 100,
            minHeight: 0, // 底部高度
            TIN_X: 300,
            TIN_Y: 300,
            colorScale: 1, //色值转换高度的比例
            //showTIN: true, //显示三角网
            //tooltip: true // tooltip显示数值
        });
        return heatmapLayer;
    },
    /**
     *
     * 创建地图柱状图
     *
     */
    createMapBar(response, attr, nameAttr) {
        let features = response.data.features;
        let entityData = [];
        let groupId = sgworld.ProjectTree.createGroup("柱状图", true, 0);
        var StartColor = "#0088ff";
        var EndColor = "#a5dc00";
        //获取填充颜色
        var colorArr = sgworld.Core.gradientColor(StartColor, EndColor, 10);
        var maxVal = -99999;
        var minVal = 99999;
        for (let i = 0; i < features.length; i++) {
            let pre = features[i].properties;
            let value = pre[attr] ? pre[attr] : 1;
            if (value > maxVal) {
                maxVal = value;
            }
            if (value < minVal) {
                minVal = value;
            }
        }
 
        for (let i = 0; i < features.length; i++) {
            let geom = features[i].geometry.coordinates;
            let pre = features[i].properties;
            //var position = { X: geom[0], Y: geom[1], Altitude: 100 };
            let value = pre[attr] ? pre[attr] : 1;
 
            let labelVal = pre[attr] ? pre[attr] : 0;
            if (labelVal > 500) {
                let labelName = pre[nameAttr];
                var num = Math.floor(((value - minVal) / (maxVal - minVal)) * 10);
                var ysk = colorArr[num];
 
                let scale = 0.3;
                let Histogramwidth = 100;
 
                var position = sgworld.Creator.CreatePosition(geom[0], geom[1], (value * scale) / 2, 1, 0, 0, 0, 300);
                let cylinder = sgworld.Creator.CreateCylinder(position, Histogramwidth, value * scale, "", ysk, 100, groupId, "柱" + i);
 
                //let label = sgworld.Creator.CreateLabel(position,value,"",{},groupId, "文本" + i);
                let label = sgworld.Creator.addSimpleGraphic("label", {
                    position: Cesium.Cartesian3.fromDegrees(geom[0], geom[1], value * scale),
                    removeEdit: true,
                    text: labelName + "\n" + labelVal.toFixed(2) + " ",
                    heightReference: 0,
                    font: "42px 宋体",
                    outlineWidth: 2,
                    GroupID: groupId,
                });
            }
        }
        return groupId;
    },
    /**
     *
     * 创建模型
     *
     */
    createModel(url) {
        window.sceneObj.tiltLowModel = sgworld.Creator.create3DTilesets(
            "",
            url,
            {
                skipLevelOfDetail: true,
                preferLeaves: true,
            },
            {},
            0,
            true,
            (data) => {
                sgworld.Navigate.flyToObj(data);
            }
        );
    },
    /**
     *
     * 创建发光线
     *
     */
    createFlyLine() {},
    /**
     *
     * 创建扫描
     *
     */
    createScanLight() {},
    /**
     *
     * 创建圆形扫描
     *
     */
    createCircleLight() {},
};