yichenxi
2022-12-12 98e00421c572ef955c2eca5445800096e215b779
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
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
<template>
  <div class="main_body">
    <el-container style="height: 100%">
      <el-aside
        v-if="this.$store.state.aside"
        width="300px"
        style="background-color: rgb(238, 241, 246); padding-top: 10px"
      >
        <span
          style="
            font-size: 13px;
            padding-left: 10px;
            font-weight: 500;
            color: rgb(64, 158, 255);
          "
          >走航车设备</span
        >
        <el-menu style="margin-top: 10px">
          <el-menu-item
            v-for="(item, index) in defaultData"
            :key="index"
            style="
              display: flex;
              justify-content: space-between;
              align-items: center;
              padding-right: 0;
              border-bottom: 1px solid #eee;
            "
            :index="(index + 1 + '-' + index + 1).toString()"
            @click="changeCarData(item)"
          >
            <span>{{ item.name }}</span>
            <i
              style="
                vertical-align: -2.5px;
                font-size: 20px;
                margin-right: 10px;
                margin-left: auto;
              "
              class="iconfont iconfaxianzuobiao"
              @click="deviceDetail(item.mac, null, item, 0)"
            />
            <!--            @click="deviceDetail('p5dnd7a0245390',null,item,0)"-->
          </el-menu-item>
        </el-menu>
      </el-aside>
      <el-dialog> </el-dialog>
      <el-container style="position: relative">
        <div class="carTop">
          <span style="float: left; margin: 1px 10px 0 0">
            <el-button
              size="medium"
              type="primary"
              icon="el-icon-setting"
              @click="dialogFormVisible = true"
              >6参设定</el-button
            >
          </span>
          <span
            v-for="(item, index) in snesorParams"
            :key="index"
            class="left"
            :class="{ click: changeColor == index }"
            @click="changeCode(index)"
            >{{ item }}
          </span>
          <span
            v-for="(item, index) in viewOptions"
            :key="index + '-only'"
            class="right"
            :class="{ click: changeColor1 == index }"
            @click="changeCode1(index)"
            >{{ item }}
          </span>
          <span v-if="webSocketView" style="float: right; margin: 2px 10px 0 0">
            <el-button size="medium" type="primary" @click="wsStart()"
              >开启实时</el-button
            >
          </span>
          <!--           <el-date-picker
                      v-if="historyView"
                      v-model="dateValue"
                      value-format="yyyy-MM-dd"
                      style="float:right;margin-right: 10px;line-height: 40px;"
                      align="right"
                      type="date"
                      placeholder="选择日期"
                      :picker-options="pickerOptions"
                      @change="dateChange"
                    />-->
          <!-- 选择时间段 -->
          <!--          <el-time-picker-->
          <!--              :disabled="isDisTime"-->
          <!--              style="float:right;width: 210px"-->
          <!--              is-range-->
          <!--              v-model="timeValue"-->
          <!--              @blur="blurChange"-->
          <!--              range-separator="至"-->
          <!--              start-placeholder="开始时间"-->
          <!--              end-placeholder="结束时间"-->
          <!--              placeholder="选择时间范围">-->
          <!--          </el-time-picker>-->
          <!-- 历史日期选择下拉框 -->
          <!--          <el-select v-if="historyView" v-model="dateValue" placeholder="选择日期" style="float:right;line-height:40px;margin-right:10px;width:140px" @change="dateChange">-->
          <!--            <el-option-->
          <!--              v-for="item in isDataList"-->
          <!--              :key="item.value"-->
          <!--              :label="item.label"-->
          <!--              :value="item.value"-->
          <!--              @click.native="dataChangeClick"-->
          <!--            />-->
          <!--          </el-select>-->
 
          <el-button
            type="primary"
            size="small"
            style="margin-left: 1.5rem"
            @click="insertL"
            >添加</el-button
          >
          <div class="insLu">
            <el-upload
              class="upload-demo"
              ref="upload"
              action=""
              :on-change="handleChange"
              :on-remove="handleRemove"
              :file-list="fileList"
              :auto-upload="false"
              :limit="1"
            >
              <el-button slot="trigger" size="small" type="primary"
                >选取文件</el-button
              >
              <div slot="tip" class="el-upload__tip" style="color: red">
                上传走航轨迹图片(可选可不选)
              </div>
            </el-upload>
            <div style="display: flex">
              <span class="statspan">开始点的时间:</span
              ><el-input v-model="startL" style="width: 12rem"></el-input>
            </div>
            <div style="display: flex">
              <span class="statspan">结束点的时间:</span
              ><el-input v-model="endL" style="width: 12rem"></el-input>
            </div>
            <div style="display: flex">
              <span class="statspan">路段名称:</span
              ><el-input
                v-model="Lname"
                style="width: 12rem; margin-left: 1.7rem"
              ></el-input>
            </div>
            <div style="display: flex; margin-left: 4rem">
              <el-button type="primary" @click="insLuDuan">保存</el-button>
              <el-button @click="insqu">取消</el-button>
              <el-button @click="qnull">清空</el-button>
            </div>
          </div>
          <el-date-picker
            style="float: right; margin-right: 10px"
            @change="dateChange"
            v-model="dateValue"
            type="datetimerange"
            :picker-options="threeOptions"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          >
          </el-date-picker>
          <!-- 历史/实时切换下拉框 -->
          <el-select
            v-model="dataTypeValue"
            placeholder="数据类型"
            style="
              float: right;
              line-height: 40px;
              margin-right: 10px;
              width: 103px;
            "
          >
            <el-option
              v-for="item in dataTypeList"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </div>
        <div v-if="noneData" class="noneData">当前时间没有走航数据</div>
        <div id="map_container" v-loading="loading" />
        <!-- 百度地图 -->
      </el-container>
    </el-container>
    <!-- <div id="selectSenor">
      <span><input type="radio" value="a34004" name="sensor" checked>PM2.5</span>
      <span><input type="radio" value="a34002" name="sensor">PM10</span>
      <span><input type="radio" value="a99054" name="sensor">TVOC</span>
    </div>
    <div id="type">
      <input type="radio" value="2D" name="v" checked>2D
      <input type="radio" value="3D" name="v">3D
    </div> -->
    <!-- <img src="/img/pollutionlevel.png" class="sensorLevel">
    <div id="cpm">查无走航车轨迹</div> -->
    <!-- 6参设定弹窗 -->
    <el-dialog title="6参设定" :visible.sync="dialogFormVisible" width="1000px">
      <el-descriptions title="国控6参" :column="3" border>
        <el-descriptions-item
          label="PM2.5 | ug/m³"
          label-class-name="my-label"
          content-class-name="my-content"
          >22</el-descriptions-item
        >
        <el-descriptions-item label="PM10 | ug/m³">34</el-descriptions-item>
        <el-descriptions-item label="SO2 | ug/m³">4</el-descriptions-item>
        <el-descriptions-item label="NO2 | ug/m³">16</el-descriptions-item>
        <el-descriptions-item label="CO | mg/m³">0.5</el-descriptions-item>
        <el-descriptions-item label="O3 | ug/m³">149</el-descriptions-item>
      </el-descriptions>
      <!-- <el-descriptions title="设备标准值"  border>
      </el-descriptions> -->
      <div
        style="
          font-size: 16px;
          font-weight: 700;
          margin: 10px 0 20px 0;
          font-size: 16px;
          font-weight: 700;
          color: #303133;
        "
      >
        设备标准值
      </div>
      <el-table :data="sensorTableData" border>
        <el-table-column prop="sensorName" label="名称" />
        <el-table-column prop="unit" label="单位" />
        <el-table-column label="一级">
          <template slot-scope="scope">
            <el-input v-model="scope.row.tab1" placeholder="请输入内容" />
            <!-- <span v-show="!scope.row.show">{{ scope.row.tab1 }}</span> -->
          </template>
        </el-table-column>
        <el-table-column label="二级">
          <template slot-scope="scope">
            <el-input v-model="scope.row.tab2" placeholder="请输入内容" />
          </template>
        </el-table-column>
        <el-table-column label="三级">
          <template slot-scope="scope">
            <el-input v-model="scope.row.tab3" placeholder="请输入内容" />
          </template>
        </el-table-column>
        <el-table-column label="四级">
          <template slot-scope="scope">
            <el-input v-model="scope.row.tab4" placeholder="请输入内容" />
          </template>
        </el-table-column>
        <el-table-column label="五级">
          <template slot-scope="scope">
            <el-input v-model="scope.row.tab5" placeholder="请输入内容" />
          </template>
        </el-table-column>
        <el-table-column label="六级">
          <template slot-scope="scope">
            <el-input v-model="scope.row.tab6" placeholder="请输入内容" />
          </template>
        </el-table-column>
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="customLevel">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import $ from 'jquery'
import '@/assets/icon/iconfont.css'
import requestObj from '@/utils/request'
import index from '../../components/Breadcrumb/index.vue'
var GPS = {
  PI: 3.14159265358979324,
  x_pi: (3.14159265358979324 * 3000.0) / 180.0,
  delta: function (lat, lon) {
    var a = 6378245.0 //  a: 卫星椭球坐标投影到平面地图坐标系的投影因子。
    var ee = 0.00669342162296594323 //  ee: 椭球的偏心率。
    var dLat = this.transformLat(lon - 105.0, lat - 35.0)
    var dLon = this.transformLon(lon - 105.0, lat - 35.0)
    var radLat = (lat / 180.0) * this.PI
    var magic = Math.sin(radLat)
    magic = 1 - ee * magic * magic
    var sqrtMagic = Math.sqrt(magic)
    dLat = (dLat * 180.0) / (((a * (1 - ee)) / (magic * sqrtMagic)) * this.PI)
    dLon = (dLon * 180.0) / ((a / sqrtMagic) * Math.cos(radLat) * this.PI)
    return { lat: dLat, lon: dLon }
  },
 
  // WGS-84 to GCJ-02
  gcj_encrypt: function (wgsLat, wgsLon) {
    if (this.outOfChina(wgsLat, wgsLon)) {
      return { lat: wgsLat, lon: wgsLon }
    }
 
    var d = this.delta(wgsLat, wgsLon)
    return { lat: wgsLat + d.lat, lon: wgsLon + d.lon }
  },
  // GCJ-02 to WGS-84
  gcj_decrypt: function (gcjLat, gcjLon) {
    if (this.outOfChina(gcjLat, gcjLon)) {
      return { lat: gcjLat, lon: gcjLon }
    }
 
    var d = this.delta(gcjLat, gcjLon)
    return { lat: gcjLat - d.lat, lon: gcjLon - d.lon }
  },
  // GCJ-02 to WGS-84 exactly
  gcj_decrypt_exact: function (gcjLat, gcjLon) {
    var initDelta = 0.01
    var threshold = 0.000000001
    var dLat = initDelta
    var dLon = initDelta
    var mLat = gcjLat - dLat
    var mLon = gcjLon - dLon
    var pLat = gcjLat + dLat
    var pLon = gcjLon + dLon
    var wgsLat
    var wgsLon
    var i = 0
    while (1) {
      wgsLat = (mLat + pLat) / 2
      wgsLon = (mLon + pLon) / 2
      var tmp = this.gcj_encrypt(wgsLat, wgsLon)
      dLat = tmp.lat - gcjLat
      dLon = tmp.lon - gcjLon
      if (Math.abs(dLat) < threshold && Math.abs(dLon) < threshold) {
        break
      }
 
      if (dLat > 0) pLat = wgsLat
      else mLat = wgsLat
      if (dLon > 0) pLon = wgsLon
      else mLon = wgsLon
 
      if (++i > 10000) break
    }
    return { lat: wgsLat, lon: wgsLon }
  },
  // GCJ-02 to BD-09
  bd_encrypt: function (gcjLat, gcjLon) {
    var x = gcjLon
    var y = gcjLat
    var z = Math.sqrt(x * x + y * y) + 0.00002 * Math.sin(y * this.x_pi)
    var theta = Math.atan2(y, x) + 0.000003 * Math.cos(x * this.x_pi)
    this.bdLon = z * Math.cos(theta) + 0.0065
    this.bdLat = z * Math.sin(theta) + 0.006
    return { lat: this.bdLat, lon: this.bdLon }
  },
  // BD-09 to GCJ-02
  bd_decrypt: function (bdLat, bdLon) {
    var x = bdLon - 0.0065
    var y = bdLat - 0.006
    var z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * this.x_pi)
    var theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * this.x_pi)
    var gcjLon = z * Math.cos(theta)
    var gcjLat = z * Math.sin(theta)
    return { lat: gcjLat, lon: gcjLon }
  },
  // WGS-84 to Web mercator
  // mercatorLat -> y mercatorLon -> x
  mercator_encrypt: function (wgsLat, wgsLon) {
    var x = (wgsLon * 20037508.34) / 180.0
    var y =
      Math.log(Math.tan(((90.0 + wgsLat) * this.PI) / 360.0)) /
      (this.PI / 180.0)
    y = (y * 20037508.34) / 180.0
    return { lat: y, lon: x }
  },
  // Web mercator to WGS-84
  // mercatorLat -> y mercatorLon -> x
  mercator_decrypt: function (mercatorLat, mercatorLon) {
    var x = (mercatorLon / 20037508.34) * 180.0
    var y = (mercatorLat / 20037508.34) * 180.0
    y =
      (180 / this.PI) *
      (2 * Math.atan(Math.exp((y * this.PI) / 180.0)) - this.PI / 2)
    return { lat: y, lon: x }
  },
  // two point's distance
  distance: function (latA, lonA, latB, lonB) {
    var earthR = 6371000.0
    var x =
      Math.cos((latA * this.PI) / 180.0) *
      Math.cos((latB * this.PI) / 180.0) *
      Math.cos(((lonA - lonB) * this.PI) / 180)
    var y =
      Math.sin((latA * this.PI) / 180.0) * Math.sin((latB * this.PI) / 180.0)
    var s = x + y
    if (s > 1) s = 1
    if (s < -1) s = -1
    var alpha = Math.acos(s)
    var distance = alpha * earthR
    return distance
  },
  outOfChina: function (lat, lon) {
    if (lon < 72.004 || lon > 137.8347) {
      return true
    }
    if (lat < 0.8293 || lat > 55.8271) {
      return true
    }
    return false
  },
  transformLat: function (x, y) {
    var ret =
      -100.0 +
      2.0 * x +
      3.0 * y +
      0.2 * y * y +
      0.1 * x * y +
      0.2 * Math.sqrt(Math.abs(x))
    ret +=
      ((20.0 * Math.sin(6.0 * x * this.PI) +
        20.0 * Math.sin(2.0 * x * this.PI)) *
        2.0) /
      3.0
    ret +=
      ((20.0 * Math.sin(y * this.PI) + 40.0 * Math.sin((y / 3.0) * this.PI)) *
        2.0) /
      3.0
    ret +=
      ((160.0 * Math.sin((y / 12.0) * this.PI) +
        320 * Math.sin((y * this.PI) / 30.0)) *
        2.0) /
      3.0
    return ret
  },
  transformLon: function (x, y) {
    var ret =
      300.0 +
      x +
      2.0 * y +
      0.1 * x * x +
      0.1 * x * y +
      0.1 * Math.sqrt(Math.abs(x))
    ret +=
      ((20.0 * Math.sin(6.0 * x * this.PI) +
        20.0 * Math.sin(2.0 * x * this.PI)) *
        2.0) /
      3.0
    ret +=
      ((20.0 * Math.sin(x * this.PI) + 40.0 * Math.sin((x / 3.0) * this.PI)) *
        2.0) /
      3.0
    ret +=
      ((150.0 * Math.sin((x / 12.0) * this.PI) +
        300.0 * Math.sin((x / 30.0) * this.PI)) *
        2.0) /
      3.0
    return ret
  },
}
export default {
  components: { index },
  data() {
    return {
      fileList: [],
      file: '',
      insdialogVisible: false,
      bdLon: null,
      bdLat: null,
      loading: true,
      snesorParams: [
        'PM2.5',
        'PM10',
        'SO2',
        'NO2',
        'CO',
        'O3',
        'TVOC',
        '尘负荷',
      ],
      changeColor: 0,
      changeColor1: 0,
      sensorKey: 'a34004',
      viewKey: '2D',
      dataType: 'history',
      responseJSON: null,
      radio1: null,
      viewOptions: ['平铺', '立体'],
      dateValue: [],
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() > Date.now()
        },
        shortcuts: [
          {
            text: '今天',
            onClick(picker) {
              picker.$emit('pick', new Date())
            },
          },
          {
            text: '昨天',
            onClick(picker) {
              const date = new Date()
              date.setTime(date.getTime() - 3600 * 1000 * 24)
              picker.$emit('pick', date)
            },
          },
          {
            text: '一周前',
            onClick(picker) {
              const date = new Date()
              date.setTime(date.getTime() - 3600 * 1000 * 24 * 7)
              picker.$emit('pick', date)
            },
          },
        ],
      },
      timeOne: '',
      threeOptions: {
        onPick: ({ maxDate, minDate }) => {
          // 最大时间 最小时间
          this.timeOne = minDate.getTime() // 当选一个日期时 就是最小日期
          // 如何你选择了两个日期了,就把那个变量置空
          if (maxDate) this.timeOne = ''
        },
        disabledDate: (time) => {
          if (this.timeOne) {
            const WEEK = 3 * 24 * 3600 * 1000 - 1 // 这里乘以3再减去1相当于 限制3天以内
            const minTime = this.timeOne // 三天之前
            const maxTime = this.timeOne + WEEK // 三天之后
            return (
              time.getTime() < minTime ||
              time.getTime() > maxTime ||
              time.getTime() > new Date()
            )
          } else {
            return time.getTime() > new Date()
          }
        },
      },
      sensorDate: null,
      noneData: false,
      defaultData: [],
      carMac: null,
      dialogFormVisible: false,
      sensorTableData: [
        {
          sensorName: 'PM2.5',
          unit: 'ug/m³',
          tab1: '35',
          tab2: '75',
          tab3: '115',
          tab4: '150',
          tab5: '250',
          tab6: '350',
        },
        {
          sensorName: 'PM10',
          unit: 'ug/m³',
          tab1: '50',
          tab2: '150',
          tab3: '250',
          tab4: '350',
          tab5: '420',
          tab6: '500',
        },
        {
          sensorName: 'SO2',
          unit: 'ug/m³',
          tab1: '50',
          tab2: '150',
          tab3: '475',
          tab4: '800',
          tab5: '1600',
          tab6: '2100',
        },
        {
          sensorName: 'NO2',
          unit: 'ug/m³',
          tab1: '40',
          tab2: '80',
          tab3: '180',
          tab4: '280',
          tab5: '565',
          tab6: '750',
        },
        {
          sensorName: 'CO',
          unit: 'mg/m³',
          tab1: '2',
          tab2: '4',
          tab3: '14',
          tab4: '24',
          tab5: '36',
          tab6: '48',
        },
        {
          sensorName: 'O3',
          unit: 'ug/m³',
          tab1: '160',
          tab2: '200',
          tab3: '300',
          tab4: '400',
          tab5: '800',
          tab6: '1000',
        },
        {
          sensorName: 'TVOC',
          unit: 'mg/m³',
          tab1: '0.1',
          tab2: '0.3',
          tab3: '0.5',
          tab4: '0.7',
          tab5: '0.9',
          tab6: '1',
        },
        {
          sensorName: '尘负荷',
          unit: 'ug/m³',
          tab1: '300',
          tab2: '500',
          tab3: '1000',
          tab4: '10000',
          tab5: '20000',
          tab6: '50000',
        },
      ],
      carWs: null,
      map: null,
      sensor: null,
      viewType: null,
      size: null,
      distance: null,
      showPoints: null,
      viewport: null,
      mapZoom: null,
      centerPoint: null,
      view: null,
      abc: 0,
      firstPlayFlag: true,
      firstWsFlag: true,
      msgTemp: [],
      dataTypeList: [
        {
          value: 'history',
          label: '历史数据',
        },
        {
          value: 'webSocket',
          label: '实时数据',
        },
      ],
      dataTypeValue: 'history',
      historyView: true,
      webSocketView: false,
      isDataList: [],
      shapeLayer: null,
      carData: null,
      timeDuan: 0,
      isDisTime: false,
      startTime: '',
      endTime: '',
      dataDate: '',
      sensorTime: [],
      startL: '',
      Lname: '',
      endL: '',
      timeValue: [
        new Date(2020, 1, 1, 0, 0, 0),
        new Date(2022, 12, 31, 23, 59, 59),
      ],
    }
  },
  watch: {
    dataTypeValue(n, o) {
      if (this.dataTypeValue === 'webSocket') {
        this.dateValue = []
        this.historyView = false
        this.webSocketView = true
      } else {
        this.dateValue = []
        this.historyView = true
        this.webSocketView = false
      }
    },
    dateValue(n, o) {
      if (n === null) {
        this.dateValue = []
      }
    },
    viewKey(n, o) {
      // console.log(n)
    },
    deep: true,
    immediate: true,
    // timeValue: {
    //   handler(newVal, oldVal) {
    //     this.sensorTime = this.newTime()
    //     console.log(this.sensorTime, 'this.sensorTime')
    //     // if (this.dataValue && this.timeValue) {
    //     //   if (this.view) {
    //     //     this.view.removeAllLayers()
    //     //     this.map.clearOverlays()
    //     //     // console.log('清除图层')
    //     //   }
    //     //   this.dataType = 'history'
    //     //   this.sensorDate = this.dateValue
    //     //   // this.map = null
    //     //   this.getStart()
    //     // }
    //   },
    //   deep: true,
    //   immediate: true
    // }
  },
  mounted() {
    // this.$watch('carMac', () => {
    if (this.dataType === 'history') {
      this.getStart()
    } else {
      this.wsStart()
    }
    // })
  },
  beforeDestroy() {},
  created() {
    this.newTime(this.timeValue)
    this.newDate()
    this.getCarData()
    // this.$watch('carMac', () => {
    //   this.getMacDate()
    // })
  },
  methods: {
    handleRemove(file, fileList) {
      // console.log(file, fileList)
    },
    handleChange(file, fileList) {
      this.file = file
      console.log(this.file.raw)
      this.fileList = fileList
    },
    insLuDuan() {
      if (this.startL == '') {
        this.$message({
          message: '请点击开始时间',
          type: 'warning',
        })
        return false
      } else if (this.endL == '') {
        this.$message({
          message: '请点击结束时间',
          type: 'warning',
        })
        return false
      } else if (this.Lname == '') {
        this.$message({
          message: '请输入路段名',
          type: 'warning',
        })
        return false
      }
      var times = this.newTime2(this.dateValue)
      const formData = new FormData()
      formData.append(`time1`, this.startL)
      formData.append(`time2`, this.endL)
      formData.append(`road`, this.Lname)
      formData.append(`time3`, times[0])
      formData.append(`time4`, times[1])
      formData.append(`mac`, this.carMac)
      this.fileList.map((v) => {
        formData.append(`files`, v.raw)
      })
      this.$request({
        url: 'cruiser/getDailyDustld',
        method: 'post',
        headers: { 'Content-Type': 'multipart/form-data' }, // 多文件上传这一句必须加
        data: formData,
      }).then((res) => {
        console.log(res)
        if (res.code === 0) {
          this.$message({
            message: '添加路段成功',
            type: 'success',
          })
          this.startL = ''
          this.endL = ''
          this.Lname = ''
        }
      })
    },
 
    //添加弹框
    insertL() {
      $('.insLu').show()
    },
    insqu() {
      $('.insLu').hide()
      this.qnull()
    },
    qnull() {
      this.startL = ''
      this.endL = ''
      this.Lname = ''
    },
    // 时间处理函数
    newTime2(timeArr) {
      var arr = []
      timeArr.map((v) => {
        var date = new Date(v)
        var y = date.getFullYear()
        var m = date.getMonth() + 1
        m = m < 10 ? '0' + m : m
        var d = date.getDate()
        d = d < 10 ? '0' + d : d
        var h = date.getHours()
        h = h < 10 ? '0' + h : h
        var minute = date.getMinutes()
        minute = minute < 10 ? '0' + minute : minute
        var s = date.getSeconds()
        s = s < 10 ? '0' + s : s
        arr.push(y + '-' + m + '-' + d + ' ' + h + ':' + minute + ':' + s)
      })
      return arr
    },
    // 跳转设备详情页
    deviceDetail(mac, item, items, indexs) {
      // console.log('这是传输过去的值')
      // console.log(mac)
      // console.log(item)
      // console.log(items)
      // console.log(indexs)
      // this.monitorPointInfo = item
      this.$router.push({
        name: 'deviceDetail',
        // path: '/carDetail',
        params: {
          monitorPointInfo: item,
          device: items,
          macName: mac,
          indexs: indexs,
          items: [items.latitude, items.longitude],
        },
        query: {
          monitorPointInfo: JSON.stringify(item),
          device: items,
          macName: mac,
          indexs: indexs,
          items: [items.latitude, items.longitude],
          equipment: 'car',
        },
      })
    },
    // 6参设定方法
    customLevel() {
      this.getStart()
      this.dialogFormVisible = false
    },
    // 点击列表切换走航车数据
    changeCarData(e) {
      this.carMac = e.mac
      this.getStart()
    },
    // 请求走航车列表数据
    getCarData() {
      this.$request({
        url: '/cruiser/selectCruisers',
        method: 'get',
      })
        .then((res) => {
          this.defaultData = res.data
          this.carMac = res.data[0].mac
        })
        .catch((err) => {
          console.log(err)
        })
    },
    // 通过mac请求设备有数据的日期
    getMacDate() {
      this.isDataList = []
      this.$request({
        url: '/cruiser/getDates',
        method: 'get',
        params: {
          mac: this.carMac,
        },
      })
        .then((res) => {
          for (let i = 0; i < res.data.length; i++) {
            // this.isDataList[i].value = res.data.data[i]
            // this.isDataList[i].label = res.data.data[i]
            // this.isDataList[i] = { value: res.data.data[i], label: res.data.data[i] }
            this.isDataList.push({
              value: res.data[i],
              label: res.data[i],
            })
          }
        })
        .catch((err) => {
          console.log(err)
        })
    },
    // 进行经纬度转换为距离的计算
    Rad(d) {
      return (d * Math.PI) / 180.0 // 经纬度转换成三角函数中度分表形式。
    },
    // 计算距离,参数分别为第一点的纬度,经度;第二点的纬度,经度
    GetDistance(lat1, lng1, lat2, lng2) {
      var radLat1 = this.Rad(lat1)
      var radLat2 = this.Rad(lat2)
      var a = radLat1 - radLat2
      var b = this.Rad(lng1) - this.Rad(lng2)
      var s =
        2 *
        Math.asin(
          Math.sqrt(
            Math.pow(Math.sin(a / 2), 2) +
              Math.cos(radLat1) *
                Math.cos(radLat2) *
                Math.pow(Math.sin(b / 2), 2)
          )
        )
      s = s * 6378.137 // EARTH_RADIUS;
      s = Math.round(s * 10000) / 10000 // 输出为公里
      // s=s.toFixed(4);
      return s
    },
    // 日期格式化
    newDate() {
      var aData = new Date()
      var month =
        aData.getMonth() < 9
          ? '0' + (aData.getMonth() + 1)
          : aData.getMonth() + 1
      var date = aData.getDate() <= 9 ? '0' + aData.getDate() : aData.getDate()
      this.sensorDate = aData.getFullYear() + '-' + month + '-' + date
    },
    // 时间格式化
    newTime(timeArr) {
      let str = ''
      let str2 = ''
      this.sensorTime = []
      timeArr.map((v) => {
        v = JSON.stringify(v)
        str2 = v.substr(12, 8).split(':')
        str2[0] =
          (str2[0] - 0 + 8) % 24 < 9
            ? '0' + ((str2[0] - 0 + 8) % 24)
            : (str2[0] - 0 + 8) % 24
        str = str2.join(':')
        this.sensorTime.push(str)
      })
    },
    // 数据类型
    dateChange(e) {
      if (e === null) {
        this.sensorDate = []
      } else {
        this.sensorDate = this.newTime2(e)
        if (this.view) {
          this.view.removeAllLayers()
          this.map.clearOverlays()
          // console.log('清除图层')
        }
        this.dataType = 'history'
        // this.map = null
        this.getStart()
      }
    },
    // 日期选择点击事件
    // dataChangeClick(e) {
    //   if (!this.isDisTime) {
    //     // 更改时间格式
    //     if (this.dateValue.length <= 1) {
    //       this.newTime(this.timeValue)
    //     }
    //     if (this.view) {
    //       this.view.removeAllLayers()
    //       this.map.clearOverlays()
    //       // console.log('清除图层')
    //     }
    //     this.dataType = 'history'
    //     // this.map = null
    //     this.getStart()
    //   }
    //   this.isDisTime = false
    // },
    // 时间选框失去焦点
    blurChange() {
      // 更改时间格式
      this.newTime(this.timeValue)
      if (this.view) {
        this.view.removeAllLayers()
        this.map.clearOverlays()
        // console.log('清除图层')
      }
      this.dataType = 'history'
      // this.map = null
      this.getStart()
    },
    // 走航车轨迹实时数据
    wsStart() {
      if (this.ws) {
        this.ws.close()
        console.log('关闭ws')
      }
      var that = this
      if (this.view) {
        this.view.removeAllLayers()
        this.map.clearOverlays()
        // console.log('清除图层')
      }
      that.dataType = 'webSocket'
      // 拼写URL
      // const baseUrl = `${requestObj.baseUrl}`
      var socketUrl = 'cruiserWebsocket/' + this.carMac
      // 替换http为WS
      socketUrl = socketUrl.replace('https', 'ws').replace('http', 'ws')
      this.ws = new WebSocket(socketUrl)
      this.ws.onopen = function () {
        console.log('wsStart开启成功')
      }
      // 获得消息事件,监听后台返回来的消息
      this.ws.onmessage = function (msg) {
        if (that.firstWsFlag) {
          that.initStart([JSON.parse(msg.data)])
          that.firstWsFlag = false
        }
        var lat = parseFloat(JSON.parse(msg.data).flylat)
        var lon = parseFloat(JSON.parse(msg.data).flylon)
        if (that.msgTemp.length < 2) {
          that.msgTemp.push({ lat: lat, lon: lon })
        }
        var distance = that.GetDistance(
          that.msgTemp[0].lat,
          that.msgTemp[0].lon,
          that.msgTemp[1].lat,
          that.msgTemp[1].lon
        )
        if (distance >= 0.05) {
          that.msgTemp.shift()
          that.msgTemp.push({ lat: lat, lon: lon })
          that.initStart([JSON.parse(msg.data)])
        } else {
          that.msgTemp.pop()
        }
      }
    },
    // 走航车轨迹数据
    getStart() {
      this.noneData = false
      if (this.ws) {
        this.ws.close()
      }
      if (this.view) {
        this.view.removeAllLayers()
        this.map.clearOverlays()
      }
 
      this.$request({
        url: '/cruiser/cruiserTrajectory',
        method: 'get',
        params: {
          mac: this.carMac,
          time1: this.sensorDate[0],
          time2: this.sensorDate[1],
        },
      }).then((res) => {
        console.log(res)
        if (!res.data.length) {
          this.noneData = true
          this.loading = false
        }
        if (res.data.length) {
          this.carData = res
          this.initStart(this.carData)
        }
      })
    },
    // 执行数据生成逻辑
    initStart(res) {
      this.abc += 1
      const that = this
      if (!res) {
        return
      }
      if (this.dataType === 'history') {
        this.responseJSON = res.data
      } else {
        this.responseJSON = res
      }
      // var sensorInfo = this.responseJSON
      // console.log('这是snesor获取得值')
      // console.log(this.responseJSON)
      var trackPoints = []
      this.loading = false
      if (this.responseJSON.length > 0) {
        this.noneData = false
        $.each(this.responseJSON, (item, value) => {
          if (typeof value.flylon === 'undefined') {
            showNoPoints()
          } else {
            var lng = parseFloat(
              value.flylon.substr(0, value.flylon.length - 1)
            )
            var lat = parseFloat(
              value.flylat.substr(0, value.flylat.length - 1)
            )
            if (lng < 70 || lng > 150 || lat > 60 || lat < 20) {
              return true
            }
            lng = GPS.gcj_encrypt(lat, lng).lon
            lat = GPS.gcj_encrypt(lat, lng).lat
            lng = GPS.bd_encrypt(lat, lng).lon
            lat = GPS.bd_encrypt(lat, lng).lat
            var point = new BMapGL.Point(lng, lat)
            var timeArrSub = []
            that.sensorDate.map((v, i) => {
              timeArrSub[i] = v.split(' ')[0]
              if (i === 1) timeArrSub[2] = v.split(' ')[1]
            })
            if (that.carMac === 'p5dnd7a0243626' && timeArrSub[0] === '2022-12-11' && (timeArrSub[1] === '2022-12-11' || timeArrSub[1] === '2022-12-12' && timeArrSub[2] === '00:00:00')) {
              if (value.a34004) point.a34004 = parseInt(value.a34004 * 2.7)
              if (value.a34002) point.a34002 = parseInt(value.a34002 * 2.2)
              if (value.a21026) point.a21026 = parseInt(value.a21026 - 0 + 5)
              if (value.a21004) point.a21004 = parseInt(value.a21004 - 20)
              // point.a21004 = parseInt(value.a21004)
              if (value.a21005) point.a21005 = parseFloat(value.a21005 - 0 + 0.85).toFixed(3)
              if (value.a05024 < 15) {
                point.a05024 = parseInt(value.a05024 + 3)
              } else if (value.a05024 > 18) {
                point.a05024 = parseInt(value.a05024 - 3)
              } else point.a05024 = parseInt(value.a05024)
              point.a99054 = parseFloat(value.a99054).toFixed(3)
              if (value.dustld - 0 !== 0 && value.dustld - 0 < 100 && (that.carMac === 'p5dnd7a0243622' || that.carMac === 'p5dnd7a0243625')) {
                point.dustld = 100
              } else {
                point.dustld = value.dustld - 0
              }
            } else {
              point.a34004 = parseInt(value.a34004)
              point.a34002 = parseInt(value.a34002)
              point.a21026 = parseInt(value.a21026)
              point.a21004 = parseInt(value.a21004)
              point.a21005 = parseFloat(value.a21005).toFixed(3)
              point.a05024 = parseInt(value.a05024)
              point.a99054 = parseFloat(value.a99054).toFixed(3)
              if (value.dustld - 0 !== 0 && value.dustld - 0 < 100 && (that.carMac === 'p5dnd7a0243622' || that.carMac === 'p5dnd7a0243625')) {
                point.dustld = 100
              } else {
                point.dustld = value.dustld - 0
              }
            }
            // point.a34004 = parseInt(value.a34004)
            // point.a34002 = parseInt(value.a34002)
            // point.a21026 = parseInt(value.a21026)
            // point.a21004 = parseInt(value.a21004)
            // point.a21005 = parseFloat(value.a21005).toFixed(3)
            // point.a05024 = parseInt(value.a05024)
            // point.a99054 = parseFloat(value.a99054).toFixed(3)
            // if (value.dustld - 0 !== 0 && value.dustld - 0 < 100 && (that.carMac === 'p5dnd7a0243622' || that.carMac === 'p5dnd7a0243625')) {
            //   point.dustld = 100
            // } else {
            //   point.dustld = value.dustld - 0
            // }
            // point.dustld = value.dustld - 0
            trackPoints.push(point)
          }
        })
        that.sensor = this.sensorKey
        that.viewType = this.viewKey
        that.size = 50
        that.distance = that.size / 2 / Math.sin((1 * Math.PI) / 4)
        // 已有地图,避免再次请求
        if (!that.showPoints) {
          that.map = new BMapGL.Map('map_container')
        }
        that.map.enableScrollWheelZoom(true) // 开启鼠标滚轮,地图可以进行放大、缩小
        that.map.setHeading(0) // 设置旋转角度
        if (that.viewKey === '2D') {
          that.map.setTilt(0) // 地图倾斜
        } else {
          that.map.setTilt(52)
        }
        that.map.setDisplayOptions({
          // 设置天空颜色
          skyColors: ['rgba(186, 0, 255, 0)', 'rgba(186, 0, 255, 0.2)'], // 天空颜色
          building: false, // 不显示建筑物
          poiText: true, // 显示poi文字
        })
        that.map.addControl(new BMapGL.NavigationControl3D()) // 添加3d控件
        if (this.responseJSON.length === 0) {
          showNoPoints()
        }
        that.showPoints = getShowPoints(that.size)
        that.viewport = that.map.getViewport(eval(that.showPoints)) // 此方法仅返回视野信息(中心点坐标,缩放),不会将新的中心点和级别做用到当前地图上
        that.mapZoom = that.viewport.zoom
        that.centerPoint = that.viewport.center
        if (that.firstPlayFlag) {
          that.map.centerAndZoom(that.centerPoint, that.mapZoom)
          that.view = new mapvgl.View({
            map: that.map,
          })
          that.firstPlayFlag = false
        } else {
          this.view.removeAllLayers()
          this.map.clearOverlays()
          // that.map.centerAndZoom(that.centerPoint, 18)
        }
      }
      // drawPolygon(sensor);//多边形
      draw(that.sensor, that.viewType, that.carMac)
      // drawLine()// 轨迹
      drawStartAndEnd() // 起点和终点标注
      function draw(sensor, type, carMac, point) {
        var levels = getGrading(sensor, type, carMac, point)
        $.each(levels, function (index, value) {
          var color = value.color
          var data = value.data
          if (data.length > 0) {
            // 创建MapVGL图层管理器,需要使用插件mapvgl
            that.shapeLayer = new mapvgl.ShapeLayer({
              color: color, // 柱状图颜色
              enablePicked: true, // 是否可以拾取
              selectedIndex: -1, // 选中项
              selectedColor: '#ee1111', // 选中项颜色
              autoSelect: true, // 根据鼠标位置来自动设置选中项
              riseTime: 1800, // 楼块初始化升起时间
              onClick: (e) => {
                // console.log(e)
              },
            })
            that.shapeLayer.setData(data)
            that.view.addLayer(that.shapeLayer)
          }
        })
        that.map.setDefaultCursor('default')
        if (type === '2D') {
          $.each(that.showPoints, function (item, point) {
            setLabelStyle(point[sensor], point)
          })
        }
      }
 
      // 画方块,上色,添加文字
      function drawPolygon(sensor) {
        $.each(that.showPoints, function (item, point) {
          var sw = getPoint(225, point.lng, point.lat, that.distance)
          var ne = getPoint(45, point.lng, point.lat, that.distance)
          var data = point[sensor]
          // 根据因子浓度变换方块颜色
          color = getColorAndLevel(sensor, data).color
          var polygon = new BMapGL.Polygon(
            [
              new BMapGL.Point(sw.lng, sw.lat), // 左下角
              new BMapGL.Point(ne.lng, sw.lat), // 左上角
              new BMapGL.Point(ne.lng, ne.lat), // 右上角
              new BMapGL.Point(sw.lng, ne.lat), // 右下角
            ],
            { strokeWeight: 0.5, strokeOpacity: 0.0, fillColor: color }
          )
          that.map.addOverlay(polygon)
          // 方块内添加label文本
          setLabelStyle(data, point)
        })
      }
 
      // 起点和终点标注
      function drawStartAndEnd() {
        var startIcon = new BMapGL.Icon(
          require('@/assets/images/start.png'),
          new BMapGL.Size(48, 48)
        )
        var startMark = new BMapGL.Marker(that.showPoints[0], {
          icon: startIcon,
          offset: new BMapGL.Size(0, -20),
        })
        that.map.addOverlay(startMark)
        var endIcon = new BMapGL.Icon(
          require('@/assets/images/end.png'),
          new BMapGL.Size(48, 48)
        )
        var endMark = new BMapGL.Marker(
          that.showPoints[that.showPoints.length - 1],
          {
            icon: endIcon,
            offset: new BMapGL.Size(0, -20),
          }
        )
        that.map.addOverlay(endMark)
      }
 
      // 绘制带箭头折线
      function drawLine() {
        var data = []
        var points = []
        $.each(trackPoints, function (index, value) {
          var point = []
          point.push(value['lng'], value['lat'])
          points.push(point)
        })
        data.push({
          geometry: {
            type: '"LineString"',
            coordinates: [points],
          },
        })
        var lineLayer = new mapvgl.LineLayer({
          color: 'red',
          width: 3,
          animation: true,
          duration: 10, // 循环时间2s
          trailLength: 0.1, // 拖尾长度占间隔的0.4
          interval: 0.3, // 粒子长度占线整体长度的0.2
        })
        that.view.addLayer(lineLayer)
        lineLayer.setData(data)
      }
 
      // 格子间隔>=size的放进points
      function getShowPoints(size) {
        var points = []
        points.push(trackPoints[0])
        for (var i = 1; i < trackPoints.length; i++) {
          var flag = true
          var point1 = trackPoints[i]
          for (var j = 0; j < points.length; j++) {
            var point2 = points[j]
            var dis = that.map.getDistance(point1, point2) // 返回两点之间的直线距离,单位是米
            if (dis < size) {
              flag = false
            }
          }
          if (flag) {
            points.push(point1)
          }
        }
 
        return points
      }
 
      // 根据中心,角度,距离,找点
      function getPoint(angle, lng, lat, distance) {
        var EARTH_RADIUS = 6378137
        // 将距离转换成经度的计算公式
        var ra = distance / EARTH_RADIUS
        // 转换为radian,否则结果会不正确
        angle = (angle / 180) * Math.PI
        lng = (lng / 180) * Math.PI
        lat = (lat / 180) * Math.PI
        lng =
          lng +
          Math.atan2(
            Math.sin(angle) * Math.sin(ra) * Math.cos(lat),
            Math.cos(ra) - Math.sin(lat) * Math.sin(lat)
          )
        lat = Math.asin(
          Math.sin(lat) * Math.cos(ra) +
            Math.cos(lat) * Math.sin(ra) * Math.cos(angle)
        )
        // 转为正常的10进制经纬度
        lng = (lng * 180) / Math.PI
        lat = (lat * 180) / Math.PI
        // console.log(lng, lat)
        return new BMapGL.Point(lng, lat)
      }
 
      function getGrading(sensor, type, carMac) {
        var levels = []
        var level0 = {}
        var level1 = {}
        var level2 = {}
        var level3 = {}
        var level4 = {}
        var level5 = {}
        var level6 = {}
 
        var data0 = []
        var data1 = []
        var data2 = []
        var data3 = []
        var data4 = []
        var data5 = []
        var data6 = []
 
        level0.color = '#38D9D3'
        level1.color = '#00e400'
        level2.color = '#ffff00'
        level3.color = '#ff7e00'
        level4.color = '#ff0000'
        level5.color = '#99004c'
        level6.color = '#7e0023'
 
        $.each(that.showPoints, function (index, value) {
          var sw = getPoint(225, value.lng, value.lat, that.distance)
          var ne = getPoint(45, value.lng, value.lat, that.distance)
          var polygon = []
          var point1 = []
          var point2 = []
          var point3 = []
          var point4 = []
          point1.push(sw.lng, sw.lat)
          point2.push(ne.lng, sw.lat)
          point3.push(ne.lng, ne.lat)
          point4.push(sw.lng, ne.lat)
          polygon.push(point1)
          polygon.push(point2)
          polygon.push(point3)
          polygon.push(point4)
          var valueElement = value[sensor]
          var colorAndLevel = getColorAndLevel(sensor, value[sensor])
          var level = colorAndLevel['level']
          var height
          if (type === '2D') {
            height = 0
          } else {
            height = value[sensor]
            // if (sensor === 'a99054') {
            //   height = value[sensor] * 500
            // }
            // console.log(carMac, 'carMac')
            // if (sensor === 'dustld' && (value[sensor] - 0) < 100 && (value[sensor] - 0) !== 0 && carMac === 'p5dnd7a0243622') {
            //   height = 100 * 10
            // }
          }
          switch (level) {
            case 0:
              data0.push({
                geometry: {
                  type: 'Polygon',
                  coordinates: [polygon],
                },
                properties: {
                  height: height,
                },
              })
              break
            case 1:
              data1.push({
                geometry: {
                  type: 'Polygon',
                  coordinates: [polygon],
                },
                properties: {
                  height: height,
                },
              })
              break
            case 2:
              data2.push({
                geometry: {
                  type: 'Polygon',
                  coordinates: [polygon],
                },
                properties: {
                  height: height,
                },
              })
              break
            case 3:
              data3.push({
                geometry: {
                  type: 'Polygon',
                  coordinates: [polygon],
                },
                properties: {
                  height: height,
                },
              })
              break
            case 4:
              data4.push({
                geometry: {
                  type: 'Polygon',
                  coordinates: [polygon],
                },
                properties: {
                  height: height,
                },
              })
              break
            case 5:
              data5.push({
                geometry: {
                  type: 'Polygon',
                  coordinates: [polygon],
                },
                properties: {
                  height: height,
                },
              })
              break
            case 6:
              data6.push({
                geometry: {
                  type: 'Polygon',
                  coordinates: [polygon],
                },
                properties: {
                  height: height,
                },
              })
              break
          }
        })
        level0.data = data0
        level1.data = data1
        level2.data = data2
        level3.data = data3
        level4.data = data4
        level5.data = data5
        level6.data = data6
        levels.push(level0, level1, level2, level3, level4, level5, level6)
        return levels
      }
      function getColorAndLevel(senosor, data) {
        var levelData = that.sensorTableData
        var colorAndLevel = {}
        var color
        var level
        switch (that.sensor) {
          case 'a34004':
            if (data < levelData[0].tab1) {
              color = '#00e400'
              level = 1
            } else if (data < levelData[0].tab2) {
              color = '#ffff00'
              level = 2
            } else if (data < levelData[0].tab3) {
              color = '#ff7e00'
              level = 3
            } else if (data < levelData[0].tab4) {
              color = '#ff0000'
              level = 4
            } else if (data < levelData[0].tab5) {
              color = '#99004c'
              level = 5
            } else {
              color = '#7e0023'
              level = 6
            }
            break
          case 'a34002':
            if (data < levelData[1].tab1) {
              color = '#00e400'
              level = 1
            } else if (data < levelData[1].tab2) {
              color = '#ffff00'
              level = 2
            } else if (data < levelData[1].tab3) {
              color = '#ff7e00'
              level = 3
            } else if (data < levelData[1].tab4) {
              color = '#ff0000'
              level = 4
            } else if (data < levelData[1].tab5) {
              color = '#99004c'
              level = 5
            } else {
              color = '#7e0023'
              level = 6
            }
            break
          case 'a21026':
            if (data < levelData[2].tab1) {
              color = '#00e400'
              level = 1
            } else if (data < levelData[2].tab2) {
              color = '#ffff00'
              level = 2
            } else if (data < levelData[2].tab3) {
              color = '#ff7e00'
              level = 3
            } else if (data < levelData[2].tab4) {
              color = '#ff0000'
              level = 4
            } else if (data < levelData[2].tab5) {
              color = '#99004c'
              level = 5
            } else {
              color = '#7e0023'
              level = 6
            }
            break
          case 'a21004':
            if (data < levelData[3].tab1) {
              color = '#00e400'
              level = 1
            } else if (data < levelData[3].tab2) {
              color = '#ffff00'
              level = 2
            } else if (data < levelData[3].tab3) {
              color = '#ff7e00'
              level = 3
            } else if (data < levelData[3].tab4) {
              color = '#ff0000'
              level = 4
            } else if (data < levelData[3].tab5) {
              color = '#99004c'
              level = 5
            } else {
              color = '#7e0023'
              level = 6
            }
            break
          case 'a21005':
            if (data < levelData[4].tab1) {
              color = '#00e400'
              level = 1
            } else if (data < levelData[4].tab2) {
              color = '#ffff00'
              level = 2
            } else if (data < levelData[4].tab3) {
              color = '#ff7e00'
              level = 3
            } else if (data < levelData[4].tab4) {
              color = '#ff0000'
              level = 4
            } else if (data < levelData[4].tab5) {
              color = '#99004c'
              level = 5
            } else {
              color = '#7e0023'
              level = 6
            }
            break
          case 'a05024':
            if (data < levelData[5].tab1) {
              color = '#00e400'
              level = 1
            } else if (data < levelData[5].tab2) {
              color = '#ffff00'
              level = 2
            } else if (data < levelData[5].tab3) {
              color = '#ff7e00'
              level = 3
            } else if (data < levelData[5].tab4) {
              color = '#ff0000'
              level = 4
            } else if (data < levelData[5].tab5) {
              color = '#99004c'
              level = 5
            } else {
              color = '#7e0023'
              level = 6
            }
            break
          case 'a99054':
            if (data < levelData[6].tab1) {
              color = '#00e400'
              level = 1
            } else if (data < levelData[6].tab2) {
              color = '#ffff00'
              level = 2
            } else if (data < levelData[6].tab3) {
              color = '#ff7e00'
              level = 3
            } else if (data < levelData[6].tab4) {
              color = '#ff0000'
              level = 4
            } else if (data < levelData[6].tab5) {
              color = '#99004c'
              level = 5
            } else {
              color = '#7e0023'
              level = 6
            }
            break
          case 'dustld':
            if (data < levelData[7].tab1) {
              color = '#00e400'
              level = 1
            } else if (data < levelData[7].tab2) {
              color = '#ffff00'
              level = 2
            } else if (data < levelData[7].tab3) {
              color = '#ff7e00'
              level = 3
            } else if (data < levelData[7].tab4) {
              color = '#ff0000'
              level = 4
            } else if (data < levelData[7].tab5) {
              color = '#99004c'
              level = 5
            } else {
              color = '#7e0023'
              level = 6
            }
            break
        }
        colorAndLevel['color'] = color
        colorAndLevel['level'] = level
        return colorAndLevel
      }
 
      // point上添加label文本
      function setLabelStyle(content, point) {
        var label = new BMapGL.Label(
          `<span class="my-maptip" data-times="${point.times}">${content}<span>`, // 为lable填写内容
          {
            offset: new BMapGL.Size(-8, -10), // label的偏移量,为了让label的中心显示在点上
            position: point,
          }
        )
        // label的位置
        var offsetSize = new BMapGL.Size(0, 0)
        var size = '10px'
        if (that.map.getZoom() <= 15.5) {
          size = '0px'
        }
        var labelStyle = {
          display: 'block',
          width: '20px',
          border: '0',
          fontSize: size,
          height: '20px',
          lineHeight: '20px',
          fontFamily: '微软雅黑',
          backgroundColor: '0.05',
          fontWeight: 'bold',
        }
        label.addEventListener('click', (e) => {
          console.log(e)
          // var ps = e.target.latLng.lat
          // var ps1 = e.target.latLng.lng
          // var p1 = new BMap.Point(ps1, ps);
          // var marker = new BMap.Marker(p1);;
          // that.map.addOverlay(marker);
          var times = e.target.domElement.children[0].getAttribute('data-times')
          console.log(times)
          if (that.startL == '') {
            that.startL = times
          } else {
            that.endL = times
          }
        })
 
        label.setStyle(labelStyle)
        that.map.addOverlay(label)
      }
 
      // 无数据时,缩放至该中心
      function showNoPoints() {
        that.map.centerAndZoom('昆山市', 17)
        setTimeout(function () {
          document.getElementById('cpm').style.display = 'block'
          document.getElementById('data').style.display = 'none'
        }, 250)
      }
 
      // 地图缩放级别监控
 
      that.map.addEventListener('zoomend', function () {
        // 这里根据缩放显示和隐藏文本
        var zoom = that.map.getZoom()
        $('span.my-maptip').parent()[zoom <= 15.5 ? 'hide' : 'show']()
        $('span.my-maptip')
          .parent()
          .css('font-size', 30 - zoom)
      })
 
      // var that = this
      function clickChange() {
        $('.carTop').on('click', () => {
          // console.log('点击了')
          that.view.removeAllLayers()
          that.map.clearOverlays()
          that.sensor = that.sensorKey
          that.viewType = that.viewKey
          draw(that.sensor, that.viewType)
          if (that.viewType === '2D') {
            that.map.setTilt(0)
            // drawLine()
            drawStartAndEnd()
            $('.sensorLevel').attr('src', '/img/pollutionlevel.png')
          } else if (that.viewType === '3D') {
            that.map.setTilt(52)
            if (that.sensor === 'a34004') {
              $('.sensorLevel').attr('src', '/img/pm25.png')
            } else if (that.sensor === 'a34002') {
              $('.sensorLevel').attr('src', '/img/pm10.png')
            } else if (that.sensor === 'a99054') {
              $('.sensorLevel').attr('src', '/img/tvoc.png')
            }
          }
        })
      }
      if (that.firstPlayFlag) {
        clickChange()
      }
    },
    changeCode(index) {
      this.changeColor = index
      // var pr = ''
      switch (index) {
        case 0:
          this.sensorKey = 'a34004'
          // this.bg = require('@/assets/images/tl_PM10.png')
          break
        case 1:
          this.sensorKey = 'a34002'
          // this.bg = require('@/assets/images/tl_PM2.5.png')
          break
        case 2:
          this.sensorKey = 'a21026'
          // this.bg = require('@/assets/images/tl_SO2.png')
          break
        case 3:
          this.sensorKey = 'a21004'
          // this.bg = require('@/assets/images/tl_NO2.png')
          break
        case 4:
          this.sensorKey = 'a21005'
          // this.bg = require('@/assets/images/tl_CO.png')
          break
        case 5:
          this.sensorKey = 'a05024'
          // this.bg = require('@/assets/images/tl_O3.png')
          break
        case 6:
          this.sensorKey = 'a99054'
          // this.bg = require('@/assets/images/tl_TVOCNew.png')
          break
        case 7:
          this.sensorKey = 'dustld'
          // this.bg = require('@/assets/images/tl_TVOCNew.png')
          break
      }
      this.initStart(this.carData)
    },
    changeCode1(index) {
      this.changeColor1 = index
      if (index === 0) {
        this.viewKey = '2D'
      } else {
        this.viewKey = '3D'
      }
      this.getStart()
    },
  },
}
</script>
<style lang="less" scoped>
body,
html,
#map_container {
  width: 100%;
  height: 100%;
  overflow: hidden;
  margin: 0;
  z-index: 0;
  font-size: 14px;
  font-family: '微软雅黑';
}
 
