qinbo
2021-11-16 afc782bf0610a55eae2e27b7d4e0ecb4565451ea
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
'use script' //开发环境建议开启严格模式
;
 
 
function getPositionFromLonLat(in_json_string) {
    let postion = [];
    var points = in_json_string.split(",");
    points.forEach(element => {
        var tmplon_lat = element.split(" ");
        postion[postion.length] = [tmplon_lat[0], tmplon_lat[1], 1];
    });
    return postion;
}
 
function getClass(o) { //判断数据类型
    return Object.prototype.toString.call(o).slice(8, -1);
}
 
function deepCopy(obj) {
    var result, oClass = getClass(obj);
 
    if (oClass == "Object") result = {}; //判断传入的如果是对象,继续遍历
    else if (oClass == "Array") result = []; //判断传入的如果是数组,继续遍历
    else return obj; //如果是基本数据类型就直接返回
 
    for (var i in obj) {
        var copy = obj[i];
 
        if (getClass(copy) == "Object") result[i] = deepCopy(copy); //递归方法 ,如果对象继续变量obj[i],下一级还是对象,就obj[i][i]
        else if (getClass(copy) == "Array") result[i] = deepCopy(copy); //递归方法 ,如果对象继续数组obj[i],下一级还是数组,就obj[i][i]
        else result[i] = copy; //基本数据类型则赋值给属性
    }
 
    return result;
}
(function (window, mars3d) {
    //创建widget类,需要继承BaseWidget
    class MyWidget extends mars3d.widget.BaseWidget {
        get view() {
            return {
                type: 'window',
                url: 'view.html',
                windowOptions: {
                    width: 450,
                    position: {
                        top: 140,
                        left: 5,
                        bottom: 80
                    },
                },
            }
        }
        //初始化[仅执行1次]
        create() {
            this.nodejs_url_predix = mars3d.global_variables.nodejs_url_predix;
            this.userid = mars3d.global_variables.userid;
            this.datatype = mars3d.global_variables.queryDataType;
            this.datatime = mars3d.global_variables.queryDataTStart;
        }
 
        reloadData(params) {
            this.datatype = mars3d.global_variables.queryDataType;
            this.datatime = mars3d.global_variables.queryDataTStart;
            this.winPage.reloadData();
        }
 
        locateAndHighlight(lon, lat) {
            this.map.flyToPoint(Cesium.Cartesian3.fromDegrees(lon, lat, 0.2));
        }
 
        HighlightMulti(layerid, qindex, selectedItem) {
            mars3d.global_variables.tmpHighlightGraphicLayer.clear(true);
 
            if (layerid == 1001 || layerid == 1002 || layerid == 1003 || layerid == 1004) {
                selectedItem.forEach(element => {
                    this.addPointToMap(layerid, qindex, element);
                });
 
            } else if (layerid == 1005 || layerid == 100500) {
                selectedItem.forEach(element => {
                    var path = element.shape;
                    if (path.substring(0, 1) == "M") {
                        var paths = (path.substring(17, path.length - 2)).split("),(");
                        paths.forEach(element_path => {
                            var positions = getPositionFromLonLat(element_path)
                            var tmpAttr = deepCopy(element);
                            delete tmpAttr['shape'];
                            this.addPathToMap(layerid, qindex, positions, tmpAttr);
                        });
                    } else {
                        var positions = getPositionFromLonLat(path.substring(11, path.length - 1))
                        var tmpAttr = deepCopy(element);
                        delete tmpAttr['shape'];
                        this.addPathToMap(layerid, qindex, positions, tmpAttr);
                    }
                });
            }else if (layerid == 1006) {
                selectedItem.forEach(element => {
                    var path = element.shape;
                    if(path == null && path == "null" && path == undefined){
                        return;
                    }
                    if (path.substring(0, 1) == "M") {
                        var paths = (path.substring(15, path.length - 3)).split(")),((");
                        paths.forEach(element_path => {
                            var positions = getPositionFromLonLat(element_path)
                            var tmpAttr = deepCopy(element);
                            delete tmpAttr['shape'];
                            this.addPolygonToMap(layerid, qindex, positions, tmpAttr);
                        });
                    } else {
                        var positions = getPositionFromLonLat(path.substring(9, path.length - 2));
                        var tmpAttr = deepCopy(element);
                        delete tmpAttr['shape'];
                        this.addPolygonToMap(layerid, qindex, positions, tmpAttr);
                    } 
                });
 
            }
        }
        addPolygonToMap(layerid, qindex, positions, attr) {
            var primitive = new mars3d.graphic.PolygonEntity({
                positions: positions,
                style: {
                    height: 50,
                    diffHeight: 200,
                    materialType: mars3d.MaterialType.PolyGradient,
                    color: this.winPage.getLayerPointColorByQindexandValue(layerid, qindex, attr[qindex]),
                    alphaPower: 1.5,
                    //高亮时的样式(默认为鼠标移入,也可以指定type:'click'单击高亮),构造后也可以openHighlight、closeHighlight方法来手动调用
                    highlight: {
                        color: "#ff0000",
                    },
                },
                attr: attr
            });
            mars3d.global_variables.tmpHighlightGraphicLayer.addGraphic(primitive);
        }
 
        addPointToMap(layerid, qindex, attr) {
            //立体围墙扩散效果,圆状
            var circleDiffuseWallGlow = new mars3d.graphic.DiffuseWall({
                position: Cesium.Cartesian3.fromDegrees(attr["lon"], attr["lat"], 20), //圆中心点
                style: {
                    diffHeight: qindex == "co" ? 10 * attr[qindex] :  attr[qindex], //高度
                    radius: 200, //半径
                    color: this.winPage.getLayerPointColorByQindexandValue(layerid, qindex, attr[qindex]),
                    speed: 10, //速度
                },
                attr: attr
            });
            mars3d.global_variables.tmpHighlightGraphicLayer.addGraphic(circleDiffuseWallGlow);
        }
 
        addPathToMap(layerid, qindex, positions, attr) {
            var road = new mars3d.graphic.WallPrimitive({
                positions: positions,
                style: {
                    closure: true,
                    diffHeight: qindex == "co" ? 10 * attr[qindex] :  attr[qindex], //高度
                    material: mars3d.MaterialUtil.createMaterial(mars3d.MaterialType.LineFlow, {
                        //动画线材质
                        image: "img/textures/fence.png",
                        axisY: true,
                        color: this.winPage.getLayerPointColorByQindexandValue(layerid, qindex, attr[qindex]),
                        speed: 10, //速度,建议取值范围1-100
                    }),
                },
                attr: attr
            });
            mars3d.global_variables.tmpHighlightGraphicLayer.addGraphic(road);
        }
 
        showDetailedWindow(params) {
            if (mars3d.widget.isActivate("widgetsTS/widget_detail/widget.js")) {
                var detailWiget = mars3d.widget.getClass("widgetsTS/widget_detail/widget.js");
                detailWiget.reloadData(params);
            } else {
                mars3d.widget.activate({
                    uri: "widgetsTS/widget_detail/widget.js",
                    disableOther: false,
                    params: params
                });
            }
        }
 
        //每个窗口创建完成后调用
        winCreateOK(opt, result) {
            this.winPage = result;
            // this.winPage.reloadData();
 
        }
 
        //打开激活
        activate() {
 
        }
        //关闭释放
        disable() { }
 
    }
 
    //注册到widget管理器中。
    mars3d.widget.bindClass(MyWidget)
 
    //每个widet之间都是直接引入到index.html中,会存在彼此命名冲突,所以闭包处理下。
})(window, mars3d)