liuxiaolong
2019-05-06 2418a2d61feea858e9e63aa52fd64ddfe17e392a
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
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
<template>
  <div :id="newMapId" class="map"></div>
</template>
<script>
/* eslint-disable */
import { findInArrJson } from '@/components/common/util.js'
import {getDeviceType,getDeviceBrand,getDevSnapshot} from '@/server/home.js'
export default {
  components: {
 
  },
  props: {
    newId:{
      default:'amap',
      type:String
    },
    zoomSize:{
      default:12,
      type:Number
    }
  },
  computed: {
    newMapId() {
      return this.newId && this.newId !== '' ? this.newId : 'amap'
    },
    newDefaultMapZoom() {
      return this.zoomSize && this.zoomSize !== ''
        ? this.zoomSize
        : 14
    }
  },
  data() {
    return {
      /** 存放地图对象 */
      mapObject: {},
      /** 存放设备信息 */
      deviceMarkers: [],
      /** 信息窗体 */
      textInfoWindow: {},
      textInfoWindow2: {},
      indexPlayer: 1,
      /** 用于存储拖拽物放下时的坐标 */
      point: {},
      /** 获取设备品牌 */
      deviceBrandList: []
    }
  },
  methods: {
    // 获取摄像机实时最新图片
    async getNowBigImg(videoReqNum) {
      const res = await getDevSnapshot({ devId: videoReqNum })
      if (res && res.success) {
        return res.data.imgUrl
      }
      return '/static/img/map/1111.jpg'
    },
    InitMap() {
      console.log(this.newMapId,'初始化地图!!!!')
      const map = new AMap.Map(this.newMapId, {
        center: [116.397428, 39.90923],
        resizeEnable: true,
        zoom: this.newDefaultMapZoom
      })
      /** 添加地图插件 */
      AMap.plugin(['AMap.ToolBar'],function(){
        map.addControl(new AMap.ToolBar({
            // 简易缩放模式,默认为 false
            liteStyle: true
        }))
      })
      /** 获取品牌 */
      this.getDeviceBrand()
      this.mapObject = map
      //创建全局弹窗
      this.textInfoWindow = new AMap.InfoWindow({
        isCustom: true,
        autoMove: true,
        closeWhenClickMap: true,
        size: new AMap.Size(449, 427),
        offset: new AMap.Pixel(5, -35)
      })
      this.textInfoWindow2 = new AMap.InfoWindow({
        isCustomL: true,
        autoMove: false,
        closeWhenClickMap: true,
        size: new AMap.Size(430, 410),
        offset: new AMap.Pixel(0, -20)
      })
 
    },
    amapPto(lng, lat) {
      if (lng && lat) {
        this.mapObject.panTo(new AMap.LngLat(lng, lat))
      }
    },
    /** 设备marker标记点 */
    amapCreateMarker(arr){
      const map = this.mapObject
      let mapData = arr || []
      //更改地图中心
      if(mapData && mapData.length > 0 && mapData[0]){
        let arrIndex = mapData.length - 1
        this.amapPto(mapData[arrIndex].longitude, mapData[arrIndex].latitude)
      } else {
        return false
      }
      /** 摄像头全局对象 */
      let cameraMarkers = []
      /** 渲染marker */
      console.log(mapData,'mapData')
      for(let i = 0; i < mapData.length; i++){
        if (
          mapData[i].longitude &&
          mapData[i].latitude &&
          mapData[i].longitude !== 'None' &&
          mapData[i].latitude !== 'None'
        ) {
          let url = this.getvideoUrl(mapData[i])
          this.$set(mapData[i],'url',url)
          let pt = new AMap.LngLat(mapData[i].longitude, mapData[i].latitude)
          let iconStrOnline = '/static/img/icon/green_camer.png'
          let iconStrAlarm = '/static/img/map/camera_device_alarm.png'
          let iconUnline = '/static/img/map/camera_device.png'
          /* 图标设置 */
          //绿色摄像头图标
          let cameraIcon_green = new AMap.Icon({
            size: new AMap.Size(48, 48),
            image: '/static/img/icon/green_camer.png',
            imageOffset: new AMap.Pixel(0, 0),
            imageSize: new AMap.Size(36, 36)
          })
          //绿色摄像头高亮图标
          let cameraIcon_green_active = new AMap.Icon({
            size: new AMap.Size(48, 48),
            image: '/static/img/icon/green_camer_active.gif',
            imageOffset: new AMap.Pixel(0, 0),
            imageSize: new AMap.Size(48, 48)
          })
          //红色摄像头图标
          let cameraIcon_red = new AMap.Icon({
            size: new AMap.Size(48, 48),
            image: '/static/img/icon/red_camer.png',
            imageOffset: new AMap.Pixel(0, 0),
            imageSize: new AMap.Size(36, 36)
          })
          //灰色摄像头图标
          let cameraIcon_gray = new AMap.Icon({
            size: new AMap.Size(48, 48),
            image: '/static/img/icon/gray_camer.png',
            imageOffset: new AMap.Pixel(0, 0),
            imageSize: new AMap.Size(36, 36)
          })
          //灰色摄像头高亮图标
          let cameraIcon_gray_active = new AMap.Icon({
            size: new AMap.Size(48, 48),
            image: '/static/img/icon/gray_camer_active.gif',
            imageOffset: new AMap.Pixel(0, 0),
            imageSize: new AMap.Size(48, 48)
          })
          //红色摄像头高亮图标
          let cameraIcon_red_active = new AMap.Icon({
            size: new AMap.Size(48, 48),
            image: '/static/img/icon/red_camer_active.gif',
            imageOffset: new AMap.Pixel(0, 0),
            imageSize: new AMap.Size(48, 48)
          })
          //绿色服务器图标
          let serverIcon_green = new AMap.Icon({
            size: new AMap.Size(48, 48),
            image: '/static/img/icon/green_server.png',
            imageOffset: new AMap.Pixel(0, 0),
            imageSize: new AMap.Size(36, 36)
          })
          //绿色服务器高亮图标
          let serverIcon_green_active = new AMap.Icon({
            size: new AMap.Size(48, 48),
            image: '/static/img/icon/green_server_active.gif',
            imageOffset: new AMap.Pixel(0, 0),
            imageSize: new AMap.Size(48, 48)
          })
          //红色服务器图标
          let serverIcon_red = new AMap.Icon({
            size: new AMap.Size(48, 48),
            image: '/static/img/icon/red_server.png',
            imageOffset: new AMap.Pixel(0, 0),
            imageSize: new AMap.Size(36, 36)
          })
          //红色服务器高亮图标
          let serverIcon_red_active = new AMap.Icon({
            size: new AMap.Size(48, 48),
            image: '/static/img/icon/red_server_active.gif',
            imageOffset: new AMap.Pixel(0, 0),
            imageSize: new AMap.Size(48, 48)
          })
          //灰色服务器图标
          let serverIcon_gray = new AMap.Icon({
            size: new AMap.Size(48, 48),
            image: '/static/img/icon/gray_server.png',
            imageOffset: new AMap.Pixel(0, 0),
            imageSize: new AMap.Size(36, 36)
          })
          //灰色服务器高亮图标
          let serverIcon_gray_active = new AMap.Icon({
            size: new AMap.Size(48, 48),
            image: '/static/img/icon/gray_server_active.gif',
            imageOffset: new AMap.Pixel(0, 0),
            imageSize: new AMap.Size(48, 48)
          })
          //高亮图标
          let cameraIcon_active = new AMap.Icon({
            size: new AMap.Size(48, 48),
            image: iconStrAlarm,
            imageOffset: new AMap.Pixel(0, 0),
            imageSize: new AMap.Size(48, 48)
          })
          let marker
          if(mapData[i].status === 0){
            /** 状态0为正常 */
            if(mapData[i].type === '101'){
              /** 101 摄像机 */
              marker = new AMap.Marker({
                position: pt,
                icon:cameraIcon_green,
                offset: new AMap.Pixel(-25, -40)
              })
              marker.Icon_original = cameraIcon_green
              marker.Icon_active = cameraIcon_green_active
            } else if(mapData[i].type === '103'){
              /** 103分析设备(服务器) */
              marker = new AMap.Marker({
                position: pt,
                icon:serverIcon_green,
                offset: new AMap.Pixel(-25, -40)
              })
              marker.Icon_original = serverIcon_green
              marker.Icon_active = serverIcon_green_active
            }
          } else if(mapData[i].status === 1){
             /** 状态1为报警 */
            if(mapData[i].type === '101'){
              /** 101 摄像机 */
              marker = new AMap.Marker({
                position: pt,
                icon:cameraIcon_red,
                offset: new AMap.Pixel(-25, -40)
              })
              marker.Icon_original = cameraIcon_red
              marker.Icon_active = cameraIcon_red_active
            } else if(mapData[i].type === '103'){
              /** 103分析设备(服务器) */
              marker = new AMap.Marker({
                position: pt,
                icon:serverIcon_red,
                offset: new AMap.Pixel(-25, -40)
              })
              marker.Icon_original = serverIcon_red
              marker.Icon_active = serverIcon_red_active
            }
          } else if(mapData[i].status === -1){
            /** 状态-1为维修 */
            if(mapData[i].type === '101'){
              /** 101 摄像机 */
              marker = new AMap.Marker({
                position: pt,
                icon:cameraIcon_gray,
                offset: new AMap.Pixel(-25, -40)
              })
              marker.Icon_original = cameraIcon_gray
              marker.Icon_active = cameraIcon_gray_active
            } else if(mapData[i].type === '103'){
              /** 103分析设备(服务器) */
              marker = new AMap.Marker({
                position: pt,
                icon:serverIcon_gray,
                offset: new AMap.Pixel(-25, -40)
              })
              marker.Icon_original = serverIcon_gray
              marker.Icon_active = serverIcon_gray_active
            }
          }
          if(marker === undefined){
            return false
          }
          this.mapObject.add(marker)
          /** 设置标注点可拖拽 测试*/
          // marker.enableDragging()
 
          /** 将设备信息存储到marker中 */
          marker.index = i
          marker.data = mapData[i]
          marker.id = mapData[i].id
          marker.visibility = 'none'
 
          if (findInArrJson(mapData[i].id, this.deviceMarkers, 'id') === -1) {
            this.deviceMarkers.push(marker)
          }
          //是否点击摄像机
          let _this = this
          const opentextInfoWindow = async() => {
            /* 查询设备情况 */
            let typeArr = await getDeviceType()
            let typeName
            if(typeArr && typeArr.success && typeArr.data.length!==0){
              typeArr.data.forEach((item) => {
                if(item.value === marker.data.type){
                  typeName = item.name
                }
              })
            }
            if(marker.data && !marker.data.basePhoto){
              this.$set(marker.data,'basePhoto','/static/img/map/1111.jpg')
            }
            // let labelHtml = `<div class="pb10">
            //   <div style="height:70%;width:100%">
            //     <div id="dynamicallyPlayers" style="width:410px;height:287px;" class="flex-center">
            //       <div id="img" style="background-image: url(/httpImage/`+marker.data.basePhoto+`);width:100%;height:100%" class="img-icon"></div>
            //     </div>
            //     <div class="model-palyer-box" id="palyerBox">
            //       <i class="fas fa-play-circle model-palyer"></i>
            //     </div>
            //   </div>
            //   <div style="height:30%;" class="">
            //     <div class="flex-row-between">
            //       <div class="flex-row-left">
            //         <span>设备类型:${typeName}</span>
            //       </div>
            //       <div id="toDetails" class="flex-row-right">
            //         <a href="javascript:console.log('')">详情</a>
            //       </div>
            //     </div>
                
            //     <div class="flex-row-between">
            //       <div class="flex-row-left">
            //         <span>设备位置:${marker.data.address}</span>
            //       </div>
            //       <div class="flex-row-right">
            //         <i class="d-block fas fa-edit" id="toEdit" click=""></i>
            //       </div>
            //     </div>
                
            //   </div>
            //   <div style="width:100%;visibility:${marker.visibility};" class="flex-center">
            //     <button id="saveLnglat" type="button" class="btn btn-secondary btn-sm">保存坐标</button>
            //   </div>
            //   <style>
            //       .info-bg{
            //         background: #f8f8f8;
            //       }
            //       .model-palyer-box{
            //         position: absolute;
            //         width: 100%;
            //         height: 76%;
            //         left: 0;
            //         top: 0;
            //         text-align: center;
            //         display: flex;
            //         justify-content: center;
            //         align-items: center;
            //       }
            //       .model-palyer{
            //         font-size: 60px;
            //         cursor: pointer;
            //         color: #fff;
            //       }
            //     </style>  
            // </div>`
 
            //从检索复制过来的labelHtml
            let labelHtml =
              `<div class="pb10" style="background-color:white;border-style:solid; border-width:10px; border-color:white; border-bottom:0px">
                  <div style="height:70%;width:100%">
                      <div id="dynamicallyPlayers" style="width:410px;height:287px;" class="flex-center pr">
                          <div id="img" style="background-image: url(/httpImage/` +
                            marker.data.basePhoto +
                            `);width:100%;height:100%" class="img-icon">
                          </div>
                          <div class="model-palyer-box" id="palyerBox">
                            <i class="fas fa-play-circle model-palyer"></i>
                          </div>
                      </div>
                    <div class="pt5 pb10 pl10 pr10 info-bg">
                      <div class="flex-row-between">
                        <div class="flex-row-left">
                          <span>设备类型:${typeName}</span>
                        </div>
                      </div>
                      <div class="flex-row-between">
                        <div class="flex-row-left">
                          <span>设备名称:${marker.data.name}</span>
                        </div>
                      </div>
                      <div class="flex-row-between">
                        <div class="flex-row-left">
                          <span>设备位置:${marker.data.address}</span>
                        </div>
                        <div id="toDetails" class="flex-row-right ">
                          <a href="javascript:console.log('')"><i class="fa fa-list-alt f20 text-primary mr10" style="position:relative;top:5px;margin-right:13px;"></i>详情</a>
                        </div>
                      </div>
                      <div class="flex-row-between">
                        <div class="flex-row-left">
                          <span>设备状态:${marker.data.status === 0?'在线':'故障'}</span>
                        </div>
                        
                        <div class="flex-row-right ">
                          <a id="toEdit" href="javascript:console.log('')" style="display:${marker.visibility==='none'?'inline':'none'};"><i class="fas fa-edit f20 text-primary mr10" style="position:relative;top:5px;"></i>编辑</a>
                            <div style="width:100%;display:${marker.visibility};position:relative;top:5px" class="flex-center">
                              <button id="saveLnglat" type="button" class="btn btn-secondary btn-sm text-primary">保存坐标</button>
                            </div>
                        </div>
                      </div>
                    </div>
                  </div>
                <div style=' height: 0px;width: 100%;clear: both;text-align: center;'>
                  <img src='/static/img/sharp.png' style='position: relative;z-index: 104;'>
                </div>
                <style>
                  .info-bg{
                    background: #f8f8f8;
                  }
                  .model-palyer-box{
                    position: absolute;
                    width: 100%;
                    height: 100%;
                    left: 0;
                    top: 0;
                    text-align: center;
                    display: flex;
                    justify-content: center;
                    align-items: center;
                  }
                  .model-palyer{
                    font-size: 60px;
                    cursor: pointer;
                    color: #fff;
                  }
                </style>
              </div>`
            
            this.textInfoWindow.setContent(labelHtml)
            // marker.openInfoWindow(this.textInfoWindow)
            this.textInfoWindow.open(this.mapObject, marker.getPosition())
            console.log(document.getElementById('vxg_media_player1'),'this.textInfoWindow.getContent()') 
            // var playerId = 'vxg_media_player1'+this.indexPlayer
            // var player = vxgplayer(playerId)
            // player.play()
            setTimeout(() => {
                //添加事件
              // console.log(document.querySelector(
              //   `#${this.newMapId} #toDetails`
              // ),'看看docu是否渲染成功')
              if(document.querySelector(`#${this.newMapId} #img`) !== null){
                document.querySelector(
                  `#${this.newMapId} #toDetails`
                ).onclick = () => {
                  _this.$emit('toDetails', marker)
                }
                document.querySelector(
                  `#${this.newMapId} #toEdit`
                ).onclick = () => {
                  _this.setDrag(marker)
                }
                document.querySelector(
                  `#${this.newMapId} #saveLnglat`
                ).onclick = () => {
                  _this.saveLnglat(marker)
                }
                document.querySelector(
                  `#${this.newMapId} #dynamicallyPlayers`
                ).onclick = async () => {
                  /** 渲染弹框中的视频插件*/
                  let bigImg = await this.getNowBigImg(marker.id)
                  this.$set(marker.data,'basePhoto',bigImg)
                  console.log(marker.data,'=====更新图片===')
 
                  // console.log('能否走到这一步')
                  let parent=document.getElementById("dynamicallyPlayers");
                  let child=document.getElementById("img");
                  parent.removeChild(child);
                  this.indexPlayer++
                  var playerId = 'vxg_media_player1'+this.indexPlayer
                  var div = document.createElement('div')
                  div.setAttribute("id", playerId)
                  div.setAttribute("class", "vxgplayer")
                  // console.log(document.getElementById('toDetails'),'this.textInfoWindow.getContent()') 
                  var runtimePlayers = document.getElementById('dynamicallyPlayers')
                  runtimePlayers.appendChild(div)
                  console.log(marker.data.url,'vxgplayer')
                  vxgplayer(playerId, {
                          // url: 'rtsp://admin:a1234567@192.168.1.64:8000/h264/ch1/main/av_stream',
                          url: marker.data.url,
                          nmf_path: 'media_player.nmf',
                          nmf_src: '/static/vxgplayer-1.8.31/pnacl/Release/media_player.nmf',
                          latency: 300000,
                          width: "100%",
                          height: "100%",
                          aspect_ratio_mode: 1,
                          autohide: 3,
                          controls: true,
                          connection_timeout: 5000,
                          connection_udp: 0,
                          custom_digital_zoom: false
                  }).ready(function(){
                      console.log(' =>ready player '+playerId)
                      // 等后面拼好流地址后再进行赋值
                      // vxgplayer(playerId).src(mapData[i].url)
                      // vxgplayer(playerId).play()
                      console.log(' <=ready player '+playerId)
                  })
                }
              }
            }, 100);
            
          }
          /** 鼠标移动到标记点上的事件 */
          const mouseOve = async() => {
            console.log(this.textInfoWindow2.getIsOpen(),'getIsOpen')
            if(!this.textInfoWindow2.getIsOpen() && !this.textInfoWindow.getIsOpen()){
               /* 查询设备情况 */
                let typeArr = await getDeviceType()
                let typeName
                if(typeArr && typeArr.success && typeArr.data.length!==0){
                  typeArr.data.forEach((item) => {
                    if(item.value === marker.data.type){
                      typeName = item.name
                    }
                  })
                }
                let labelHtml = `<div class="pb10">
                  <div style="height:70%;width:100%">
                    <div id="dynamicallyPlayers2" style="width:380px;height:260px;padding:10px" class="flex-center">
                      <div style="background-image: url('/static/img/map/1111.jpg');width:100%;height:100%" class="img-icon"></div>
                    </div>
                  </div>
                  <div style="height:30%;" class="">
                    <div class="flex-row-between">
                      <div class="flex-row-left">
                        <span>设备类型:${typeName}</span>
                      </div>
                      <div id="toDetails" class="flex-row-right">
                        <a href="javascript:console.log('')">详情</a>
                      </div>
                    </div>
                    
                    <div class="flex-row-between">
                      <div class="flex-row-left">
                        <span>设备位置:${marker.data.address}</span>
                      </div>
                      <div class="flex-row-right">
                        <i class="d-block fas fa-edit" id="toEdit" click=""></i>
                      </div>
                    </div>
                    
                  </div>
                  <div style="width:100%" class="flex-center">
                    <button id="saveLnglat" type="button" class="btn btn-secondary btn-sm">保存坐标</button>
                  </div>  
                </div>`
                this.textInfoWindow2.setContent(labelHtml)
                // marker.openInfoWindow(this.textInfoWindow)
                this.textInfoWindow2.open(this.mapObject, marker.getPosition())
                // console.log(document.getElementById('vxg_media_player1'),'this.textInfoWindow.getContent()') 
                // var playerId = 'vxg_media_player1'+this.indexPlayer
                // var player = vxgplayer(playerId)
                // player.play()
                setTimeout(() => {
                  /** 渲染弹框中的视频插件*/
                  // console.log('能否走到这一步')
                  // this.indexPlayer++
                  // var playerId = 'vxg_media_player2'+this.indexPlayer
                  // var div = document.createElement('div')
                  // div.setAttribute("id", playerId)
                  // div.setAttribute("class", "vxgplayer")
                  // // console.log(document.getElementById('toDetails'),'this.textInfoWindow.getContent()') 
                  // var runtimePlayers = document.getElementById('dynamicallyPlayers2')
                  // runtimePlayers.appendChild(div)
                  // // console.log(vxgplayer,'vxgplayer')
                  // vxgplayer(playerId, {
                  //         url: 'rtsp://admin:a1234567@192.168.1.201:554/h264/ch1/main/av_stream',
                  //         nmf_path: 'media_player.nmf',
                  //         nmf_src: '/static/vxgplayer-1.8.31/pnacl/Release/media_player.nmf',
                  //         latency: 300000,
                  //         width: "330",
                  //         height: "230",
                  //         aspect_ratio_mode: 1,
                  //         autohide: 3,
                  //         controls: true,
                  //         connection_timeout: 5000,
                  //         connection_udp: 0,
                  //         custom_digital_zoom: false
                  // }).ready(function(){
                  //     // console.log(' =>ready player '+playerId)
                  //     // 等后面拼好流地址后再进行赋值
                  //     // vxgplayer(playerId).src(mapData[i].url)
                  //     // vxgplayer(playerId).play()
                  //     // console.log(' <=ready player '+playerId)
                  // })
                    //添加事件
                  // console.log(document.querySelector(
                  //   `#${this.newMapId} #toDetails2`
                  // ),'看看docu是否渲染成功')
                  if(document.querySelector(`#${this.newMapId} #toDetails2`)!== null){
                    document.querySelector(
                      `#${this.newMapId} #toDetails2`
                    ).onclick = () => {
                      _this.$emit('toDetails', marker)
                    }
                    document.querySelector(
                      `#${this.newMapId} #dynamicallyPlayers2`
                    ).onclick = () => {
                      //  _this.$emit('toDetails', marker)
                      this.opentextInfoWindow()
                    }
                    // document.querySelector(
                    //   `#${this.newMapId} #saveLnglat`
                    // ).onclick = () => {
                    //   _this.saveLnglat(marker)
                    // }
                  }
                }, 100);
              }
            }
           
          const closeInfoWin = async() =>{
            console.log('关闭InfoWin')
            this.textInfoWindow.close()
          }
 
          const toDetails = async(marker) =>{
            console.log(marker,'跳转详情页面')
            this.$emit('toDetails', marker.target)
          }
 
          const mouseUp = async(marker) =>{
            this.textInfoWindow.close()
          }
 
          marker.on('mouseover', opentextInfoWindow)
          marker.on('mouseout', closeInfoWin)
          marker.on('click',toDetails,marker)
          marker.on('dragstart',mouseUp,marker)
          marker.on('dragend',opentextInfoWindow)
          // AMap.event.addListener(marker, 'mousemove', opentextInfoWindow)
          // AMap.event.addListener(marker,'mouseout',closeInfoWin)
          // AMap.event.addListener(marker, 'click', toDetails(marker))
          // AMap.event.addListenerOnce(marker, 'mousemove', mouseOve)
        }
      }
    },
    /** 设置高亮 */
    setActiveDeviceMarkers(arr){
      let idArr = arr || []
      let markers = this.deviceMarkers || []
 
      /** 在设置高亮之前先把之前设置的高亮去掉 */
      if (idArr.length === 0) {
        return false
      }
 
      let activeDevices = []
      //遍历id查找高亮
      idArr.forEach((idItem, index) => {
        for (let iteam of markers) {
          if (iteam.id == idItem.id) {
            activeDevices.push(iteam)
            //iteam.setIcon(iteam.Icon_active);
            //移动到第0个的位置
            if (index === 0) {
              this.amapPto(iteam.data.longitude, iteam.data.latitude)
            }
          } else {
            // console.log(iteam,'iteam ')
            if(iteam.data.status === 'online'){
              iteam.setIcon(iteam.Icon_online)
              iteam.setAnimation('AMAP_ANIMATION_NONE')
            } else if(iteam.data.status === 'unOnline'){
              iteam.setIcon(iteam.Icon_unOnline)
              iteam.setAnimation('AMAP_ANIMATION_NONE')
            }
          }
        }
      })
      //设置高亮图标
      for (let val of activeDevices) {
        val.setIcon(val.Icon_active)
        // 设置标记点跳动
        // val.setAnimation('AMAP_ANIMATION_BOUNCE')
        // val.setOffset(new AMap.Pixel(-47, -80))
        val.setOffset(new AMap.Pixel(-25, -40))
      }
    },
    /** 取消高亮 */
    removeActiveDeviceMarkers(){
      let markers = this.deviceMarkers || []
      for (let iteam of markers) {
        // if(iteam.data.status === 0){
        //   iteam.setIcon(iteam.Icon_original)
        // } else if(iteam.data.status === 1){
        //   iteam.setIcon(iteam.Icon_unOnline)
        // }
        iteam.setIcon(iteam.Icon_original)
        iteam.setOffset(new AMap.Pixel(-25, -40))
        iteam.setAnimation('AMAP_ANIMATION_NONE')
      }
    },
    /** 监听信息窗口打开 */
    listenInfoWin(){
      // console.log(document.getElementById('dynamicallyPlayers'),'this.textInfoWindow.getContent()') 
    },
     // 地图中监听鼠标松开事件,获取松开的经纬度
    listenMouseUp(e){
      // let point = new AMap.LngLat(e.point.lng,e.point.lat)
      console.log(e,'鼠标在这里松开')
      // this.$emit('getPoint',point)
    },
    listenMouseOve(e){
      // let point = new BMap.Point(e.point.lng,e.point.lat)
      // console.log(e,'鼠标在这里移动')
      this.point = {}
      let pt = e.lnglat
      if(Object.keys(pt).length!==0){
        this.point = pt
      }
      console.log(this.point,'this.point')
    },
    listenMouseDown(e){
      // let point = new BMap.Point(e.point.lng,e.point.lat)
      console.log(e,'鼠标在这里按下鼠标')
    },
    /** 获取拖拽点 */
    receveLnglat(data){
      console.log(data,'================')
      AMap.event.addListenerOnce(this.mapObject, 'mousemove', this.listenMouseOve)
      setTimeout(() => {
        if(Object.keys(this.point).length!==0){
          data.longitude = this.point.lng
          data.latitude = this.point.lat
          let arr = []
          arr.push(data)
          this.amapCreateMarker(arr)
          this.$nextTick(()=>{
            this.deviceMarkers.forEach((item)=>{
              if(item.data.id === data.id){
                this.saveLnglat(item)
              }
            })
          })
          console.log(data,' 将要打印的点')
        }
      }, 100);
      
    },
    /** 定义鼠标移动到标记点的回调 */
    removeToMarker(data){
      console.log(data,'鼠标移动的回调函数')
    },
    /** 设置拖拽 */
    setDrag(data){
      // console.log(data,'设置拖拽')
      data.setDraggable(true)
      this.$toast({
        type:'success',
        message:'您现在可以对该设备进行移动了,别忘了保存坐标!'
      })
      this.$set(data,'visibility','inline')
    },
    /** 移动后保存坐标 */
    saveLnglat(data){
      // console.log(data,'保存拖拽后的marker')
      data.setDraggable(false)
      this.$set(data,'visibility','none')
      this.$emit('updatePos',data)
    },
    /** 查询设备类型 */
    async getDeviceType(){
      let res = await getDeviceType()
      if(res&&res.success){
        return res.data
      }
    },
    /** 关闭弹框 */
    closeInfoWin(){
      console.log('关闭InfoWin2')
      this.textInfoWindow2.close()
    },
    /** 获取品牌 */
    async getDeviceBrand() {
      const res = await getDeviceBrand()
      this.deviceBrandList =
        res.success && res.code === 200 && res.data ? res.data : []
    },
    // 根据字典模版 拼接rtsp流地址
    // urlTemplate: 'rtsp://[username]:[password]@[ip]:[port]/cam/realmonitor?channel=1&subtype=0'
    getvideoUrl(data) {
      // console.log(!this.deviceBrandList.length,'拼接流地址data')
      if (!this.deviceBrandList.length) {
        return ''
      }
      // console.log(data,'拼接流地址data')
      const setting = ['username', 'password', 'ip', 'port']
      const itemArr = this.deviceBrandList.filter(
        item => item.value === data.brand
      )
      if (itemArr.length === 1) {
        let urlTemplate =
          itemArr[0] && itemArr[0].urlTemplate ? itemArr[0].urlTemplate : ''
        setting.map(val => {
          urlTemplate = urlTemplate.replace(
            `[${val}]`,
            data[val] ? data[val] : ''
          )
        })
        return urlTemplate
      }
      return ''
    }
  },
  mounted() {
    this.InitMap()
  },
  created() {
    // this.InitMap()
  }
}
</script>
<style>
.map {
  width: 100%;
  height: 100%;
}
.info-top {
    position: relative;
    background: none repeat scroll 0 0 #F9F9F9;
    border-bottom: 1px solid #CCC;
    border-radius: 5px 5px 0 0;
}
 
.amap-overlays {
  z-index: 50;
  cursor: default;
}
</style>