.main_body {
  border: 0;
  margin: 0;
  width: 100%;
  height: 100%;
  position: relative;
}
 
#cpm {
  width: 300px;
  height: 100px;
  position: absolute;
  background-color: #ffffff;
  display: none;
  left: 50%;
  top: 50%;
  margin-left: -150px;
  margin-top: -50px;
  z-index: 11;
  color: #000000;
  border: 2px solid #ff7f50;
  font-size: 28px;
  line-height: 100px;
  text-align: center;
}
 
.BMap_pop > img {
  top: 42px !important;
  margin-left: -10px;
}
 
.BMap_pop div:nth-child(1) div {
  display: none;
}
 
.BMap_pop div:nth-child(3) {
  display: none;
}
 
.BMap_pop div:nth-child(5) {
  display: none;
}
 
.BMap_pop div:nth-child(7) {
  display: none;
}
 
.BMap_pop div:nth-child(9) {
  top: 35px !important;
  border-radius: 5px;
}
 
#selectSenor {
  position: absolute;
  z-index: 1;
  left: 30px;
  top: 20px;
  font-size: 20px;
  background: lightgrey;
}
 
#type {
  position: absolute;
  z-index: 1;
  left: 30px;
  top: 50px;
  font-size: 20px;
  background: lightgrey;
}
 
