1
Surpriseplus
2022-09-16 8d1a91c23df335b090e38b2edd15203aa3b03da9
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
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
 
// $(document).ready(function () {
//     init();
// });
var selectedView;
var arrViewVideo=[];
var selectedView1;
var selectedView2;
var selectedView3;
var selectedView4;
var videourl='http://10.32.24.233:8080/img/video/DJI_0119.mp4';
var hlsUrl=null;
function initVideo(){
    console.log("初始化");
 
    $("#chkDebugFrustum").change(function () {
        if (selectedView == null) return;
 
        var debugFrustum = $(this).is(':checked');
        selectedView.debugFrustum = debugFrustum;
    });
 
    $("#txtMixNum").range({
        onChange: function (value, bfb) {
            if (selectedView == null) return;
            selectedView.alpha = value;
        }
    });
    
    $("#cameraFov").range({
        onChange: function (value, bfb) {
            if (selectedView == null) return;
            selectedView.fov = value;
        }
    });
    
    
    $("#cameraWidHei").range({
        onChange: function (value, bfb) {
            if (selectedView == null) return;
            selectedView.aspectRatio = value;
        }
    });
    
 
    //修改坐标
    var drawControl = new mars3d.Draw(viewer, {
        hasEdit: false
    });
    drawControl.on(mars3d.draw.event.DrawMouseMove, function (e) {
        var pos = e.position;
        if (drawType === "ViewPos")
            arrViewVideo[arrViewVideo.length - 1].position = pos;
        if (drawType === "CameraPos")
            arrViewVideo[arrViewVideo.length - 1].cameraPosition = pos;
    });
    drawControl.on(mars3d.draw.event.DrawCreated, function (e) {
        drawControl.clearDraw();
    });
    
    var drawType;
    $("#btnSelCamera").click(function () {
        if (selectedView == null) return;
        // if(viewer.mars == undefined){
        //     viewer.mars = new mars3d.ViewerEx(viewer);
        // }
        drawType = "CameraPos";
        drawControl.clearDraw();
        drawControl.startDraw({ type: "point" });
    });
    $("#btnSelView").click(function () {
        if (selectedView == null) return;
        // if(viewer.mars == undefined){
        //     viewer.mars = new mars3d.ViewerEx(viewer);
        // }
        drawType = "ViewPos";
        drawControl.clearDraw();
        drawControl.startDraw({ type: "point" });
    });
 
    $("#btnLocate").click(function () {
        if (selectedView == null) return;
        selectedView.locate();
    });
 
    $("#btnConsoleJson").click(function () {
        if (selectedView == null) return;
 
        var params = JSON.stringify(selectedView.params);
        console.log(params);
        haoutil.msg(params);
    });
 
    $("#btnPlayPause").click(function () {
        if (selectedView == null) return;
 
        selectedView.videoPlay = !selectedView.videoPlay;
    });
    
    bindKeydownEvnet();
    //addHistoryVideo1() ;
                //addHistoryVideo2();
                //addHistoryVideo();
    //viewerflyToLonLat(118.869942,33.309917,1);
}
 
function addHistoryVideo() {
    var camera = viewer.scene.camera;
    camera.setView({
        destination: Cesium.Cartesian3.fromDegrees(118.55966032833229, 31.976695936962915, 159.54014013189413),
        orientation: {
            direction: new Cesium.Cartesian3( 0.15284668979678995,-0.2026634956655926, -0.9672462959054257),
            up: new Cesium.Cartesian3(-0.42820575667497207, 0.8685149858870838,-0.24964284335821352),
            right: new Cesium.Cartesian3(0.8906613943405083, 0.4523375142680082, 0.04596796511986649)
        }
    });
    // 加载已配置好的视频(此参数为界面上“打印参数”按钮获取的)
    var params1 = {
        type: mars3d.video.Video3D.Type.Video,
        url: "./video/1.MP4",
        position: Cesium.Cartesian3.fromDegrees(120.55966032833229, 28.976695936962915, 159.54014013189413), 
        cameraPosition: Cesium.Cartesian3.fromDegrees(118.55966032833229, 31.976695936962915, 159.54014013189413),
        fov: 58,
        aspectRatio: 1.7778,
        alpha: 0.7,
        debugFrustum: false,
        dirObj: {
            direction: { x: 0.15284668979678995, y: -0.2026634956655926, z: -0.9672462959054257},
            right: { x: 0.8906613943405083, y: 0.4523375142680082, z: 0.04596796511986649 },
            up: { x: -0.42820575667497207, y: 0.8685149858870838, z: -0.24964284335821352 }
        }
    }
 
    selectedView = new mars3d.video.Video3D(viewer, params1);
    arrViewVideo.push(selectedView);
}
 
