zhanmingkan
2022-05-17 18eabf15daa1876b5200659e8fac24b2bd76ff39
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
document.write('<script src="../js/car_service.js"></script>');
/*
 * 车辆监督:实时定位和轨迹方法
 */
//打开车辆定位功能的交互操作
var policeCarInterval;
var deviceListCar=[];
//构建车辆目录树方法
function createZTree(data,count){
    //构建目录树
    var treeObjList = null;
    if (data !== undefined || data != null) {
        var setting = {
            check : {
                enable : true,
                autoCheckTrigger : true,
                chkboxType : { "Y" : "s", "N" : "s" }
            },
            data : {
                simpleData : {
                    enable : true
                }
            },
            callback : {
                onCheck : carLayerzTreeOnCheck,
                onClick : carLayerzTreeOnClick,
            },
            view : {
                showIcon : showIconForTree,
                selectedMulti : true,     //可以多选
                fontCss : setFontCss,      //状态颜色回调函数
            }
        };
        var treeListArray = [];
        var treeName = "车辆载具目录树 "+" (共"+count+"辆)";
        var pNode = {id:0, pId:"", name:treeName, isNode:false, icon:"../images/treeicon/car1.png"};
        treeListArray.push(pNode);
        for (var i = 0; i < data.length; i++) {
            var j = {};
            j.id = data[i].carId;
            j.pId = 0;
            j.name = data[i].policeType+'('+data[i].carLicense+')';
            j.highlight = false;
            j.isNode = true;
            j.phone = data[i].cardNum;
            treeListArray.push(j);
        }
        treeObjList = $.fn.zTree.init($("#policeCarTree"), setting, treeListArray);
        policeCarInterval = window.setInterval(function(){
            freshPoliceCarPos(deviceListCar);
        },30000);
        //父节点显示图标
        function showIconForTree(treeId, treeNode) {
            return treeNode.isParent == true;
        }
        //状态变化不同颜色的回调函数
        function setFontCss(treeId, treeNode) {
            return treeNode.checked == true ? {color:"white"} : {color:"gray"};
        };
        //点击车辆check执行
        function carLayerzTreeOnCheck(event, treeId, treeNode) {
            var node = treeObjList.getNodeByParam('id',treeNode.id,null);
            treeObjList.updateNode(node);
            treeObjList.reAsyncChildNodes(node,'refresh',false);
            if(treeNode.level!=0){
                if(treeNode.name!=undefined){
                    var result = treeNode.name.match(/\(([^)]*)\)/);
                }
                if(treeNode.checked){
                    if(deviceListCar.length==0||deviceListCar.indexOf(result[1])==-1){
                        deviceListCar.push(result[1]);
                    }
                    freshPoliceCarPos(deviceListCar);
                }else{
                    deviceListCar.splice(deviceListCar.indexOf(result[1]),1);
                    viewer.entities.removeById('pc'+treeNode.id);
                    closeVideoPop(treeNode.id);
                }
            }
        }        
    }
}
//停止刷新车辆位置
function stopFreshPoliceCarPos(){
    window.clearInterval(policeCarInterval);
}
 