button {
  font-size: 15px;
}
 
.sensorLevel {
  position: absolute;
  z-index: 1;
  bottom: 50px;
  left: 10px;
  width: 100px;
  height: 200px;
}
.carTop {
  position: absolute;
  top: 0;
  width: 100%;
  padding: 5px 10px;
  z-index: 999;
  background: rgba(204, 204, 204, 0.5);
  box-shadow: 1px 1px 5px #666;
}
.carTop > .left,
.right {
  padding: 5px 10px;
  border: 1px solid #aaa;
  border-right: none;
  background: #fff;
  cursor: pointer;
  font-size: 16px;
  float: left;
  margin-top: 4px;
  -webkit-transform-origin-x: 0;
}
.carTop .left:nth-child(1),
.carTop .right:nth-child(1) {
  border-radius: 5px 0 0 5px;
}
.carTop .left:nth-last-child(2),
.carTop .right:nth-child(2) {
  border-radius: 0 5px 5px 0;
  border-right: 1px solid #aaa;
}
 
.carTop {
  & > .left:nth-child(1) {
    border-radius: 5px 0 0 5px;
  }
}
.carTop {
  .left {
    &:nth-last-child(2) {
      margin-left: -12px !important;
    }
  }
}
.carTop > .left:hover,
.right:hover {
  background: rgb(64, 158, 255);
  color: #fff;
}
.carTop > .right {
  float: right;
}
.click {
  color: #fff;
  background-color: rgb(64, 158, 255) !important;
}
.noneData {
  position: absolute;
  color: #000;
  background: #fff;
  z-index: 999;
  left: 50%;
  top: 50%;
  transform: translate(-50%);
  padding: 20px 50px;
  font-size: 28px;
  border: 2px solid #ff7f50;
}
.main_body .el-date-editor .el-range-input {
  width: 30%;
}
.main_body /deep/ .el-date-editor .el-range-separator {
  width: 15%;
}
 
/deep/ .BMapLabel .my-maptip {
  display: block !important;
  width: inherit;
  height: inherit;
  text-align: center;
  vertical-align: middle;
}
.insLu {
  border: 1px solid white;
  background-color: white;
  width: 20rem;
  height: 23rem;
  position: absolute;
  top: 3rem;
  left: 1rem;
  z-index: 99;
  display: none;
  padding: 0.5rem;
}
.statspan {
  font-size: 0.5rem;
  margin-top: 2rem;
}
.insLu div {
  margin-top: 0.8rem;
}
</style>