function addHistoryVideo1() {
    
    // 加载已配置好的视频(此参数为界面上“打印参数”按钮获取的)
    var params1 = {
        type: mars3d.video.Video3D.Type.Video,
        //url:"http://10.32.24.233:8080/img/video/DJI_0120_00_02_10.mp4","position":{"x":-2620207.5321477014,"y":4710443.073189139,"z":3398466.5078547043},"cameraPosition":{"x":-2620200.830350536,"y":4710481.110750541,"z":3398474.7447419357},"fov":57.3,"aspectRatio":1.990668740279938,"alpha":0.8,
        "url":"http://10.32.24.233:8080/img/video/DJI_0120 00_00_00-00_01_01.mp4","position":{"x":-2620207.0157359475,"y":4710443.6707390025,"z":3398466.111278378},"cameraPosition":{"x":-2620202.261681702,"y":4710480.551432474,"z":3398475.5831979616},"fov":56.7,"aspectRatio":1.9,"alpha":0.8,
        debugFrustum: false
    }
 
    selectedView1 = new mars3d.video.Video3D(viewer, params1);
    //arrViewVideo.push(selectedView1);
}
 
function addHistoryVideo2() {
    
    // 加载已配置好的视频(此参数为界面上“打印参数”按钮获取的)
    var params1 = {
        type: mars3d.video.Video3D.Type.Video,
        //url:"http://10.32.24.233:8080/img/video/DJI_0003_1 00_02_10.mp4","position":{"x":-2620227.2554531517,"y":4710425.355336995,"z":3398475.417897917},"cameraPosition":{"x":-2620226.989430694,"y":4710463.347535606,"z":3398490.2529985034},"fov":56.1,"aspectRatio":1.990668740279938,"alpha":0.8,
        "url":"http://10.32.24.233:8080/img/video/DJI_0003_1 00_00_00-00_01_01.mp4","position":{"x":-2620226.9297979367,"y":4710425.663849721,"z":3398475.231407834},"cameraPosition":{"x":-2620226.803189126,"y":4710457.677956819,"z":3398487.412634559},"fov":62.29999999999999,"aspectRatio":1.990668740279938,"alpha":0.8,
        debugFrustum: false
    }
 
    selectedView2 = new mars3d.video.Video3D(viewer, params1);
    //arrViewVideo.push(selectedView2);
}
 
function addHistoryVideo3() {
    
    // 加载已配置好的视频(此参数为界面上“打印参数”按钮获取的)
    var params1 = {
        type: mars3d.video.Video3D.Type.Video,
        url: "http://10.32.24.233:8080/img/video/DJI_0119.mp4",
        "position":{"x":-2620948.205397221,"y":4709851.305287631,"z":3398710.34265271},"cameraPosition":{"x":-2620982.6203615326,"y":4709875.980817173,"z":3398737.010255333},"fov":45.5,"aspectRatio":1.926260346124906,"alpha":0.8,"debugFrustum":false
    }
 
    selectedView3 = new mars3d.video.Video3D(viewer, params1);
    //arrViewVideo.push(selectedView2);
}
 