//创建车辆标签
var policecar3D_marks=[];
function createPoliceCarPin(url,id,point,carLicense,cartype){
    var carPin = viewer.entities.getById('pc'+id);
    if(carPin == undefined){
        policecar3D_marks.push(viewer.entities.add({
            name : '车辆',
            id :'pc'+id,
            position : point,
            billboard : {
                image : url,
                verticalOrigin : Cesium.VerticalOrigin.BOTTOM,
                pixelOffset : new Cesium.Cartesian2(51.0, 0.0),
                scaleByDistance : new Cesium.NearFarScalar(1000, 1, 20000, 0.2),
                pixelOffsetScaleByDistance : new Cesium.NearFarScalar(1000, 1, 20000, 0.2),
            },
            label : {
                show : true,
                verticalOrigin : Cesium.VerticalOrigin.BOTTOM,
                horizontalOrigin : Cesium.HorizontalOrigin.CENTER,
                font : 'bold 17px Helvetica',
                fillColor : Cesium.Color.WHITE,
                text : carLicense,
                pixelOffset : new Cesium.Cartesian2(67.0, -135.0),
                disableDepthTestDistance : 100000000,
                scaleByDistance : new Cesium.NearFarScalar(1000, 1, 20000, 0.2),
                pixelOffsetScaleByDistance : new Cesium.NearFarScalar(1000, 1, 20000, 0.2),
            }
        }));
    }else{
        carPin.position = point;
    }
}
//车辆实时监督
function showPoliceCar_3D(data){
    var url = '';
    deletePoliceCar3DMarks();
    $.each(data, function() {
        var carId = this.car.carId;
        var carLicense = this.car.carLicense;
        var cartype = this.car.policeType;
        if(this.realdata!=undefined){
            var point = Cesium.Cartesian3.fromDegrees(
                    Number(this.realdata.longitude),
                    Number(this.realdata.latitude),
                    Number(this.realdata.altitude)+mancarHeight);
            var clampedpoint = viewer.scene.clampToHeight(point);//将悬空的点落到三维或地形数据上
            switch (cartype) {
            case '巡逻车':
                url = '../images/pinimg/13.png';
                break;
            case '警卫车':
                url = '../images/pinimg/15.png';
                break;
            case '防爆装甲车':
                url = '../images/pinimg/14.png';
                break;
            default:
                url = '../images/pinimg/16.png';
                break;
            };
            createPoliceCarPin(url,carId,clampedpoint,carLicense,cartype);
            //如有气泡,更新气泡位置
            if(document.getElementById("popupDiv"+carId)){
                var pos = {"lon":Number(this.realdata.longitude),"lat":Number(this.realdata.latitude),"alt":Number(this.realdata.altitude)+mancarHeight};
                CesiumPop.updatePopPos(viewer,carId,pos,70,260,185,Cesium.Color.WHITE);
            }
        }
    });
    CesiumPop.bindPopGlobeEventHandler(viewer)
    addPOMListener();
}
function deletePoliceCar3DMarks(){
    for(var i = 0; i < policecar3D_marks.length; i++){
        viewer.entities.remove(policecar3D_marks[i]); // 将标注从场景移除
    }
    policecar3D_marks.length=0;
}
//历史轨迹回放
function carHisplay_3D(data){
    carHisStop3D();
    var traceList = [];
    for(var i=0; i<data.length; i++){
        traceList.push(Number(data[i].longitude)); 
        traceList.push(Number(data[i].latitude)); 
        traceList.push(Number(data[i].altitude)+5); 
    }
    
    var position = [Number(data[0].longitude),Number(data[0].latitude),500];
    flyToLocation(position);
    
    var startTime = Cesium.JulianDate.now(startTime);
    var stopTime = Cesium.JulianDate.now(startTime);
    var result = createCarLines(traceList,data[0].simNo,'car.png');
    if(Cesium.JulianDate.compare(startTime, result.startTime)>0){startTime = result.startTime;}
    if(Cesium.JulianDate.compare(stopTime, result.stopTime)<0){stopTime = result.stopTime;}
    
    viewer.clock.startTime = startTime.clone();
    viewer.clock.stopTime = stopTime.clone();
    viewer.clock.currentTime = startTime.clone();
    viewer.clock.clockRange = Cesium.ClockRange.UNBOUNDED;
    viewer.clock.multiplier = 10;
    viewer.timeline.zoomTo(startTime, stopTime);
    
    layer.closeAll();
}
//添加轨迹线和实体等
var policecarLine;
var policecar_mark;
var policecar_mark_start;
var policecar_mark_end;
function createCarLines(nodes,lineId,imgName){
    //添加轨迹线
    policecarLine = viewer.entities.add({
        polyline : {
            positions : Cesium.Cartesian3.fromDegreesArrayHeights(nodes),
            width : 7.0,
            material : new Cesium.PolylineGlowMaterialProperty({
                color : Cesium.Color.BLUE,
                glowPower : 0.25
            }),
            clampToGround : true,
            classificationType : Cesium.ClassificationType.BOTH
        }
    });
    //添加移动实体
    var nodesPosition = [];
    var times = [];
    var startTime = Cesium.JulianDate.now(startTime);
    for (var i = 0; i < nodes.length / 3; i++) {
        var time = new Cesium.JulianDate();
        Cesium.JulianDate.addMinutes(startTime, i * 0.5, time);
        times.push(time);
        nodesPosition.push(Cesium.Cartesian3.fromDegrees(
                nodes[i * 3], nodes[i * 3 + 1], nodes[i * 3 + 2] + 2.5));
    }
    var stopTime = times[times.length - 1];
    //插值
    var property = new Cesium.SampledPositionProperty();
    property.addSamples(times, nodesPosition);
    var pinBuilder = new Cesium.PinBuilder();
    Cesium.when(pinBuilder.fromUrl('../images/'+imgName, Cesium.Color.RED , 48),function(canvas) {
        policecar_mark = viewer.entities.add({
            id :lineId,
            position : property,
            billboard : {
                image : canvas.toDataURL(),
                verticalOrigin : Cesium.VerticalOrigin.BOTTOM,
                scale : 1,
                //大于20000显示pin,隐藏模型
                pixelOffset:new Cesium.Cartesian2(0,0),
                pixelOffsetScaleByDistance:new Cesium.NearFarScalar(1.5e2,3.0,1.5e7,0.7),
                translucencyByDistance :new Cesium.NearFarScalar(19999,0,20000,1)
            },
            model : {
                uri : '../../easy3dfile/data/model/military/99tank.gltf',
                minimumPixelSize : 128,
                maximumScale : 20,
                scale : 0.008,
                //小于20000显示模型,隐藏pin
                distanceDisplayCondition:new Cesium.DistanceDisplayCondition(0,20000),
            }
        });
    });
    //起点
    var startpoint = Cesium.Cartesian3.fromDegrees(
            Number(nodes[0]), Number(nodes[1]), Number(nodes[2]));
    policecar_mark_start = viewer.entities.add({
        position : startpoint,
        billboard : {
            image : pinBuilder.fromText('起',Cesium.Color.GREEN,40).toDataURL(),
            verticalOrigin : Cesium.VerticalOrigin.BOTTOM,
        }
    });
    //终点
    var endpoint = Cesium.Cartesian3.fromDegrees(
            Number(nodes[i-2]), Number(nodes[i-1]), Number(nodes[i]));
    policecar_mark_end = viewer.entities.add({
        position : endpoint,
        billboard : {
            image : pinBuilder.fromText('终',Cesium.Color.RED,40).toDataURL(),
            verticalOrigin : Cesium.VerticalOrigin.BOTTOM,
        }
    });
    return {
        startTime:startTime,
        stopTime:stopTime
    };
}
//历史轨迹停止
function carHisStop3D(){
    viewer.entities.remove(policecarLine);
    viewer.entities.remove(policecar_mark);
    viewer.entities.remove(policecar_mark_start);
    viewer.entities.remove(policecar_mark_end);
    layer.closeAll();
}
//圈内图标高亮
function highlightCarPin(data){
    for(var i=0;i<data.length;i++){
        viewer.entities.getById(data[i].id).billboard.color = Cesium.Color.WHITE;
    }
}
function showCarPop(data,posCart) {
    closeVideoPop(data.carId);
    var num=0;
    var dataCE=data.CarEquipments
    if(dataCE!=undefined){
        for(var i=0;i<dataCE.length;i++){
            num+=Number(dataCE[i].equipmentcar.equipmentcarGrade)
        }
    }
    var popcolor = '';
    switch (data.policeType) {
        case '防爆装甲车':
            popcolor = '#00d3e7';
            break;
        case '巡逻车':
            popcolor = '#FF6A6A';
            break;
        case '武装巡逻车':
            popcolor = '#836FFF';
            break;
        case '警卫车':
            popcolor = '#FFD700';
            break;
        default:
            break;
    }
    var content = '<div style="box-shadow:0 0 25px '+popcolor+'" class="ibox float-e-margins mybox mapPopMan">'
                + '<div style="box-shadow:inset 0 0 15px '+popcolor+'" class="ibox-title mybox-title">'
                + '<h5>'+data.carLicense+'-5G图传</h5><div class="ibox-tools">'
                + '<i class="fa fa-object-group myfab myfa-dark" onclick="initSewisePlayer(\''+data.deviceNum+'\',\''+data.name+'\')" title="视频图传"></i>'
                + '<i class="fa fa-car myfab myfa-dark" '
                +'onclick="showInfoPoliceCar_3D('+JSON.stringify(data).replace(/"/g,'&quot;')+')" title="车辆信息"></i>'
                + '<i class="fa fa-remove myfab myfa-dark" onclick="closeVideoPop(\''+data.carId+'\')" title="关闭气泡"></i>'
                + '</div></div><div class="ibox-content equipPopnei"><div style="margin-bottom:5px;">战斗能力综合评分:'+num+'</div><div class="popBoxwai">'
                + '<div class="equipLeftbox">'
                + '<img src="'+data.image+'" alt=""></div>'
                + '<div class="equipPopRightbox">'
                if(dataCE!=undefined){
                    for(var i=0;i<dataCE.length;i++){
                        content+= '<div class="equipPoliceType">'+dataCE[i].equipmentcar.equipmentcarType+':<img alt="无图" src="'+(dataCE[i].equipmentcar.equipmentcarPicture==null?"../images/noneImg.png":dataCE[i].equipmentcar.equipmentcarPicture)+'"></div>'
                    }
                }else{
                    content+= '<div class="equipPoliceType" style="text-align:center;">未佩戴装备<img src="../images/noneImg.png"  alt="未佩戴装备" style="width:72px;height:50px;margin:10px 49px 0 0;"></div>'
                }
                content+='</div></div></div></div>'
                + '<div style="border-top-color:'+popcolor+'" class="box_leg box_legnew"></div>'
                + '<div style="border-color:'+popcolor+'" class="box_lt"></div>'
                + '<div style="border-color:'+popcolor+'" class="box_lb"></div>'
                + '<div style="border-color:'+popcolor+'" class="box_rt"></div>'
                + '<div style="border-color:'+popcolor+'" class="box_rb"></div></div>';
    var cartographic = Cesium.Cartographic.fromCartesian(posCart);
    var lon = Cesium.Math.toDegrees(cartographic.longitude);
    var lat = Cesium.Math.toDegrees(cartographic.latitude);
    var options = {
        "viewer":viewer,
        "id":data.carId,
        "popupWidth":300,
        "popupHeight":185,
        "pos":{"lon":Number(lon),"lat":Number(lat),"alt":Number(cartographic.height)},
        "extentHeight":70,
        "extentColor":Cesium.Color.WHITE,
        "content":content
    };
    CesiumPop.addDivPop(options);
}