liuxiaolong
2019-05-06 3e0536f508aad49f743e7bfabca34e3980a1b6e2
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
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
<template>
  <div :id="newMapId" class="map"></div>
</template>
<script>
/* eslint-disable */
import { findInArrJson } from '@/components/common/util.js'
import { getDeviceType, getDeviceBrand } from '@/server/home.js'
import {
  getcameraRecord,
  queryCameraCount,
  getDevSnapshot
} from '@/server/map.js'
import { Row, Col } from 'element-ui'
import speciaButton from '@/components/specialButton/speciaButton.vue'
import { WebVideo } from '../../WebVideo/WebVideo.js'
export default {
  components: {
    elRow: Row,
    elCol: Col
  },
  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: [],
      /** 轨迹对象 */
      PathSimplifierObj: {},
      /** 当前的imgId */
      iconImgId: ''
    }
  },
  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
      })
      // map.on('complete',function(){
      //   console.log("地图加载完成!")
      // })
      /** 添加地图插件 */
      AMap.plugin(['AMap.ToolBar'], function() {
        map.addControl(
          new AMap.ToolBar({
            // 简易缩放模式,默认为 false
            liteStyle: true
          })
        )
      })
      /** 获取品牌 */
      // this.getDeviceBrand()
      // AMap.event.addListener(map, 'mousedown', this.listenMouseDown)
      // AMap.event.addListener(map, 'mousemove', this.listenMouseOve)
      // AMap.event.addListener(map, 'mouseup', this.listenMouseUp)
      // debugger
      this.mapObject = map
      //创建全局弹窗
      this.textInfoWindow = new AMap.InfoWindow({
        isCustom: true,
        autoMove: true,
        closeWhenClickMap: true,
        size: new AMap.Size(430, 380),
        offset: new AMap.Pixel(25, -25)
      })
      this.textInfoWindow2 = new AMap.InfoWindow({
        isCustomL: true,
        autoMove: false,
        closeWhenClickMap: true,
        size: new AMap.Size(430, 410),
        offset: new AMap.Pixel(0, -20)
      })
 
      /** 监听信息窗口的打开事件 */
      // this.textInfoWindow.on('open',this.listenInfoWin)
      // this.textInfoWindow.on('mouseover',this.removeToMarker(this.textInfoWindow))
    },
    amapPto(lng, lat) {
      if (lng && lat) {
        this.mapObject.panTo(new AMap.LngLat(lng, lat))
      }
    },
    /* by mcdowell 2019-02-22 */
    async getCameraMarkersCount(arr, isids) {
      let mapData = arr || []
      const mapDataId = isids ? mapData : mapData.map(item => item.id)
      const sear = JSON.parse(localStorage.getItem('sear'))
      let res = await queryCameraCount({
        reqNumList: mapDataId,
        startDate: sear.startDate,
        endDate: sear.endDate
      })
      let list = []
      if (res && res.success && res.data && res.data.equList) {
        list = res.data.equList
        list = list.map(item => ({ [item.devId]: item.alarmCount }))
      }
      return list
    },
    /** 设备marker标记点 */
    async 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
      }
      // 获取全部设备数值
      const markersCounts = await this.getCameraMarkersCount(mapData)
      console.log(markersCounts, 'markersCounts')
      /** 摄像头全局对象 */
      let cameraMarkers = []
      /** 渲染marker */
      for (let i = 0; i < mapData.length; i++) {
        if (
          mapData[i].longitude &&
          mapData[i].latitude &&
          mapData[i].longitude !== 'None' &&
          mapData[i].latitude !== 'None'
        ) {
          /* 禁止多次调用 */
          /* let sear = JSON.parse(localStorage.getItem('sear'))
          let res = await queryCameraCount({
            reqNumList: [mapData[i].id],
            startDate: sear.startDate,
            endDate: sear.endDate
          })
          if (res && res.success) {
            if (res.data && res.data.total) {
              if (res.data.total !== 0) {
                this.$set(mapData[i], 'isAlarm', true)
                this.$set(mapData[i], 'alarmNum', res.data.total)
              } else {
                this.$set(mapData[i], 'isAlarm', false)
                this.$set(mapData[i], 'alarmNum', res.data.total)
              }
            }
          } */
          /**
           * 匹配mark警报数量
           *  by mcdowell
           *  */
          this.$set(mapData[i], 'isAlarm', false)
          this.$set(mapData[i], 'alarmNum', 0)
          markersCounts.map(item => {
            let num = parseInt(item[mapData[i].id])
            if (mapData[i].id && !isNaN(num) && num > -1) {
              this.$set(mapData[i], 'isAlarm', true)
              this.$set(mapData[i], 'alarmNum', num)
            }
          })
          /* 匹配mark警报数量 end */
          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)
          })
          /** 使用SimpleMarker */
          // AMapUI.loadUI(['overlay/SimpleMarker'], function(SimpleMarker) {
          //   /** 判断标记点的相关状态,确定用什么icon */
 
          //   //创建SimpleMarker实例
          //   new SimpleMarker({
 
          //       innerHTML: '<i>B</i>',
          //       style: {
          //         color: '#fff'
          //       },
          //       //图标主题
          //       iconTheme: 'default',
          //       //背景图标样式
          //       // iconStyle: '/static/img/icon/green_camer.png',
          //       icon:icon,
          //       //...其他Marker选项...,不包括content
          //       map: map,
          //       position: pt,
          //       label:{
          //         content:'<div style="color:red;">5</div>',
          //         offset:new AMap.Pixel(30,-20)
          //       }
          //   })
          // })
          /** end */
          let marker = null
          // console.log(i,'mapData[i]====',mapData[i].status)
          if (mapData[i].status === 0) {
            /** 状态0为正常 */
            if (mapData[i].type === '101') {
              if (mapData[i].subType === '10102') {
                /** 101 摄像机 */
                marker = new AMap.Marker({
                  position: pt
                  // offset: new AMap.Pixel(-25, -40)
                })
                marker.Icon_original = cameraIcon_green
                marker.Icon_alarm = cameraIcon_red
                marker.Icon_active = cameraIcon_green_active
                marker.type = '101'
              } else if (mapData[i].subType === '10101') {
                /** 103分析设备(服务器) */
                marker = new AMap.Marker({
                  position: pt
                  // icon:serverIcon_green,
                  // offset: new AMap.Pixel(-25, -40)
                })
                marker.Icon_original = serverIcon_green
                marker.Icon_alarm = serverIcon_red
                marker.Icon_active = serverIcon_green_active
                marker.type = '103'
              }
              marker.status = 0
            }
          } 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_green = cameraIcon_green
              marker.Icon_active = cameraIcon_red_active
              marker.type = '101'
            } 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_green = serverIcon_green
              marker.Icon_active = serverIcon_red_active
              marker.type = '103'
            }
            marker.status = 1
          } 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_green = cameraIcon_green
              marker.Icon_active = cameraIcon_gray_active
              marker.type = '101'
            } 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_green = serverIcon_green
              marker.Icon_active = serverIcon_gray_active
              marker.type = '103'
            }
            marker.status = -1
          }
          if (marker === undefined) {
            return
          }
          /** 判断marker中是否有报警记录 */
          if (mapData[i].isAlarm) {
            marker.setIcon(marker.Icon_alarm)
            marker.status = 1
            marker.setLabel({
              content: `<div style="color:#fff;background-color:red;">${
                mapData[i].alarmNum
              }</div>`,
              offset: new AMap.Pixel(25, -10)
            })
          }
          marker.isActive = false
          marker.Trajectory = false
          /** 将设备信息存储到marker中 */
          marker.index = i
          marker.data = mapData[i]
          marker.id = mapData[i].id
          marker.visibility = 'hidden'
 
          // marker.setOffset(new AMap.Pixel(-35, -50))
          this.setContent(marker)
          this.mapObject.add(marker)
 
          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
                }
              })
            }
            console.log(marker.id, ' marker.data')
            // let bigImg = await this.getNowBigImg(marker.id)
            console.log(marker.data.basePhoto, 'bigImg')
            let markerImgUrl = ''
            if(marker.data && !marker.data.basePhoto){
              // this.$set(marker.data,'basePhoto','/static/img/map/1111.jpg')
              markerImgUrl = '/static/img/map/1111.jpg'
            }else{
              markerImgUrl = '/httpImage/'+marker.data.basePhoto
            }
            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(` +
                            markerImgUrl +
                            `);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="mt10 pt20 pb10 pl10 pr10 info-bg">
                      <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 pt10">
                          <span>设备位置:${marker.data.address}</span>
                        </div>
                        <div id="toDetails" class="flex-row-right ">
                          <a href="javascript:console.log('')"><i class="fa fa-list-alt f25 text-primary mr10" style="position:relative;top:5px;"></i>详情</a>
                        </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()')
            setTimeout(() => {
              //添加事件
              if (document.querySelector(`#${this.newMapId} #img`) !== null) {
                document.querySelector(
                  `#${this.newMapId} #toDetails`
                ).onclick = () => {
                  closeInfoWin()
                  _this.$emit('toDetails', { ...marker })
                }
                document.querySelector(
                  `#${this.newMapId} #dynamicallyPlayers`
                ).onclick = async () => {
                  /** 渲染弹框中的视频插件*/
                  console.log('能否走到这一步1')
                  let parent = document.getElementById('dynamicallyPlayers')
                  let child = document.getElementById('img')
                  let child2 = document.getElementById('vxg_media_player1')
                  let child3 = document.getElementById('palyerBox')
                  if (child3) {
                    parent.removeChild(child3)
                  }
                  if (child2 !== null) {
                    parent.removeChild(child2)
                  }
                  parent.removeChild(child)
 
                  let bigImg = await this.getNowBigImg(marker.id)
                  this.$set(marker.data,'basePhoto',bigImg)
                  console.log(marker.data,'=====更新图片===')
 
                  var playerId = 'vxg_media_player1'
                  var div = document.createElement('div')
                  div.setAttribute('id', playerId)
                  div.setAttribute('style', 'width:100%;height:100%')
                  parent.appendChild(div)
                  /** 采用海康的视频插件 */
                  let videoParams = {
                    deviceport: marker.data.port,
                    // rtspport:marker.data.rtspport,
                    rtspport: '554',
                    ip: marker.data.ip,
                    // port:marker.data.serverport,
                    port: '80',
                    username: marker.data.username,
                    // password: marker.data.password,
                    password: 'a1234567',
                    domId: playerId
                  }
                  console.log(marker.data, 'AMap videoParams')
                  const webVideo = new WebVideo(videoParams)
                  webVideo.init()
                  this.$nextTick(() => {
                    webVideo.clickLogin()
                  })
                }
              }
            }, 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())
              setTimeout(() => {
                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 () => {
            this.textInfoWindow.close()
          }
 
          const toDetails = async marker => {
            this.$emit('toDetails', marker.target)
          }
          marker.on('mouseover', opentextInfoWindow)
          marker.on('mouseout', closeInfoWin)
          marker.on('click', toDetails, marker)
          marker.on('dragging', opentextInfoWindow)
          // this.$nextTick(()=>{
          //   if(document.querySelector(`#${this.newMapId} #${this.iconImgId}`)!== null){
          //     console.log('iconImgId')
          //     document.querySelector(
          //       `#${this.newMapId} #${this.iconImgId}`
          //     ).onmouseover = () =>{
          //       console.log(event,'event')
          //     }
          //   }
          // })
        }
      }
    },
    async setDeviceMarkersAlarm(arr) {
      let idArr = arr || []
      let markers = this.deviceMarkers || []
 
      idArr.map(item => {
        for (let iteam of markers) {
          if (iteam.id === item.id) {
            iteam.status = item.status
          }
          // this.setContent(iteam)
        }
      })
 
      // // 获取全部设备数值
      const markersCounts = await this.getCameraMarkersCount(idArr, false)
      console.log(markersCounts, 'markersCounts')
      for (let iteam of markers) {
        this.$set(iteam, 'alarmNum', 0)
        // iteam.setLabel(null)
        markersCounts.map(item => {
          if(item.hasOwnProperty(iteam.id)){
            let num = parseInt(item[iteam.id])
            if (iteam.id && !isNaN(num) && num > -1) {
              iteam.setLabel({
                content: `<div style="color:#fff;background-color:red;">${num}</div>`,
                offset: new AMap.Pixel(25, 0)
              })
            }
          }
        })
      }
    },
    /** 设置高亮 */
    setActiveDeviceMarkers(arr, message) {
      let idArr = arr || []
      let markers = this.deviceMarkers || []
 
      /** 在设置高亮之前先把之前设置的高亮去掉 */
      if (idArr.length === 0) {
        return false
      }
      let activeDevices = []
      console.info(markers, 'markers')
      //遍历id查找高亮
      idArr.forEach((idItem, index) => {
        for (let iteam of markers) {
          // if (iteam.data && iteam.data.id === idItem.id) {
            console.log(idItem.id,'idItem.id',iteam.id,'iteam.id')
          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')
            }
          }
        }
      })
      console.log(activeDevices, 'activeDevices')
      if (activeDevices.length !== 0) {
        //设置高亮图标
        for (let val of activeDevices) {
          // val.setIcon(val.Icon_active)
          // 设置标记点跳动
          // val.setAnimation('AMAP_ANIMATION_BOUNCE')
          // val.setOffset(new AMap.Pixel(-47, -80))
          /** 通过设置content设置高亮 */
          val.isActive = true
          this.setContent(val)
          // val.setOffset(new AMap.Pixel(-47, -80))
        }
      }
      //  else if (!message) {
      //   this.$toast({
      //     type: 'warning',
      //     message: '地图上暂无此设备!'
      //   })
      // }
    },
    /** 取消高亮 */
    removeActiveDeviceMarkers() {
      let markers = this.deviceMarkers || []
      for (let iteam of this.deviceMarkers) {
        this.$set(iteam, 'Trajectory', false)
        // iteam.setIcon(iteam.Icon_original)
        // iteam.setOffset(new AMap.Pixel(-35, -50))
        // iteam.setAnimation('AMAP_ANIMATION_NONE')
        // console.log(iteam.he,'iteam.he',iteam.he.content)
        iteam.isActive = false
        console.log(iteam, 'iteam', iteam.isActive)
        iteam.setzIndex(100)
        this.setContent(iteam)
      }
    },
    /** 监听信息窗口打开 */
    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', 'visible')
    },
    /** 移动后保存坐标 */
    saveLnglat(data) {
      // console.log(data,'保存拖拽后的marker')
      data.setDraggable(false)
      this.$set(data, 'visibility', 'hidden')
      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 ''
    },
    /** 在地图上画轨迹线 */
    drawLine(data) {
      console.log(data, '在地图上画轨迹线')
      // 霍文博添加,为了消除上次的轨迹
      if (window.pathSimplifierIns) {
        window.pathSimplifierIns.setData([
          {
            name: '轨迹',
            path: []
          }
        ])
      }
      const map = this.mapObject
      /** 判断undefinde */
      // console.log(data,'===============')
      if (data === undefined) {
        return false
      }
      /** 判断数据为空 */
      if (
        data &&
        data.result.path &&
        data.result.path.path &&
        data.result.path.path.length === 0
      ) {
        return false
      }
      /** 判断是否有smallPhotoPath */
      /** 路径数据 */
      let path = data.result.path.path
 
      /** 使用简单路径 */
      AMapUI.load(['ui/misc/PathSimplifier', 'lib/$'], function(
        PathSimplifier,
        $
      ) {
        if (!PathSimplifier.supportCanvas) {
          alert('当前环境不支持 Canvas!')
          return
        }
        let pathSimplifierIns = new PathSimplifier({
          zIndex: 100,
          //autoSetFitView:false,
          map: map, //所属的地图实例
          getPath: function(pathData, pathIndex) {
            return pathData.path
          },
          getHoverTitle: function(pathData, pathIndex, pointIndex) {
            if (pointIndex >= 0) {
              //point
              return (
                pathData.name +
                ',点:' +
                pointIndex +
                '/' +
                pathData.path.length
              )
            }
            return pathData.name + ',点数量' + pathData.path.length
          },
          renderOptions: {
            renderAllPointsIfNumberBelow: 100 //绘制路线节点,如不需要可设置为-1
          }
        })
        window.pathSimplifierIns = pathSimplifierIns
        //设置数据
        pathSimplifierIns.setData([
          {
            name: '轨迹',
            path: path
          }
        ])
        //对第一条线路(即索引 0)创建一个巡航器
        let navg1 = pathSimplifierIns.createPathNavigator(0, {
          loop: true, //循环播放
          speed: 1000 //巡航速度,单位千米/小时
        })
        navg1.start()
      })
      /** 设备数据集合 */
      let arr = data.result.path.locusList
      let markers = this.deviceMarkers || []
      let activeDevices = []
      // console.log(data,'data')
      arr.forEach((i, index) => {
        for (let item of markers) {
          if (item.id === i.videoReqNum) {
            activeDevices.push(item)
          }
        }
      })
      // 霍文博添加,为了不显示多余的头像
      for (let val of activeDevices) {
        val.setContent('')
      }
      console.log(arr, 'arr', activeDevices)
      for (let val of activeDevices) {
        console.log(val, 'activeDevices')
        let sumNum = data.result.path.sumNum
        let count = 0
        for (let i of sumNum) {
          if (i.devId === val.id) {
            count = i.decCount
            break
          }
        }
        /** 根据设备状态确定图片 */
        let picStr = null
        if (val.data.type === '101') {
          if (val.data.subType === '10101') {
            if (val.data.isAlarm) {
              picStr = '/static/img/icon/red_server_active.gif'
            } else {
              picStr = '/static/img/icon/green_server_active.gif'
            }
          } else if (val.data.subType === '10102') {
            if (val.data.isAlarm) {
              picStr = '/static/img/icon/red_camer_active.gif'
            } else {
              picStr = '/static/img/icon/green_camer_active.gif'
            }
          }
        }
        this.$set(val, 'Trajectory', true)
        this.$set(val, 'allData', data)
        /** 设置标记的Content */
        let markerContent = `
            <div>
              <div style="position:absolute;top:5px;left:-76px;">
                <img src="${picStr}" style="width:48px;height:48px;" />
              </div>
              <div>
                <img class="map-img" src="/httpImage/${
                  val.allData.result.param.path
                }" width="40px" height="40px"/>
              </div>
              <div class="smdiv">${count}</div>
            </div>
          `
        /*  */
        val.setLabel({
          content: `<div style="color:#fff;background-color:red;">${
            val.data.alarmNum
          }</div>`,
          offset: new AMap.Pixel(25, 38)
        })
        val.setzIndex(101)
        val.setContent(markerContent)
        // val.setOffset(new AMap.Pixel(-25, -114.5))
        val.setOffset(new AMap.Pixel(-10, -78))
      }
    },
    /** 设置正常的content */
    setContent(marker) {
      if (marker === undefined) {
        return false
      }
      let markerContent = ''
      let id = 'iconImgId' + Math.floor(Math.random() * 10000 + 1)
      if (!marker.data.isAlarm) {
        if (marker.type === '101') {
          if (marker.isActive) {
            /** 设置标记的Content */
            markerContent = `
              <div style="position:absolute;top:-26px;left:-60px;width:0px;height:0px;">
                <img src="/static/img/icon/green_camer_active.gif" />
              </div>
            `
          } else {
            /** 设置标记的Content */
            markerContent = `
              <div style="position:absolute;top:-12px;left:-58px;width:0px;height:0px;">
                <img src="/static/img/icon/green_camer.png" style="width:36px;height:36px;"/>
              </div>
            `
          }
        } else if (marker.type === '103') {
          if (marker.isActive) {
            /** 设置标记的Content */
            markerContent = `
              <div style="position:absolute;top:-26px;left:-60px;width:0px;height:0px;">
                <img id="${id}" src="/static/img/icon/green_server_active.gif"  />
              </div>
            `
          } else {
            /** 设置标记的Content */
            markerContent = `
              <div style="position:absolute;top:-12px;left:-58px;width:0px;height:0px;">
                <img id="${id}" src="/static/img/icon/green_server.png" style="width:36px;height:36px;" />
              </div>
            `
          }
        }
      } else if (marker.data.isAlarm) {
        if (marker.type === '101') {
          if (marker.isActive) {
            /** 设置标记的Content */
            markerContent = `
              <div style="position:absolute;top:-28px;left:-60px;width:0px;height:0px;">
                <img id="${id}" src="/static/img/icon/red_camer_active.gif" />
              </div>
            `
          } else {
            /** 设置标记的Content */
            markerContent = `
              <div style="position:absolute;top:-12px;left:-58px;width:0px;height:0px;">
                <img id="${id}" src="/static/img/icon/red_camer.png" style="width:36px;height:36px;" />
              </div>
            `
          }
        } else if (marker.type === '103') {
          if (marker.isActive) {
            /** 设置标记的Content */
            markerContent = `
              <div style="position:absolute;top:-26px;left:-60px;width:0px;height:0px;">
                <img id="${id}" src="/static/img/icon/red_server_active.gif" />
              </div>
            `
          } else {
            /** 设置标记的Content */
            markerContent = `
              <div style="position:absolute;top:-12px;left:-58px;width:0px;height:0px;">
                <img id="${id}" src="/static/img/icon/red_server.png" style="width:36px;height:36px;" />
              </div>
            `
          }
        }
      } else if (marker.status === -1) {
        if (marker.type === '101') {
          if (marker.isActive) {
            /** 设置标记的Content */
            markerContent = `
              <div style="position:absolute;top:-26px;left:-60px;width:0px;height:0px;">
                <img id="${id}" src="/static/img/icon/gray_camer_active.gif" />
              </div>
            `
          } else {
            /** 设置标记的Content */
            markerContent = `
              <div style="position:absolute;top:-12px;left:-58px;width:0px;height:0px;">
                <img id="${id}" src="/static/img/icon/gray_camer.png" style="width:36px;height:36px;" />
              </div>
            `
          }
        } else if (marker.type === '103') {
          if (marker.isActive) {
            /** 设置标记的Content */
            markerContent = `
              <div style="position:absolute;top:-26px;left:-60px;width:0px;height:0px;">
                <img id="${id}" src="/static/img/icon/gray_server_active.gif" />
              </div>
            `
          } else {
            /** 设置标记的Content */
            markerContent = `
              <div style="position:absolute;top:-12px;left:-58px;width:0px;height:0px;">
                <img id="${id}" src="/static/img/icon/gray_server.png" style="width:36px;height:36px;" />
              </div>
            `
          }
        }
      }
      this.iconImgId = id
      marker.setContent(markerContent)
    },
    /** 设置正常的content */
    setRedContent(marker) {
      if (marker === undefined) {
        return false
      }
      /** 设置标记的Content */
      let markerContent = `
        <div>
          <div style="position:absolute;top:-12px;left:-58px;width:36px;height:36px;">
            <img src="/static/img/icon/red_camer.png" />
          </div>
        </div>
      `
      marker.setContent(markerContent)
    },
    /** 设置鼠标滑动的弹框 */
    async opentextInfoWindow(marker) {
      /* 查询设备情况 */
      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="dynamicallyPlayers" style="width:410px;height:287px;" class="flex-center">
            <div id="img" 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>设备名称:${marker.data.name}</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>
        </div>
      </div>`
 
      this.textInfoWindow.setContent(labelHtml)
      this.textInfoWindow.open(this.mapObject, marker.getPosition())
      console.log(
        document.getElementById('vxg_media_player1'),
        'this.textInfoWindow.getContent()'
      )
      setTimeout(() => {
        //添加事件
        if (document.querySelector(`#${this.newMapId} #img`) !== null) {
          document.querySelector(
            `#${this.newMapId} #toDetails`
          ).onclick = () => {
            _this.$emit('toDetails', marker)
          }
          document.querySelector(`#${this.newMapId} #img`).onclick = () => {
            /** 渲染弹框中的视频插件*/
            console.log('能否走到这一步2')
            let parent = document.getElementById('dynamicallyPlayers')
            let child = document.getElementById('img')
            let child3 = document.getElementById('palyerBox')
            if (child3) {
              parent.removeChild(child3)
            }
            parent.removeChild(child)
            this.indexPlayer++
            var playerId = 'vxg_media_player1' + this.indexPlayer
            var div = document.createElement('div')
            div.setAttribute('id', playerId)
            div.setAttribute('style', 'width:100%;height:100%')
            parent.appendChild(div)
            /** 采用海康的视频插件 */
            let videoParams = {
              deviceport: marker.data.port,
              rtspport: '554',
              ip: marker.data.ip,
              port: '80',
              username: marker.data.username,
              password: marker.data.password,
              domId: playerId
            }
            console.log(videoParams, 'AMap videoParams')
            const webVideo = new WebVideo(videoParams)
            webVideo.init()
            this.$nextTick(() => {
              webVideo.clickLogin()
            })
          }
        }
      }, 100)
    }
  },
  mounted() {
    this.InitMap()
  },
  created() {
    // this.InitMap()
  }
}
</script>
<style lang="scss" scoped>
.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;
}
.number {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background-color: aquamarine;
}
.btn-circle2 {
  text-align: center;
  position: absolute;
  top: 52%;
  left: -12%;
}
.imgC {
  position: absolute;
  left: -50%;
  top: 22%;
}
.smdiv {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background-color: rgb(89, 34, 238);
  color: red;
  position: absolute;
  top: 105px;
  left: 27px;
}
.radius {
  width: 40px;
  height: 40px;
  background-color: aqua;
  border-radius: 50%;
}
 
.img1 {
  position: absolute;
  left: -55%;
  top: -33%;
}
 
.img2 {
  position: absolute;
  top: -44%;
  left: -185%;
}
.amap-overlays {
  z-index: 50;
  cursor: default;
}
</style>