function addHistoryVideo4() {
    
    // 加载已配置好的视频(此参数为界面上“打印参数”按钮获取的)
    var params1 = {
        type: mars3d.video.Video3D.Type.Video,
        url: "http://10.32.24.233:8080/img/video/DJI_0002.mp4",
        "position":{"x":-2620930.368913842,"y":4709866.550191198,"z":3398702.857806974},"cameraPosition":{"x":-2620951.4737488255,"y":4709893.469478797,"z":3398726.289609433},"fov":50.5,"aspectRatio":1.95,"alpha":0.8,"debugFrustum":false
    }
 
    selectedView4 = new mars3d.video.Video3D(viewer, params1);
    //arrViewVideo.push(selectedView2);
}
 
function createViewForVideo() {
    if(videourl==null && hlsUrl==null){
        return;
    }
    
    //取屏幕中心点
    var cartesian = mars3d.point.getCenter(viewer);
    cartesian = Cesium.Cartesian3.fromDegrees(cartesian.x, cartesian.y, cartesian.z);
    if (!cartesian) return;
    var cameraPosition = Cesium.clone(viewer.scene.camera.position);
 
 
    var debugFrustum = $("#chkDebugFrustum").is(':checked');
    var alpha = Number($("#txtMixNum").val());
 
    if(videourl!=null){
        //构造投射体
        selectedView = new mars3d.video.Video3D(viewer, {
            type: mars3d.video.Video3D.Type.Video,
            url: videourl,
            cameraPosition: cameraPosition,
            position: cartesian,
            alpha: alpha,
            debugFrustum: debugFrustum,
        });
    }else{
        var id = arrViewVideo.length+1;
        createVideoElement(id);
        var videoElement = document.getElementById('trailer'+id);
        if (Hls.isSupported()) {
            var hls = new Hls();
            hls.loadSource(hlsUrl);
            hls.attachMedia(videoElement);
            hls.on(Hls.Events.MANIFEST_PARSED, function () {
                videoElement.play();
            });
        }
        else if (videoElement.canPlayType('application/vnd.apple.mpegurl')) {
            videoElement.src = hlsUrl;
            videoElement.addEventListener('loadedmetadata', function () {
                videoElement.play();
            });
        }
        selectedView = new mars3d.video.Video3D(viewer, {
            type: mars3d.video.Video3D.Type.Video,
            dom: $("#trailer"+id),
            cameraPosition: cameraPosition,
            position: cartesian,
            alpha: alpha,
            debugFrustum: debugFrustum,
        });
    }
    
    
    arrViewVideo.push(selectedView);
}
 
function clearVideo() {
    for (var i = 0; i < arrViewVideo.length; i++) {
        arrViewVideo[i].destroy();
    }
    arrViewVideo = [];
    selectedView = null;
    //selectedView1 = null;
    //selectedView2 = null;
}
 
function clearHisVideo(){
    selectedView1.destroy();
    selectedView2.destroy();
    selectedView3.destroy();
    selectedView4.destroy();
    selectedView1 = null;
    selectedView2 = null;
    selectedView3 = null;
    selectedView4 = null;
}
 
function locateMain(){
    selectedView.locate();
}
 
function locate1(){
    selectedView1.destroy();
    selectedView2.destroy();
    selectedView3.destroy();
    selectedView4.destroy();
    addHistoryVideo2();
    addHistoryVideo3();
    addHistoryVideo4();
    addHistoryVideo1();
    
    selectedView1.locate();
}
 
function locate2(){
    selectedView1.destroy();
    selectedView2.destroy();
    selectedView3.destroy();
    selectedView4.destroy();
    addHistoryVideo1();
    addHistoryVideo3();
    addHistoryVideo4();
    addHistoryVideo2();
    
    selectedView2.locate();
}
 
function locate3(){
    selectedView1.destroy();
    selectedView2.destroy();
    selectedView3.destroy();
    selectedView4.destroy();
    addHistoryVideo1();
    addHistoryVideo2();
    addHistoryVideo4();
    addHistoryVideo3();
    
    selectedView3.locate();
}
 
function locate4(){
    selectedView1.destroy();
    selectedView2.destroy();
    selectedView3.destroy();
    selectedView4.destroy();
    addHistoryVideo1();
    addHistoryVideo2();
    addHistoryVideo3();
    addHistoryVideo4();
    
    selectedView4.locate();
}
 
