liuyg
2021-07-02 25ce610f6ecca7325e7a743dc032c4a76559c63d
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
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-SQLQuery',
            name: 'SQLQuery',
            flag: false,
            startup: function () {
                var that = this;
                topic.subscribe("beginSQL", lang.hitch(this, this.beginSQL));
                topic.subscribe("closesSQL", lang.hitch(this, this.closesSQL));
                // topic.publish('beginSQL', that.beginSQL);
                $(`.${that.baseClass}`).find('.closeOUR').click(() => {
                    $(`.${that.baseClass}`).hide();
                    that.closesSQL();
                })
 
                // that.beginSQL();
 
            },
            beginSQL: function () {
                var that = this
                    , viewer = that.map
                    , scene = viewer.scene;
 
                scene.shadowMap.darkness = 1.275; //设置第二重烘焙纹理的效果(明暗程度)
                scene.skyAtmosphere.brightnessShift = 0.4;  //修改大气的亮度
                scene.debugShowFramesPerSecond = false;
                scene.hdrEnabled = false;
                scene.sun.show = false;
                // 01设置环境光的强度-新处理CBD场景
                scene.lightSource.ambientLightColor = new Cesium.Color(0.65, 0.65, 0.65, 1);
                // 添加光源
                var position1 = new Cesium.Cartesian3.fromDegrees(116.261209157595, 39.3042238956531, 480);
                //光源方向点
 
                var targetPosition1 = new Cesium.Cartesian3.fromDegrees(116.261209157595, 39.3042238956531, 430);
                var dirLightOptions = {
                    targetPosition: targetPosition1,
                    color: new Cesium.Color(1.0, 1.0, 1.0, 1),
                    intensity: 0.55
                };
                directionalLight_1 = new Cesium.DirectionalLight(position1, dirLightOptions);
                scene.addLightSource(directionalLight_1);
                var widget = viewer.cesiumWidget;
                var buildingLayer;
                var IDs = [];
                $('#loadingbar').remove();
                var URL_CONFIG = {
                    SCENE_CBD: 'http://www.supermapol.com/realspace/services/3D-CBDCache20200416/rest/realspace',
                }
                var promise = scene.open(URL_CONFIG.SCENE_CBD);
                // try {
                Cesium.when(promise, function (layers) {
                    // console.log(layers, 1111)
                    //设置相机位置、视角,便于观察场景
                    scene.camera.setView({
                        destination: new Cesium.Cartesian3.fromDegrees(116.4566, 39.9149, 5323.445971240632),
                        orientation: {
                            heading: 0,
                            pitch: -1.5188,
                            roll: 0
                        }
                    });
                    var camera = scene.camera;
 
                    buildingLayer = scene.layers.find("Building@CBD");
                    buildingLayer.indexedDBSetting.isAttributesSave = true;//保存属性
 
                    //点击属性查询
                    var handler = new Cesium.ScreenSpaceEventHandler(scene.canvas);
                    handler.setInputAction(function (evt) {
                        var position = scene.pickPosition(evt.position);
 
                        if (buildingLayer.getSelection().length > 0) {
                            const selectedId = Number(buildingLayer.getSelection()[0]);
                            buildingLayer.getAttributesById([selectedId]).then(function (atts) {
                                if (atts) {
                                    console.log(atts);
 
                                    viewer.entities.removeAll();
 
                                    var length = Object.keys(atts).length;
                                    var des;
                                    for (var i = 0; i < length; i++) {
                                        var key = Object.keys(atts)[i];
                                        var value = atts[key];
 
 
                                        var index = i.toString();
                                        if (i == 0) {
                                            des = '<table class="cesium-infoBox-defaultTable"><tbody>' + '<tr><th>' + key + '</th><td>' + value + '</td></tr>';
                                        } else if (i == length - 1) {
                                            des += '<tr><th>' + key + '</th><td>' + value + '</td></tr>' + "</tbody></table>";
                                        } else {
                                            des += '<tr><th>' + key + '</th><td>' + value + '</td></tr>';
                                        }
                                    }
 
                                    viewer.entities.add({
                                        position: position,
                                        billboard: {
                                            image: './images/addL/dworgin.png',
                                            width: 30,
                                            height: 40,
 
                                        },
                                        name: atts["MODELNAME"],
                                        description: des
                                    });
 
                                }
                            }
                            )
                        }
                    }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
 
 
                    $("#SQLQuerysearch").click(function () {
                        doSqlQuery($("#SQL").val());
                    });
                    $("#SQLQueryposition").change(function () {
                        if (this.value == "1") {
                            camera.flyTo({
                                destination: Cesium.Cartesian3.fromDegrees(116.45756824765414, 39.9151525065, 303.9282348283207),
                                orientation: {
                                    heading: 3.361386,
                                    pitch: -0.543285,
                                    roll: 6.283185307179563
                                }
                            });
                        }
                        if (this.value == "2") {
                            camera.flyTo({
                                destination: Cesium.Cartesian3.fromDegrees(116.45898554643348, 39.90943026228571, 32.707476595524625),
                                orientation: {
                                    heading: 6.016771,
                                    pitch: -0.300416,
                                    roll: 0.0
                                }
                            });
                        }
                        if (this.value == "3") {
                            camera.flyTo({
                                destination: Cesium.Cartesian3.fromDegrees(116.43518565219966, 39.95097107746538, 2078.0503226706123),
                                orientation: {
                                    heading: 2.718565,
                                    pitch: -0.415366,
                                    roll: 0.0
                                }
                            });
                        }
                        if (this.value == "4") {
                            camera.flyTo({
                                destination: Cesium.Cartesian3.fromDegrees(116.48368313561016, 39.911532190450295, 369.08993153401934),
                                orientation: {
                                    heading: 4.771817,
                                    pitch: -0.190922,
                                    roll: 0.0
                                }
                            });
                        }
 
                    })
                }, function () {
                    var title = '加载SCP失败,请检查网络连接状态或者url地址是否正确?';
                    widget.showErrorPanel(title, undefined, e);
                });
                // } catch (e) {
                // if (widget._showRenderLoopErrors) {
                //     var title = '渲染时发生错误,已停止渲染。';
                //     widget.showErrorPanel(title, undefined, e);
                // }
                // }
 
                function onQueryComplete(features) {
                    var selectedFeatures = features;
                    viewer.entities.removeAll();
                    for (var i = 0; i < selectedFeatures.length; i++) {
                        var value = selectedFeatures[i].fieldValues["0"];
                        var feature = selectedFeatures[i];
                        for (var j = 0; j < feature.fieldNames.length; j++) {
                            var index = j.toString();
                            if (j == 0) {
                                var des = '<table class="cesium-infoBox-defaultTable"><tbody>' + '<tr><th>' + selectedFeatures[i].fieldNames["0"] + '</th><td>' + selectedFeatures[i].fieldValues["0"] + '</td></tr>';
                            } else if (j == feature.fieldNames.length - 1) {
                                des += '<tr><th>' + selectedFeatures[i].fieldNames[index] + '</th><td>' + selectedFeatures[i].fieldValues[index] + '</td></tr>' + "</tbody></table>";
                            } else {
                                des += '<tr><th>' + selectedFeatures[i].fieldNames[index] + '</th><td>' + selectedFeatures[i].fieldValues[index] + '</td></tr>';
                            }
                        }
                        viewer.entities.add({
                            position: Cesium.Cartesian3.fromDegrees(parseFloat(selectedFeatures[i].fieldValues["12"]), parseFloat(selectedFeatures[i].fieldValues["13"]), parseFloat(selectedFeatures[i].fieldValues["16"])),
                            billboard: {
                                image: './images/addL/dwblue.png',
                                width: 30,
                                height: 40,
 
                            },
                            name: selectedFeatures[i].fieldValues["11"],
                            description: des,
                            SQLData: selectedFeatures[i]//设置数据
                        });
                        IDs.push(parseInt(value) + 11);
                    }
                    if (IDs.length > 0) {
                        buildingLayer.setSelection(IDs);
                    }
                }
 
                function doSqlQuery(sqlStr) {
                    var sqlParameter = {
                        "datasetNames": ["二维数据:Building"],
                        getFeatureMode: "SQL",
                        queryParameter: {
                            attributeFilter: sqlStr
                        }
                    };
                    var url = "http://www.supermapol.com/realspace/services/data-cbd/rest/data/featureResults.rjson?returnContent=true";
                    var queryData = JSON.stringify(sqlParameter);
 
                    $.ajax({
                        type: "post",
                        url: url,
                        data: queryData,
                        success: function (result) {
                            var resultObj = JSON.parse(result);
                            console.log(resultObj);
                            if (resultObj.featureCount > 0) {
                                onQueryComplete(resultObj.features);
                            }
                        },
                        error: function (msg) {
                            console.log(msg);
                        },
                        // complete: function () {
                        //     console.log("complete");
                        // }
                    })
 
 
                    // $.ajax({
                    //     url: url,
                    //     async: true,
                    //     data: queryData,
                    //     method: "POST"
                    // }).done(function (result) {
                    //     var resultObj = JSON.parse(result);
                    //     console.log(resultObj);
                    //     if (resultObj.featureCount > 0) {
                    //         onQueryComplete(resultObj.features);
                    //     }
                    //
                    // })
                }
 
                function processFailed(queryEventArgs) {
                    alert('查询失败!');
                }
                that.promise = promise;
            },
            promise: '',
            closesSQL: function () {
                var that = this
                    , viewer = this.map;
                viewer.entities.removeAll();
                Cesium.when(that.promise, function (layer) {
                    for (var i = 0; i < layer.length; i++) {
                        that.map.scene.layers.remove(layer[i].name)
                    }
                })
            },
            onOpen: function () {
 
            },
 
            onClose: function () {
                //面板关闭的时候触发 (when this panel is closed trigger)
                console.log('jies')
            },
 
            onMinimize: function () {
                this.resize();
            },
 
            onMaximize: function () {
                this.resize();
            },
 
            resize: function () {
 
            },
 
            destroy: function () {
                //销毁的时候触发
                //todo
                //do something before this func
                this.inherited(arguments);
            }
 
        });
    });