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
define(['dojo/_base/lang',
        'dojo/_base/array',
        "dojo/_base/declare",
        'dojo/topic',
        'jimu/dijit/Popup',
        './GeologicalDisasterPanel',
        'libs/layer/layer.js'
    ],
    function (lang,
        array,
        declare,
        topic,
        Popup,
        GeologicalDisasterPanel,
        layer
    ) {
 
        return declare("practice.cesium.layers.CommonPointLayer3D", [], { // 三维点图层
            id: null,
            map: null,
            showName: "STNM", //title显示字段
            idField: "OBJECTID",  // 声明的类似变量,用来储存数据,或者布尔值
            firstLoad: true,
            billboards: null,
            currentVis: true,
            labelVis: false,
            constructor: function (option) {
                this.id = option.id;
                this.map = option.map;
                this.billboards = null;
            },
 
            destroy: function () {
                this.inherited(arguments);
            },
            getData: function (list, txt) {
                //判断下
                this.txt = txt;
                if (!lang.isArray(list)) {
                    var ls = list.data;
                    this.filterData = list.filterData;
                    list = ls;
                }
                if (this.firstLoad) {
                    this.billboards = [];
 
                    this.firstLoad = false;
                } else {
                    //循环删除
                    for (var i = 0; i < this.billboards.length; i++) {
 
                        this.map.entities.remove(this.billboards[i]);
                    }
                    this.billboards = [];
                }
                this.datas = {};
                for (var i = 0; i < list.length; i++) {
                    var lgtd = list[i].x;
                    var lttd = list[i].y ;
                    /**
                     * @billbo 对象,确定entities中billboard的值
                     * @labble 对象,确定entities中lable的值
                     * 
                     */
                    var billbo, labble, colorBill;
 
                    if (txt == "水文站") {
                        this.url = "./widgets/Location/popup/river.html"
                        // 与实体相关的图片
                        billbo = {
                            image: './images/hedao_sq.png',
                            pixelOffset: new Cesium.Cartesian2(0, 0),
                            color: Cesium.Color.fromBytes(128, 255, 255),
                            width: 16,
                            height: 16,
                            heightReference : Cesium.HeightReference.CLAMP_TO_GROUND,
                            disableDepthTestDistance: Number.POSITIVE_INFINITY
                        }
                        // 与实体相关的文字
                        labble = {
                            show: true,
                            text: list[i][this.showName], // text 与实体相关的文字
                            font: "700 14px '黑体'",
                            fillColor: Cesium.Color.DEEPSKYBLUE,
                            // backgroundColor: Cesium.Color.DEEPSKYBLUE,
                            style: Cesium.LabelStyle.FILL_AND_OUTLINE,
                            outlineWidth: 2,
                            outlineColor: Cesium.Color.fromBytes(255, 255, 255), // 文字轮廓的颜色
                            verticalOrigin: Cesium.VerticalOrigin.CENTER,//垂直位置
                            horizontalOrigin: Cesium.HorizontalOrigin.LEFT,//水平位置
                            pixelOffset: new Cesium.Cartesian2(10, -10), // 文字位置
                            heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
                            disableDepthTestDistance: Number.POSITIVE_INFINITY
                        };
                    } else if (txt == "水位站") {
                        this.url = "./widgets/Location/popup/river.html"
                        // 与实体相关的图片
                        billbo = {
                            image: "./images/swhdz.png",
                            pixelOffset: new Cesium.Cartesian2(0, 0),
                            color: Cesium.Color.fromBytes(128, 255, 255),
                            width: 16,
                            height: 16,
                            heightReference : Cesium.HeightReference.CLAMP_TO_GROUND,
                            disableDepthTestDistance: Number.POSITIVE_INFINITY
                        }
                        // 与实体相关的文字
                        labble = {
                            show: true,
                            text: list[i][this.showName], // text 与实体相关的文字
                            font: "700 14px '黑体'",
                            fillColor: Cesium.Color.DEEPSKYBLUE,
                            // backgroundColor: Cesium.Color.DEEPSKYBLUE,
                            style: Cesium.LabelStyle.FILL_AND_OUTLINE,
                            outlineWidth: 2,
                            outlineColor: Cesium.Color.fromBytes(255, 255, 255), // 文字轮廓的颜色
                            verticalOrigin: Cesium.VerticalOrigin.CENTER,//垂直位置
                            horizontalOrigin: Cesium.HorizontalOrigin.LEFT,//水平位置
                            pixelOffset: new Cesium.Cartesian2(10, -10), // 文字位置
                            heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
                            disableDepthTestDistance: Number.POSITIVE_INFINITY
                        };
 
                    } else if (txt == "雨量站") {
                        this.url = "./widgets/Location/popup/rain.html"
                        // 与实体相关的图片
                        billbo = {
                            image: "./images/jiangshui_sq.png",
                            pixelOffset: new Cesium.Cartesian2(0, 0),
                            color: Cesium.Color.fromBytes(0, 255, 0),
                            width: 10,
                            height: 10,
                            heightReference : Cesium.HeightReference.CLAMP_TO_GROUND,
                            disableDepthTestDistance: Number.POSITIVE_INFINITY
                        }
                        // 与实体相关的文字
                        labble = {
                            show: true,
                            text: list[i][this.showName], // text 与实体相关的文字
                            font: "700 14px '黑体'",
                            fillColor: Cesium.Color.DEEPSKYBLUE,
                            // backgroundColor: Cesium.Color.DEEPSKYBLUE,
                            style: Cesium.LabelStyle.FILL_AND_OUTLINE,
                            outlineWidth: 2,
                            outlineColor: Cesium.Color.fromBytes(255, 255, 255), // 文字轮廓的颜色
                            verticalOrigin: Cesium.VerticalOrigin.CENTER,//垂直位置
                            horizontalOrigin: Cesium.HorizontalOrigin.LEFT,//水平位置
                            pixelOffset: new Cesium.Cartesian2(10, -10), // 文字位置
                            heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
                            disableDepthTestDistance: Number.POSITIVE_INFINITY,
                            distanceDisplayCondition: new Cesium.DistanceDisplayCondition(1, 160000),
                        };
                    } else if (txt == "水质站") {
                        // 与实体相关的图片
                        billbo = {
                            image: 'http://www.sw797.com:10011/gzsw3D/v2/images/icon/szz.png',
                            pixelOffset: new Cesium.Cartesian2(0, 0),
                            width: 16,
                            height: 16,
                            heightReference : Cesium.HeightReference.CLAMP_TO_GROUND,
                            disableDepthTestDistance: Number.POSITIVE_INFINITY
                        }
                        // 与实体相关的文字
                        labble = {
                            show: true,
                            text: list[i][this.showName], // text 与实体相关的文字
                            font: "700 16px '黑体'",
                            fillColor: Cesium.Color.DEEPSKYBLUE,
                            // backgroundColor: Cesium.Color.DEEPSKYBLUE,
                            style: Cesium.LabelStyle.FILL_AND_OUTLINE,
                            outlineWidth: 3,
                            outlineColor: Cesium.Color.fromBytes(255, 255, 255), // 文字轮廓的颜色
                            verticalOrigin: Cesium.VerticalOrigin.CENTER,//垂直位置
                            horizontalOrigin: Cesium.HorizontalOrigin.LEFT,//水平位置
                            pixelOffset: new Cesium.Cartesian2(10, -10), // 文字位置
                            heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
                            disableDepthTestDistance: Number.POSITIVE_INFINITY
                        };
                    } else if (txt == "中小河流站") {
                        // 与实体相关的图片
                        billbo = {
                            image: 'http://www.sw797.com:10011/gzsw3D/v2/images/icon/zxhlz.png',
                            pixelOffset: new Cesium.Cartesian2(0, 0),
                            width: 16,
                            height: 16,
                            heightReference : Cesium.HeightReference.CLAMP_TO_GROUND,
                            disableDepthTestDistance: Number.POSITIVE_INFINITY
                        }
                        // 与实体相关的文字
                        labble = {
                            show: true,
                            text: list[i][this.showName], // text 与实体相关的文字
                            font: "700 16px '黑体'",
                            fillColor: Cesium.Color.DEEPSKYBLUE,
                            // backgroundColor: Cesium.Color.DEEPSKYBLUE,
                            style: Cesium.LabelStyle.FILL_AND_OUTLINE,
                            outlineWidth: 3,
                            outlineColor: Cesium.Color.fromBytes(255, 255, 255), // 文字轮廓的颜色
                            verticalOrigin: Cesium.VerticalOrigin.CENTER,//垂直位置
                            horizontalOrigin: Cesium.HorizontalOrigin.LEFT,//水平位置
                            pixelOffset: new Cesium.Cartesian2(10, -10), // 文字位置
                            heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
                            disableDepthTestDistance: Number.POSITIVE_INFINITY
                        };
                    }
                    this.map.scene.globe.depthTestAgainstTerrain = false;
                    var bill = this.map.entities.add({
                        id: this.id + list[i][this.idField],
                        position: Cesium.Cartesian3.fromDegrees(lgtd, lttd, 100),
                        label: labble,
                        billboard: billbo
                    });
                    this.billboards.push(bill);
                    this.datas[list[i][this.idField]] = list[i];
                    this.movehandLerLocation();
                }
                this.setVis(this.currentVis);
            },
            updateColor: function (billboards,txt){
                var chusColor;
                var selectedColor;
                if(txt == "水文站"){
                    chusColor =Cesium.Color.fromBytes(128, 255, 255);
                    selectedColor = new Cesium.Color(20, 20, 0, 1);
                }else if(txt =="水位站"){
                    chusColor =Cesium.Color.fromBytes(128, 255, 255);
                    selectedColor = new Cesium.Color(20, 20, 0, 1);
                }else if(txt =="雨量站"){
                    chusColor =Cesium.Color.fromBytes(0, 255, 0);
                    selectedColor = new Cesium.Color(20, 20, 0, 1);
                }
 
                for (var i = 0; i < this.billboards.length; i++) {
                    this.billboards[i].billboard.color._value=chusColor;
                }
 
                for (var i = 0; i < billboards.length; i++) {
                    viewer.entities.getById(this.id + billboards[i].OBJECTID).billboard.color._value=selectedColor;
                }
            },
 
            setVisible: function (vis) { //设置可见不可见
                if (this.billboards) {
                    var len = this.billboards.length;
                    for (var i = 0; i < len; ++i) {
                        var b = this.billboards[i];
                        b.show = vis;
                    }
                }
            },
            // 获取事件
            movehandLerLocation: function () {
                // 取消默认双击事件
                this.map.cesiumWidget.screenSpaceEventHandler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK);
                // 获取鼠标事件
                var handler = new Cesium.ScreenSpaceEventHandler(this.map.scene.canvas);
                // 给鼠标左键添加事件函数
                handler.setInputAction(lang.hitch(this, this.clickHandLocation), Cesium.ScreenSpaceEventType.LEFT_CLICK);
            },
            // 注册鼠标左键单击事件
            clickHandLocation: function (movement) {
                var pickedObject = this.map.scene.drillPick(movement.position);
                if (Cesium.defined(pickedObject)) {
                    for (var i = 0; i < pickedObject.length; ++i) {
                        var arrObj = pickedObject[i].id;
                        var LocationId = arrObj.id.split(this.id)[1];
                        if (this.datas.hasOwnProperty(LocationId)) {
                            this.openWindow(this.datas[LocationId]);
                            break;
                        }
                    }
                }
 
            },
            // 点击弹出面板;
            openWindow: function (item) {
                var top = ($(window).height()-526)/2;
                var left = ($(window).width()-802-280)/2+280;
                layer.open({
                    title: item.STNM,
                    type: 2,
                    shadeClose: true,
                    shade: false,
                    maxmin: true, //开启最大化最小化按钮
                    area: ['802px', '526px'],
                    offset: [top,left],
                    content: this.url + "?id=" +item.STCD,
                    id: "Location",
                    closeBtn: 1,
                });
                $('#loc_openWin').val(item.STCD);
            },
            setVis: function (vis) {
                this.currentVis = vis;
                this.setVisible(vis);
            },
        });
    });