function showMain(){
    selectedView.show = !selectedView.show;
}
 
function show1(){
    selectedView1.show = !selectedView1.show;
}
 
function show2(){
    selectedView2.show = !selectedView2.show;
}
 
function show3(){
    selectedView3.show = !selectedView3.show;
}
 
function show4(){
    selectedView4.show = !selectedView4.show;
}
 
var cameraFollow = false;
var ratateDirection = {
    'LEFT': 'Z',
    'RIGHT': '-Z',
    'TOP': 'Y',
    'BOTTOM': '-Y',
    'ALONG': 'X',
    'INVERSE': '-X'
}
 
function bindKeydownEvnet() {
    $("#chkCameraFollow").change(function () {
        cameraFollow = $(this).is(':checked');
    });
 
    document.addEventListener('keydown', function (e) {
        switch (e.keyCode) {
            case 'A'.charCodeAt(0):
                rotateCamera(ratateDirection.LEFT);
                break;
            case 'D'.charCodeAt(0):
                rotateCamera(ratateDirection.RIGHT);
                break;
            case 'W'.charCodeAt(0):
                rotateCamera(ratateDirection.TOP);
                break;
            case 'S'.charCodeAt(0):
                rotateCamera(ratateDirection.BOTTOM);
                break;
            case 'Q'.charCodeAt(0)://Q键
                rotateCamera(ratateDirection.ALONG);
                break;
            case 'E'.charCodeAt(0)://E
                rotateCamera(ratateDirection.INVERSE);
                break;
        }
    }, false);
}
 
//微调视频
function rotateCamera(dir) {
    if (!selectedView) return;
    selectedView.rotateCamera(dir, $("#rotateDeg").val() * 1);
 
    if (cameraFollow) {
        viewer.camera.direction = selectedView.camera.direction;
        viewer.camera.right = selectedView.camera.right;
        viewer.camera.up = selectedView.camera.up;
    }
}
 
function closeVideoFrame(){
    $("#video_toolbar").css('display','none');
    
}
 
function closehVideoFrame(){
    $("#hvideo_toolbar").css('display','none');
    
}
 
var dv = document.getElementById('video_title');
var dv1 = document.getElementById('video_toolbar');
//dv.style.cursor = 'move';
var videox=0;
var videoy=0;
var videol=0;
var videot=0;
var isVideoDown=false;
dv.onmousedown = function(e){
    videox = e.clientX;
    videoy = e.clientY;
    videol = dv1.offsetLeft;
    videot = dv1.offsetTop;
 
    isVideoDown = true;
    dv.style.cursor = 'move';
}
 
dv.onmousemove = function(e){
    if(isVideoDown==false){
        return;
    }
    
    var nx = e.clientX;
    var ny = e.clientY;
 
    var nl = nx - (videox-videol);
    var nt = ny - (videoy-videot);
    
    dv1.style.left = nl + 'px';
    dv1.style.top = nt + 'px';
}
 
dv.onmouseup = function(e){
    isVideoDown = false;
    dv.style.cursor = 'default';
}
 
function FHKVideo(url, fn) {
    window.parent.libraryFn(url, fn, 'video');
}
 
function FHKvideoCb(url) {
    videourl = url;
    hlsUrl = null;
}
 
function okHls(){
    var inputValue = document.getElementById("hlsInput").value;
    if(inputValue==""){
        return;
    }
    hlsUrl = inputValue;
    videourl = null;
    $("#hls_toolbar").css('display','none');
}
 
function cancelHls(){
    $("#hls_toolbar").css('display','none');
}
 
function showHlsToolbar(){
    $("#hls_toolbar").css('display','block');
}
 
function createVideoElement(id){
    var html = '<video id="trailer'+id+'" style="display: none;" muted="muted" autoplay="autoplay" loop="loop" crossorigin="" controls=""></video>'
    document.getElementById("videoHtml").innerHTML=html;
}