TraficCanvas.vue 78.4 KB
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 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620
<template>
  <div class="modal-body">
    <div class="modal-lt">
      <button
        v-for="(item, index) in typeData"
        :class="{ curmodal: index == cindex }"
        @click="changeLayer(index)"
        :key="index"
      >
        {{ item }}
      </button>
    </div>
    <div class="modal-editbox">
      <div class="modal-lb" id="edit_list" v-if="drawState != -1">
        <!--<button>加载图片</button>-->
        <!--<button>修改保存路径</button>-->
        <!--<button>删除区域</button>-->
        <el-radio-group
          v-model="canvasState"
          @change="changeCanvasState"
          :disabled="needLine || needRect"
          v-show="drawState != 2"
        >
          <el-radio-button :label="1" class="editbtn">
            <i class="el-icon-circle-plus icon"></i>
          </el-radio-button>
          <el-radio-button :label="0" class="editbtn">
            <i class="el-icon-edit-outline"></i>
          </el-radio-button>
        </el-radio-group>
        <div v-if="!canvasState">
          <span
            @click="delShape"
            class="delbtn editbtn"
            v-show="drawState != '2'"
          >
            <i class="el-icon-delete icon"></i>
          </span>
          <el-select
            v-if="drawState == 1 && selectedShape"
            v-model="markLineType"
            @change="lineChange"
          >
            <el-option value="0" label="普通车道线"></el-option>
            <el-option value="7" label="白实线"></el-option>
            <el-option value="1" label="黄实线"></el-option>
            <el-option value="2" label="停止线"></el-option>
            <el-option value="3" label="左转判定线"></el-option>
            <el-option value="4" label="右转判定线"></el-option>
            <el-option value="5" label="直行判定线"></el-option>
            <el-option value="9" label="左转弯弧度判定线"></el-option>
          </el-select>
          <span v-if="drawState == 2 && selectedShape">导向类型</span>
          <el-select
            v-if="drawState == 2 && selectedShape"
            v-model="guidingtype"
          >
            <el-option value="0" label="直行车道"></el-option>
            <el-option value="1" label="左转车道"></el-option>
            <el-option value="2" label="右转车道"></el-option>
            <el-option value="3" label="直左混行"></el-option>
            <el-option value="4" label="直右混行"></el-option>
            <el-option value="5" label="左直右混行"></el-option>
          </el-select>
          <span v-if="drawState == 2 && selectedShape">使用类型</span>
          <el-select v-if="drawState == 2 && selectedShape" v-model="lanuse">
            <el-option value="0" label="普通车道"></el-option>
            <el-option value="1" label="公交车道"></el-option>
            <el-option value="2" label="应急车道"></el-option>
            <el-option value="3" label="非机动车道"></el-option>
            <el-option value="4" label="大货车禁行车道"></el-option>
            <el-option value="5" label="隔离带"></el-option>
          </el-select>
          <span v-if="drawState == 2 && selectedShape">方向</span>
          <el-select
            v-if="drawState == 2 && selectedShape"
            v-model="markLineDirect"
            placeholder="方向选择"
          >
            <el-option value="0" label="去向"></el-option>
            <el-option value="1" label="来向"></el-option>
            <el-option value="2" label="双向"></el-option>
          </el-select>
          <span v-if="drawState == 2 && selectedShape">车道号</span>
          <el-input
            type="number"
            placeholder="车道号"
            v-model="lineNum"
            min="1"
            v-if="
              ((drawState == 1 &&
                (markLineType == '0' ||
                  markLineType == '1' ||
                  markLineType == '7')) ||
                drawState == 2) &&
                selectedShape
            "
          ></el-input>
          <el-select
            name=""
            v-model="lightInfo.type"
            v-if="drawState == 3 && selectedShape"
          >
            <el-option value="1" label="左转灯"></el-option>
            <el-option value="2" label="直行灯"></el-option>
            <el-option value="3" label="左直灯"></el-option>
            <el-option value="4" label="右转灯"></el-option>
            <el-option value="6" label="右直灯"></el-option>
          </el-select>
          <el-select
            v-model="lightInfo.distribute"
            v-if="drawState == 3 && selectedShape"
          >
            <el-option value="1" label="单眼灯"></el-option>
            <el-option value="2" label="两眼灯"></el-option>
            <el-option value="3" label="三眼灯"></el-option>
          </el-select>
          <el-select
            name=""
            v-model="lightInfo.shap"
            v-if="drawState == 3 && selectedShape"
          >
            <el-option value="1" label="圆形"></el-option>
            <el-option value="2" label="箭头"></el-option>
            <el-option value="3" label="条形"></el-option>
          </el-select>
        </div>
        <div
          class=""
          v-if="
            !canvasState && (drawState == 6 || drawState == 7 || drawState == 8)
          "
        >
          <el-input
            v-model="polygon_id"
            disabled="disabled"
            type="text"
            class="w120"
            style="margin-top:10px"
            placeholder="区域ID"
          ></el-input>
          <el-input
            v-model="polygon_name"
            disabled="disabled"
            type="text"
            class="w120 mt10"
            placeholder="区域名称"
          ></el-input>
        </div>
        <div v-if="canvasState" sytle="textAlign:center">
          <!-- <button>撤销</button> -->
          <el-radio-group v-model="polyline" @change="polyChang">
            <div>
              <el-radio
                class="radio"
                :label="0"
                :style="lineRadioStyle"
                v-if="drawState == 1"
                >直线</el-radio
              >
            </div>
            <el-radio
              class="radio"
              :label="1"
              :style="lineRadioStyle"
              v-if="drawState == 1"
              >折线</el-radio
            >
          </el-radio-group>
        </div>
      </div>
    </div>
    <div class="modal-right">
      <div class="pic" id="pic"><img :src="bgUrl" id="bg" /></div>
      <div id="traficCanvas"></div>
    </div>
    <div class="clear"></div>
    <div id="line_type" class="littleModel BR active" v-if="smallWindow">
      <div>
        <p v-if="typeFlag == 1">线属性</p>
        <p v-if="typeFlag == 0">车道属性</p>
        <p v-if="typeFlag == 2">灯属性</p>
        <div class="item">
          <span v-if="typeFlag != 3">类型:</span>
          <div>
            <el-select v-if="typeFlag == 1" v-model="markLineType">
              <el-option value="0" label="普通车道线"></el-option>
              <el-option value="7" label="白实线"></el-option>
              <el-option value="1" label="黄实线"></el-option>
              <el-option value="2" label="停止线"></el-option>
              <el-option value="3" label="左转判定线"></el-option>
              <el-option value="4" label="右转判定线"></el-option>
              <el-option value="5" label="直行判定线"></el-option>
              <el-option value="9" label="左转弯弧度判定线"></el-option>
            </el-select>
            <el-select v-if="typeFlag == 0" v-model="markLineType">
              <el-option value="0" label="左转车道"></el-option>
              <el-option value="1" label="右转车道"></el-option>
              <el-option value="2" label="直行车道"></el-option>
              <el-option value="3" label="直左混行"></el-option>
              <el-option value="4" label="直右混行"></el-option>
              <el-option value="8" label="公交车道"></el-option>
              <el-option value="9" label="应急车道"></el-option>
              <el-option value="10" label="非机动车道"></el-option>
            </el-select>
            <el-select name="" v-model="lightInfo.type" v-if="typeFlag == 2">
              <el-option value="1" label="左转灯"></el-option>
              <el-option value="2" label="直行灯"></el-option>
              <el-option value="3" label="左直灯"></el-option>
              <el-option value="4" label="右转灯"></el-option>
              <el-option value="6" label="右直灯"></el-option>
            </el-select>
          </div>
        </div>
        <div
          class="item"
          v-if="
            (typeFlag == 1 &&
              (markLineType == '0' ||
                markLineType == '1' ||
                markLineType == '7')) ||
              drawState == 2
          "
        >
          <span>序号:</span>
          <div>
            <el-input type="number" v-model="lineNum" min="1"></el-input>
          </div>
        </div>
        <div v-if="typeFlag == 2" class="lightInfo item">
          <span>灯眼模式:</span>
          <div>
            <el-select v-model="lightInfo.distribute">
              <el-option value="1" label="单眼灯"></el-option>
              <el-option value="2" label="两眼灯"></el-option>
              <el-option value="3" label="三眼灯"></el-option>
            </el-select>
          </div>
        </div>
        <div v-if="typeFlag == 2" class="item">
          <span>形状:</span>
          <div>
            <el-select name="" v-model="lightInfo.shap">
              <el-option value="1" label="圆形"></el-option>
              <el-option value="2" label="箭头"></el-option>
              <el-option value="3" label="条形"></el-option>
            </el-select>
          </div>
        </div>
        <LightCanvas v-if="typeFlag == 3" ref="lightCanvas"></LightCanvas>
      </div>
      <div v-if="typeFlag != 3">
        <button @click="lineTypeCancel">取消</button>
        <button @click="lightLast" v-if="typeFlag == 2">上一步</button>
        <button @click="lineTypeBtn">确定</button>
      </div>
      <div v-if="typeFlag == 3">
        <button @click="lineTypeCancel">取消</button>
        <button @click="childCancle" v-if="lightCancle">撤销</button>
        <button @click="lightNext" v-if="lightNextBtn">下一步</button>
      </div>
    </div>
    <div class="pedestrian-area-attr BR" v-if="curLayerstate">
      <div class="mt40">
        <span class="label">ID号:</span>
        <input type="text" v-model="polygon_id" />
      </div>
      <div class="mt10">
        <span class="label">名称:</span>
        <input type="text" v-model="polygon_name" />
      </div>
      <div class="btn-box mt40">
        <button @click="bicyEnter">确定</button>
        <button @click="curlayCancel">取消</button>
      </div>
    </div>
  </div>
</template>
<script>
import LightCanvas from "./LightCanvas";
export default {
  name: "zoneSetting",
  data() {
    return {
      color: [
        "222,50,212",
        "24,0,254",
        "0,254,137",
        "255,255,0",
        "138,43,226",
        "241,31,8",
        "31,151,181",
        "3,65,76",
        "12,222,235",
        "12,222,235"
      ], //线颜色
      typeData: [
        "预览",
        "车牌检测区域",
        "车道标志线",
        "车道属性",
        "红绿灯区域",
        "对向车道",
        "违停区域",
        "行人检测区域",
        "行人密度区域",
        "异物检测区域",
        
      ],
      cindex: 0,
      //laneMark:false,
      drawState: -1, //配置项类型
      lineRadioStyle: {
        color: "#fff",
        width: "40px",
        margin: "10px 15px"
      },
      istest:false,
      canvasState: 0, //控制编辑/添加
      polyline: 0, //控制直线/折线
      smallWindow: false, //控制属性弹窗
      lightCancle: false, //控制属性弹窗是否显示撤销按钮
      lightNextBtn: false, //控制属性弹窗是否显示下一步按钮
      roadFlag: "", //标记车道线是否有修改
      needRect: false, //标记是否处于划矩形状态
      needLine: false, //标记是否处于划线状态
      lightShootState: 0, //标记选择灯区域截图起止方式,用于放大图片
      layers: [], //用于记录各个配置项的图层
      blueLines: [], //记录用于连接车道的车道线
      greenLines: [], //记录车道中线箭头
      roads: [],
      selectedShape: null, //当前选中图形
      typeFlag: 1, //选择属性弹窗状态
      lineNum: 1, //车道线/车道序号
      curLayerstate: false, //行人检测区域属性设置
      testLayerstate: false, //测试检测区域属性设置
      polygon_id: "", //行人检测区域id
      polygon_name: "", //行人检测区域name
      markLineType: "0",
      lanuse: "0", //车道属性类型
      guidingtype: "", //车道导向类型
      markLineDirect: "",
      childUrl: "", //红绿灯区域截图
      scale: {}, //红绿灯区域截图放大倍数
      lightInfo: {
        type: "1",
        distribute: "1",
        shap: "1",
        delay: 3
      },
      roiBody: {},
      XMLStr: "",
      eventData: []
    };
  },
  props: ["bgUrl"],
  components: {
    LightCanvas
  },
  methods: {
    stageInit: function(params) {
      console.log("init1");
      this.drawState = -1;
      this.stage = new Kinetic.Stage({
        container: "traficCanvas", //<div>的id
        width: 800, //创建的舞台宽度
        height: 500 //创建的舞台高度
      });
      this.shadowLayer = new Kinetic.Layer({
        id: "shadowLayer"
      });
      this.testLayer = new Kinetic.Layer({
        id: "testLayer",
        name: "layer"
      });
      this.lineLayer = new Kinetic.Layer({
        id: "lineLayer",
        name: "layer"
      });
      this.roadLayer = new Kinetic.Layer({
        id: "roadLayer",
        name: "layer"
      });
      this.lightLayer = new Kinetic.Layer({
        id: "lightLayer",
        name: "layer"
      });
      this.subtendLayer = new Kinetic.Layer({
        id: "subtendLayer",
        name: "layer"
      });
      this.noStopLayer = new Kinetic.Layer({
        id: "noStopLayer",
        name: "layer"
      });
      this.bicyLayer = new Kinetic.Layer({
        //行人检测区域
        id: "bicyLayer",
        name: "layer"
      });
      this.densityLayer = new Kinetic.Layer({
        //密度
        id: "densityLayer",
        name: "layer"
      });
      this.foreignLayer = new Kinetic.Layer({
        //异物
        id: "foreignLayer",
        name: "layer"
      });
      this.testRegionLayer = new Kinetic.Layer({
        //测试检测区域
        id: "testRegionLayer",
        name: "layer"
      });

      let shadow = new Kinetic.Rect({
        x: 0, //矩形左上角x坐标
        y: 0, //矩形左上角y坐标
        width: 800, //矩形的宽度
        height: 500, //矩形的高度
        fill: "rgba(255,255,255,.2)", //矩形的填充色
        stroke: "black", //矩形边缘线的颜色
        strokeWidth: 3 //矩形边缘线的宽度
      });
      let that = this;
      this.stage.on("click", function(evt) {
        that.stageClick(evt);
      });
      this.stage.on("dblclick", function(evt) {
        if (that.polyline) {
          let pos = {
            x: evt.evt.offsetX,
            y: evt.evt.offsetY
          };
          that.lineStop(that.layers[1], pos);
          that.smallWindow = true;
        }
      });
      this.stage.on("mousemove", function(evt) {
        that.stageMouseMove(evt);
      });
      this.shadowLayer.add(shadow);
      this.stage.add(this.shadowLayer);
      this.stage.add(this.testLayer);
      this.stage.add(this.lineLayer);
      this.stage.add(this.roadLayer);
      this.stage.add(this.lightLayer);
      this.stage.add(this.bicyLayer);
      this.stage.add(this.subtendLayer);
      this.stage.add(this.noStopLayer);
      this.stage.add(this.densityLayer);
      this.stage.add(this.foreignLayer);
      this.stage.add(this.testRegionLayer);
      this.layers = [
        this.testLayer,
        this.lineLayer,
        this.roadLayer,
        this.lightLayer,
        this.subtendLayer,
        this.noStopLayer,
        this.bicyLayer,
        this.densityLayer,
        this.foreignLayer,
        this.testRegionLayer
      ];
    },
    //还原配置
    configInit: function(xml) {
      let obj = this.oParse.parseXML(xml).roi;
      let that = this;
      console.log(obj);
      //检测区域
      // console.log(obj)
      let testAry = obj.flow_roi.flow_region.point;
      let testRect = [];
      try {
        testAry.forEach((ele, index) => {
          testRect.push(ele.x * 800);
          testRect.push(ele.y * 500);
        });
        let line = this.drawRect("morePoints", testRect, this.color[0]);
        this.testLayer.add(line);
      } catch (error) {
        console.log(error);
      }
      //车道线
      try {
        console.log(obj.lane_line);
        let normalLines = obj.lane_line.line;
        if (!normalLines.length) {
          normalLines = [normalLines];
        }
        normalLines.forEach(ele => {
          let points = ele.points.point;
          let lineType = ele.line_type;
          let color = "24,0,254";
          console.log(lineType);
          if (lineType == 1) {
            color = "255,255,0";
          } else if (lineType == 2) {
            color = "255,0,0";
          } else if (lineType == 7) {
            color = "255,255,255";
          } else if (
            lineType == 3 ||
            lineType == 4 ||
            lineType == 5 ||
            lineType == 9
          ) {
            color = "0,255,0";
          }
          let ary = [];
          for (let i = 0; i < points.length; i++) {
            ary.push(points[i].x * 800);
            ary.push(points[i].y * 500);
          }
          let line = this.drawLine("morePoints", ary, color);
          line.line_type = ele.line_type;
          if (
            line.line_type == 0 ||
            line.line_type == 1 ||
            line.line_type == 7
          ) {
            this.blueLines.push(line);
          }
          this.lineLayer.add(line);
        });
      } catch (e) {
        //TODO handle the exception
        console.log(e);
      }
      debugger
      //车道和行人
      if (obj.median_lines.lane_count > 0) {
        let ary = obj.median_lines.lane;
        if (!ary.length) {
          ary = [ary];
        }
        try {
          ary.forEach((ele, index) => {
            // if (ele.lane_type == "12") {
            //   let points = [];
            //   ele.lane_polygon.point.forEach((ele, index) => {
            //     points.push(ele.x * 800);
            //     points.push(ele.y * 500);
            //   });
            //   let rect = this.drawRect("morePoints", points, this.color[4]);
            //   this.bicyLayer.add(rect);
            // } else
            if (ele.lane_type == "11") {
              let points = [];
              ele.lane_polygon.point.forEach((ele, index) => {
                points.push(ele.x * 800);
                points.push(ele.y * 500);
              });
              let rect = this.drawRect("morePoints", points, this.color[5]);
              this.subtendLayer.add(rect);
            } else {
              let points = ele.line.point;
              let group = new Kinetic.Group({ name: "arr" });
              let line = this.drawLine(
                { x: points[0].x * 800, y: points[0].y * 500 },
                { x: points[1].x * 800, y: points[1].y * 500 },
                this.color[2]
              );
              this.greenLines[ele.lane_seq - 1] = line;
              let cPoints, direct;
              if (points[0].y < points[1].y) {
                cPoints = [
                  points[0].x * 800,
                  points[0].y * 500,
                  points[1].x * 800,
                  points[1].y * 500
                ];
                direct = "1";
              } else {
                cPoints = [
                  points[1].x * 800,
                  points[1].y * 500,
                  points[0].x * 800,
                  points[0].y * 500
                ];
                direct = "0";
              }
              this.drawArrow(
                [points[0].x * 800, points[0].y * 500],
                [points[1].x * 800, points[1].y * 500],
                30,
                20,
                3,
                this.color[2],
                this.roadLayer,
                group,
                line
              );
              let arrs = this.roadLayer.get(".arr");
              let arr = arrs[arrs.length - 1];
              line.index = ele.lane_no;
              let lane_guid_type = 0;
              let lane_use = 0;
              if (obj.lanes.lane_count == 1) {
                lane_guid_type = obj.lanes.lane.lane_guiding_type;
                lane_use = obj.lanes.lane.lane_use_type;
              } else {
                lane_guid_type = obj.lanes.lane[index].lane_guiding_type;
                lane_use = obj.lanes.lane[index].lane_use_type;
              }
              this.roads[parseInt(ele.lane_seq - 1)] = {
                type: ele.lane_type,
                index: ele.lane_no,
                direct: direct,
                lane_guiding_type: lane_guid_type,
                lane_use_type: lane_use
              };
            }
          });
        } catch (error) {
          console.log(error);
        }
      }
      //红绿灯
      try {
        let ary = obj.lights.light;
        if (!ary.length) {
          ary = [ary];
        }
        ary.forEach((ele, index) => {
          let points = ele.light_regions.light_region;
          let left = points.left * 800;
          let top = points.top * 500;
          let right = points.right * 800;
          let bottom = points.bottom * 500;
          let pointsAry = [left, top, left, bottom, right, bottom, right, top];
          let rect = this.drawRect("morePoints", pointsAry, this.color[3]);

          let linghtRoi = {
            light_region_seq: 1,
            top: (top / 500).toFixed(6),
            right: (right / 800).toFixed(6),
            bottom: (bottom / 500).toFixed(6),
            left: (left / 800).toFixed(6)
          };
          (rect.light_seq = index + 1),
            (rect.light_type = ele.light_type),
            (rect.light_distribute = ele.light_distribute),
            (rect.light_shape = ele.light_shape),
            (rect.light_delay =
              ele.light_yellow_delay || ele.light_yellow_interval),
            (rect.light_regions = {
              light_region_count: 1,
              light_region: linghtRoi
            });
          this.lightLayer.add(rect);
        });
      } catch (error) {
        console.log(error);
      }

      //违停区域
      let noStopAry = obj.no_stop_region.no_stop_polygon;
      console.log(noStopAry);
      try {
        if (!noStopAry.length) {
          noStopAry = [noStopAry];
        }
        noStopAry.forEach(ele => {
          let points = ele.point;
          let noStopRect = [];
          for (let i = 0; i < points.length; i++) {
            const point = points[i];
            noStopRect.push(point.x * 800);
            noStopRect.push(point.y * 500);
          }
          let line = this.drawRect("morePoints", noStopRect, this.color[5]);
          this.noStopLayer.add(line);
        });
      } catch (error) {
        console.log(error);
      }
      //行人检测区域
      try {
        let bicyarr = obj.pedestrian_detection_region.polygon;
        if (!bicyarr.length) {
          bicyarr = [bicyarr];
        }
        bicyarr.forEach(ele => {
          let points = ele.point;
          let bicRect = [];
          for (let i = 0; i < points.length; i++) {
            const point = points[i];
            bicRect.push(point.x * 800);
            bicRect.push(point.y * 500);
          }
          let rect = this.drawRect("morePoints", bicRect, this.color[6]);
          rect.polygon_name = ele.polygon_name;
          rect.polygon_id = ele.polygon_id;
          this.bicyLayer.add(rect);
        });
      } catch (error) {
        console.log(error);
      }
      //行人密度区域
      try {
        let densityarr = obj.pedestrian_density_region.polygon;
        if (!densityarr.length) {
          densityarr = [densityarr];
        }
        densityarr.forEach(ele => {
          let points = ele.point;
          let densityRect = [];
          for (let i = 0; i < points.length; i++) {
            const point = points[i];
            densityRect.push(point.x * 800);
            densityRect.push(point.y * 500);
          }
          let rect = this.drawRect("morePoints", densityRect, this.color[7]);
          rect.polygon_name = ele.polygon_name;
          rect.polygon_id = ele.polygon_id;
          this.densityLayer.add(rect);
        });
      } catch (error) {
        console.log(error);
      }
      //异物检测区域
      try {
        let foreignarr = obj.foreign_detection_region.polygon;
        if (!foreignarr.length) {
          foreignarr = [foreignarr];
        }
        foreignarr.forEach(ele => {
          let points = ele.point;
          let foreignRect = [];
          for (let i = 0; i < points.length; i++) {
            const point = points[i];
            foreignRect.push(point.x * 800);
            foreignRect.push(point.y * 500);
          }
          let rect = this.drawRect("morePoints", foreignRect, this.color[8]);
          rect.polygon_name = ele.polygon_name;
          rect.polygon_id = ele.polygon_id;
          this.foreignLayer.add(rect);
        });
      } catch (error) {
        console.log(error);
      }
      //测试检测区域
      try {
        let testarr = obj.test_result_region.polygon;
        if (!testarr.length) {
          testarr = [testarr];
        }
        testarr.forEach(ele => {
          let points = ele.point;
          let bicRect = [];
          for (let i = 0; i < points.length; i++) {
            const point = points[i];
            bicRect.push(point.x * 800);
            bicRect.push(point.y * 500);
          }
          let rect = this.drawRect("morePoints", bicRect, this.color[9]);
          rect.polygon_name = ele.polygon_name;
          rect.polygon_id = ele.polygon_id;
          this.testRegionLayer.add(rect);
        });
      } catch (error) {
        console.log(error);
      }

      this.selectedShape = null;
      this.drawRoad();
      console.log(this.stage);
      this.stage.draw();
    },
    //切换编辑、添加状态
    changeCanvasState: function() {
      if (this.canvasState) {
        this.cancleSelectedGroup();
      }
      if (this.drawState == 1) {
        this.lineNum = this.blueLines.length + 1;
      } else if (this.drawState == 2) {
        this.lineNum = this.roads.length + 1;
      }
      this.selectedShape = null;
      this.markLineType = "0";
      this.lightInfo.type = "1";
    },
    //切换配置项
    changeLayer: function(index) {
      this.cindex = index;
      if (this.needRect || this.needLine) {
        let shape = this.needRect ? "区域" : "线段";
        this.$message({
          type: "error",
          message: "当前" + shape + "配置未完成"
        });
        return;
      }
      if (this.smallWindow) {
        this.$message({
          type: "error",
          message: "当前属性配置未完成"
        });
        return;
      }
      this.layers.forEach(ele => {
        ele.setVisible(false);
      });
      if (this.drawState != -1) {
        this.cancleSelectedGroup();
      }
      this.canvasState = 0;
      this.polyline = 0;
      this.polygon_name = "";
      this.polygon_id = "";
      var e = e || window.event;

      switch (index - 1) {
        case -1:
          this.layers.forEach(ele => {
            ele.setVisible(true);
          });
          this.drawRoad();
          this.stage.draw();
          break;
        case 1:
          this.typeFlag = 1;
          this.lineNum = this.blueLines.length + 1 || 1;
          break;
        case 2:
          this.typeFlag = 0;
          this.drawRoad();
          break;
      }
      this.drawState = index - 1;
      // this.layers[this.drawState].moveToTop()

      if (index) {
        console.log(this.drawState);
        this.layers[this.drawState].setVisible(true);
        this.layers[this.drawState].draw();
      }
    },
    //切换直线/折线
    polyChang: function() {
      if (this.polyline) {
        this.markLineType = "9";
      } else {
        this.markLineType = "0";
      }
    },
    //点击配置区域
    stageClick: function(evt) {
      if (this.drawState == -1) {
        this.$message({
          type: "info",
          message: "预览模式下无法操作!"
        });
        return;
      }
      if (this.canvasState) {
        //点中空白区域添加图形
        if (this.smallWindow) return;
        this.addShape(evt);
      } else {
        //点击图形选中
        this.cancleSelectedGroup();
        if (evt.target.className != "Rect") {
          let tar = evt.target;
          if (this.drawState == "2" && tar.attrs.name != "rect") {
            return;
          }
          this.makeSelectedGroup(tar);
        }
      }
    },
    //添加图形
    addShape: function(evt) {
      let pos = {
        x: evt.evt.offsetX,
        y: evt.evt.offsetY
      };
      let layer = this.layers[this.drawState];
      switch (this.drawState) {
        case 0:
          let testRects = layer.get(".rect");
          if (testRects.length && !this.needRect) {
            this.$message({
              type: "error",
              message: "只允许设置一个车牌检测区域"
            });
            return;
          }

          if (this.needRect) {
            this.endChangeShape(evt);
          } else {
            this.needRect = true;
            this.startChangeShape(pos, layer, this.color[this.drawState]);
          }
          break;
        case 1:
          if (this.roadFlag) {
            this.roadFlag = false;
          }
          this.startChangeShape(pos, layer, this.color[this.drawState]);
          break;
        case 3:
          if (this.needRect) {
            this.endChangeShape(evt);
          } else {
            this.needRect = true;
            this.startChangeShape(pos, layer, this.color[this.drawState]);
          }
          break;
        case 4:
          if (this.needRect) {
            this.endChangeShape(evt);
          } else {
            this.needRect = true;
            this.startChangeShape(pos, layer, this.color[this.drawState]);
          }
          break;
        case 6:
          let rects = layer.get(".rect");
          if (rects.length > 1 && !this.needRect) {
            this.$message({
              type: "error",
              message: "只允许设置两个行人检测区域"
            });
            return;
          }
          if (this.needRect) {
            this.endChangeShape(evt);
          } else {
            this.needRect = true;
            this.startChangeShape(pos, layer, this.color[this.drawState]);
          }
          break;
        case 5:
          if (this.needRect) {
            this.endChangeShape(evt);
          } else {
            this.needRect = true;
            this.startChangeShape(pos, layer, this.color[this.drawState]);
          }
          break;
        case 7:
          if (this.needRect) {
            this.endChangeShape(evt);
          } else {
            this.needRect = true;
            this.startChangeShape(pos, layer, this.color[this.drawState]);
          }
          break;
        case 8:
          if (this.needRect) {
            this.endChangeShape(evt);
          } else {
            this.needRect = true;
            this.startChangeShape(pos, layer, this.color[this.drawState]);
          }
          break;
        case 9:
          if (this.needRect) {
            this.endChangeShape(evt);
          } else {
            this.needRect = true;
            this.startChangeShape(pos, layer, this.color[this.drawState]);
          }
          break;
        default:
          break;
      }
    },
    //改变选中图形样式
    makeSelectedGroup: function(shape) {
      console.log(shape);
      let points = shape.attrs.points;
      let lineType = shape.line_type;
      let color = this.color[this.drawState];
      if (this.drawState == 2) {
        this.lineNum = this.roads[shape.roadIndex].index;
        this.markLineType = this.roads[shape.roadIndex].type;
        this.markLineDirect = this.roads[shape.roadIndex].direct;
        this.guidingtype = this.roads[shape.roadIndex].lane_guiding_type;
        this.lanuse = this.roads[shape.roadIndex].lane_use_type || "0";
        shape.setFill("rgba(" + this.color[1] + ",0.3)");
        let gLine = this.greenLines[shape.roadIndex];
        if (gLine.getParent().attrs.name == "arr") {
          gLine.getParent().destroy();
          this.roadLayer.add(gLine);
        }
      } else {
        if (this.drawState == 1) {
          let index = this.blueLines.indexOf(shape);
          if (lineType == 0) {
            color = "0,0,255";
          } else if (lineType == 1) {
            color = "255,255,0";
          } else if (lineType == 2) {
            color = "255,0,0";
          } else if (lineType == 7) {
            color = "255,255,255";
          } else {
            color = "0,255,0";
          }
          if (index > -1) {
            this.blueLines.splice(index, 1);
          } else {
            index = this.blueLines.length;
          }
          this.lineNum = index + 1;
        }
        for (let i = 0; i < points.length; i += 2) {
          const pos = {
            x: points[i],
            y: points[i + 1]
          };
          let cir = this.drawCircle(pos, color, 5);
          this.layers[this.drawState].add(cir);
        }
      }
      if (this.drawState == 1) {
        this.markLineType = shape.line_type;
      } else if (this.drawState == 3) {
        this.lightInfo = {
          type: shape.light_type,
          shap: shape.light_shape,
          distribute: shape.light_distribute,
          delay: shape.light_delay
        };
      } else if (
        this.drawState == 6 ||
        this.drawState == 7 ||
        this.drawState == 8
      ) {
        this.polygon_name = shape.polygon_name;
        this.polygon_id = shape.polygon_id;
      }
      this.selectedShape = shape;

      this.layers[this.drawState].draw();
    },
    //取消选中图形样式
    cancleSelectedGroup: function(isdel) {
      if (!this.selectedShape) return;
      let cirs = this.layers[this.drawState].get(".circle");
      for (let i = 0; i < cirs.length; i++) {
        const cir = cirs[i];
        cir.destroy();
      }
      if (this.drawState == 1) {
        if (
          (this.markLineType == "0" ||
            this.markLineType == "1" ||
            this.markLineType == "7") &&
          !isdel
        ) {
          this.blueLines.splice(this.lineNum - 1, 0, this.selectedShape);
          this.lineNum++;
          this.roadFlag = false;
        }
        this.selectedShape.line_type = this.markLineType;
      } else if (this.drawState == 2) {
        console.log(this.selectedShape);
        let road = this.roads[this.selectedShape.roadIndex];
        road.type = this.markLineType;
        road.index = this.lineNum;
        road.lane_use_type = this.lanuse;
        road.lane_guiding_type = this.guidingtype;
        this.selectedShape.setFill("rgba(255,255,255,0)");
        if (this.markLineDirect != undefined) {
          road.direct = this.markLineDirect;
          road.cPoints = this.sortLinePoints(road.cPoints);
          let points;
          if (this.markLineDirect == "0") {
            points = [
              road.cPoints[2],
              road.cPoints[3],
              road.cPoints[0],
              road.cPoints[1]
            ];
          } else {
            points = road.cPoints;
          }

          let line = this.greenLines[this.selectedShape.roadIndex];
          let group = new Kinetic.Group({ name: "arr" });
          this.drawArrow(
            [points[0], points[1]],
            [points[2], points[3]],
            30,
            20,
            3,
            this.color[2],
            this.roadLayer,
            group,
            line
          );
        }
      } else if (this.drawState == 3) {
        this.selectedShape.light_type = this.lightInfo.type;
        this.selectedShape.light_shape = this.lightInfo.shap;
        this.selectedShape.light_distribute = this.lightInfo.distribute;
        this.selectedShape.light_delay = this.lightInfo.delay;
      }

      this.selectedShape = null;
      this.markLineType = "0";
      this.lightInfo = {
        type: "1",
        distribute: "1",
        shap: "1",
        delay: 3
      };
      this.layers[this.drawState].draw();
    },
    //开始绘制图形(第一次点击)
    startChangeShape: function(pos, layer, col) {
      let ary = layer.get(".circle");
      if (
        this.drawState == 0 ||
        this.drawState == 3 ||
        this.drawState == 4 ||
        this.drawState == 5 ||
        this.drawState == 6 ||
        this.drawState == 7 ||
        this.drawState == 8 ||
        this.drawState == 9
      ) {
        let rect = this.drawRect(pos, pos, col);
        rect.moveToBottom();
        layer.add(rect);
      } else {
        if (ary.length == 0 && !this.needLine) {
          let circle = this.drawCircle(pos, "rgba(255,255,255,.2)");
          layer.add(circle);
          this.needLine = true;
          let line = this.drawLine(pos, pos, col);
          this.selectedShape = line;
          layer.add(line);
        } else {
          if (this.polyline) {
            let lines = layer.get(".line");
            let lastLine = lines[lines.length - 1];
            let points = lastLine.attrs.points;
            if (points.length >= 4) {
              points.push(pos.x);
              points.push(pos.y);
            }
            lastLine.attrs.points = points;
          } else {
            this.lineStop(layer, pos);
            this.smallWindow = true;
          }
        }
      }
      layer.draw();
    },
    //鼠标移动生成线、矩形
    stageMouseMove: function(evt) {
      if (!this.needLine && !this.needRect) return;
      let pos = {
        x: evt.evt.offsetX,
        y: evt.evt.offsetY
      };
      let layer = this.layers[this.drawState];
      if (this.needLine) {
        let lines;
        if (this.drawState == 2) {
          lines = layer.get(".centerLine");
        } else {
          lines = layer.get(".line");
        }
        let points = lines[lines.length - 1].attrs.points;
        points[points.length - 2] = pos.x;
        points[points.length - 1] = pos.y;
      } else if (this.needRect) {
        let rects = layer.get(".rect");
        let rect = rects[rects.length - 1];
        rect.moveToBottom();
        rect.attrs.points[3] = pos.y;
        rect.attrs.points[4] = pos.x;
        (rect.attrs.points[5] = pos.y), pos;
        rect.attrs.points[6] = pos.x;
      }
      layer.draw();
    },
    //结束一个图形配置
    endChangeShape: function(evt) {
      evt.cancelBubble = true;
      if (!this.needRect) return;
      this.needRect = false;
      if (this.drawState == 3) {
        //车道属性
        debugger
        let layer = this.layers[this.drawState];
        let rects = layer.get(".rect");
        let rect = rects[rects.length - 1];
        let points = rect.attrs.points;
        let canvas = document.createElement("canvas");
        let img = document.getElementById("pic").childNodes[0];
        console.log(img);
        let w = Math.abs(points[0] - points[4]);
        let h = Math.abs(points[1] - points[5]);
        this.scale = {
          x: 200 / w,
          y: 200 / h
        };
        console.log(this.scale);
        canvas.width = w;
        canvas.height = h;
        if (points[0] - points[4] > 0 && points[1] - points[5] > 0) {
          this.lightShootState = 2;
          canvas
            .getContext("2d")
            .drawImage(img, points[4], points[5], w, h, 0, 0, w, h);
        } else if (points[0] - points[4] > 0 && points[1] - points[5] < 0) {
          this.lightShootState = 3;
          canvas
            .getContext("2d")
            .drawImage(img, points[6], points[7], w, h, 0, 0, w, h);
        } else if (points[0] - points[4] < 0 && points[1] - points[5] > 0) {
          this.lightShootState = 1;
          canvas
            .getContext("2d")
            .drawImage(img, points[2], points[3], w, h, 0, 0, w, h);
        } else if (points[0] - points[4] < 0 && points[1] - points[5] < 0) {
          this.lightShootState = 0;
          canvas
            .getContext("2d")
            .drawImage(img, points[0], points[1], w, h, 0, 0, w, h);
        }
        console.log(this.lightShootState);
        this.typeFlag = 3;
        // this.lineTypeShow()
        this.smallWindow = true;

        let that = this;
        this.childUrl = canvas.toDataURL("image/webp");
        setTimeout(function() {
          that.$refs.lightCanvas.bgUrl = that.childUrl;
          that.$refs.lightCanvas.imgSize(w, h);
        }, 0);
        layer.draw();
      }
      if (this.drawState == 6 || this.drawState == 7 || this.drawState == 8) {
        this.curLayerstate = true;
      }
      if (this.drawState == 9) {
        this.testLayerstate = true;
      }
    },
    lineChange: function name() {
      let color = "blue";
      if (this.markLineType == 1) {
        color = "yellow";
      } else if (this.markLineType == 2) {
        color = "red";
      } else if (this.markLineType == 7) {
        color = "white";
      } else if (
        this.markLineType == 3 ||
        this.markLineType == 4 ||
        this.markLineType == 5 ||
        this.markLineType == 9
      ) {
        color = "rgb(0,255,0)";
      }
      this.selectedShape.attrs.stroke = color;

      this.lineLayer.draw();
    },
    lineStop: function(layer, pos) {
      this.needLine = false;
      let start = layer.get(".circle")[0];
      let x = start.attrs.x;
      let y = start.attrs.y;
      start.destroy();

      if (this.drawState == 2) {
        let group = new Kinetic.Group({
          name: "arr"
        });
        let lines = layer.get(".centerLine");
        let line = lines[lines.length - 1];

        this.drawArrow(
          [x, y],
          [pos.x, pos.y],
          30,
          20,
          3,
          this.color[2],
          layer,
          group,
          line
        );
      } else {
        layer.draw();
      }
    },
    //行人检测信息/异物检测信息/测试检测区域
    bicyEnter() {
      let curLayers = this.layers[this.drawState].get(".rect");
      let curlay = curLayers[curLayers.length - 1];
      curlay.polygon_id = this.polygon_id;
      curlay.polygon_name = this.polygon_name;
      this.curLayerstate = false;
      //测试区域弹窗
      this.testLayerstate = false;
      //清空输入框
      this.polygon_id = "";
      this.polygon_name = "";
    },
    curlayCancel() {
      let curLayers = this.layers[this.drawState].get(".rect");
      let curlay = curLayers[curLayers.length - 1];
      curlay.destroy();
      console.log(curlay);
      this.selectedShape = null;
      this.cancleSelectedGroup();
      this.layers[this.drawState].draw();
      this.curLayerstate = false;
      //测试区域弹窗
      this.testLayerstate = false;
      //清空输入框
      this.polygon_id = "";
      this.polygon_name = "";
    },
    //画圆
    drawCircle: function(pos, col, r) {
      let size = r || 2;
      let circle = new Kinetic.Circle({
        x: pos.x,
        y: pos.y,
        fill: "rgb(" + col + ")",
        radius: size,
        name: "circle",
        draggable: true
      });

      circle.on("dragmove", evt => {
        if (this.canvasState) return;
        evt.cancelBubble = true;
        this.changeRect(evt);
      });

      return circle;
    },
    //画线
    drawLine: function(start, end, col, width) {
      let points;
      if (start === "morePoints") {
        points = end;
      } else {
        points = [start.x, start.y, end.x, end.y];
      }
      let name = "line";
      let size = width || 4;
      if (this.drawState == 2 && this.needLine) {
        name = "centerLine";
      }
      let line = new Kinetic.Line({
        x: 0,
        points: points,
        tension: 0,
        closed: false,
        stroke: "rgb(" + col + ")",
        strokeWidth: size,
        name: name
      });
      return line;
    },
    //画矩形
    drawRect: function(start, end, color, boo) {
      let points,
        isFill = true;
      if (boo == false) {
        isFill = boo;
      }
      if (start === "morePoints") {
        points = end;
      } else {
        points = [
          start.x,
          start.y,
          start.x,
          end.y,
          end.x,
          end.y,
          end.x,
          start.y
        ];
      }
      let rect = new Kinetic.Line({
        x: 0,
        points: points,
        // tension: 0.5,
        closed: true,
        dashEnabled: true,
        dash: ["8"],
        stroke: "rgb(" + color + ")",
        strokeWidth: 2,
        name: "rect",
        fill: isFill ? "rgba(" + color + ",0.3)" : "transparent"
      });
      return rect;
    },
    //改变矩形
    changeRect: function(evt) {
      let rects = evt.target.getParent().get(".rect");
      let cirs = evt.target.getParent().get(".circle");
      let points = [];
      cirs.forEach(ele => {
        points.push(ele.attrs.x);
        points.push(ele.attrs.y);
      });

      this.selectedShape.attrs.points = points;
      this.layers[this.drawState].draw();
    },
    //删除图形
    delShape: function() {
      if (!this.selectedShape) {
        return;
      }
      switch (this.drawState) {
        case 1:
          if (
            this.selectedShape.line_type != 0 &&
            this.selectedShape.line_type != 1 &&
            this.selectedShape.line_type != 7
          ) {
            let index = this.blueLines.indexOf(this.selectedShape);
            this.blueLines.splice(index, 1);
            this.lineNum = this.blueLines.length + 1;
          }
          this.roadFlag = false;
          break;
        case 2:
          // eslint-disable-next-line no-case-declarations
          let rindex = this.roads.indexOf(this.selectedShape);
          console.log(rindex);
          this.roads[rindex] = "";
          break;
        case 6:
          this.polygon_name = "";
          this.polygon_id = "";
        // eslint-disable-next-line no-fallthrough
        default:
          break;
      }
      this.selectedShape.destroy();
      this.cancleSelectedGroup(true);
      this.selectedShape = null;
    },
    //选择线/区域属性弹窗
    lineTypeCancel: function() {
      if (this.drawState == 3) {
        let rects = this.lightLayer.get(".rect");
        let rect = rects[rects.length - 1];
        rect.destroy();
      } else {
        this.selectedShape.destroy();
      }
      this.selectedShape = null;
      this.cancleSelectedGroup();
      this.layers[this.drawState].draw();
      this.smallWindow = false;
    },
    lineTypeBtn: function() {
      this.smallWindow = false;
      let layer = this.layers[this.drawState];
      if (this.typeFlag == 1) {
        let lines = layer.get(".line");
        let line = lines[lines.length - 1];
        let color = "blue";
        line.line_type = this.markLineType;

        if (this.markLineType == 1) {
          color = "yellow";
        } else if (this.markLineType == 2) {
          color = "red";
        } else if (this.markLineType == 7) {
          color = "white";
        } else if (
          this.markLineType == 3 ||
          this.markLineType == 4 ||
          this.markLineType == 5 ||
          this.markLineType == 9
        ) {
          color = "rgb(0,255,0)";
        }
        line.attrs.stroke = color;

        layer.draw();
        if (
          this.markLineType == "0" ||
          this.markLineType == "1" ||
          this.markLineType == "7"
        ) {
          this.blueLines.splice(this.lineNum - 1, 0, lines[lines.length - 1]);
          this.lineNum++;
        }
      } else if (this.typeFlag == 0) {
        if (this.roads[this.lineNum - 1]) {
          console.log(this.roads[this.lineNum - 1]);
          this.roads[this.lineNum - 1].getParent().destroy();
          layer.draw();
        }
        let arrs = layer.get(".arr");
        let lastLine = arrs[arrs.length - 1].children[0];
        lastLine.line_type = this.markLineType;
        lastLine.roadsIndex = this.lineNum - 1;
        this.roads[this.lineNum - 1] = lastLine;
        this.lineNum++;
      } else if (this.typeFlag == 2) {
        let that = this;
        let rects = layer.get(".rect");
        let rect = rects[rects.length - 1];
        let points = [];
        this.childCirAry.forEach(ele => {
          let cir = [];
          console.log(this.lightShootState);
          switch (this.lightShootState) {
            case 0:
              cir = [rect.attrs.points[0], rect.attrs.points[1]];
              break;
            case 1:
              cir = [rect.attrs.points[2], rect.attrs.points[3]];
              break;
            case 2:
              cir = [rect.attrs.points[4], rect.attrs.points[5]];
              break;
            case 3:
              cir = [rect.attrs.points[6], rect.attrs.points[7]];
              break;
          }
          let x = parseInt(ele[0] / that.scale.x) + parseInt(cir[0]);
          let y = parseInt(ele[1] / that.scale.y) + parseInt(cir[1]);
          points.push(x);
          points.push(y);
        });
        console.log(points);
        rect.attrs.points = points;
        layer.draw();
        let length = points;
        let top = Math.min(points[1], points[3], points[5], points[7]);
        let left = Math.min(points[0], points[2], points[4], points[6]);
        let bottom = Math.max(points[1], points[3], points[5], points[7]);
        let right = Math.max(points[0], points[2], points[4], points[6]);
        let linghtRoi = {
          light_region_seq: 1,
          top: (top / 500).toFixed(6),
          right: (right / 800).toFixed(6),
          bottom: (bottom / 500).toFixed(6),
          left: (left / 800).toFixed(6)
        };

        (rect.light_seq = this.lightLayer.get("rect").length + 1),
          (rect.light_type = this.lightInfo.type),
          (rect.light_distribute = this.lightInfo.distribute),
          (rect.light_shape = this.lightInfo.shap),
          (rect.light_delay = this.lightInfo.delay),
          (rect.light_regions = {
            light_region_count: 1,
            light_region: linghtRoi
          });
        this.childCirAry = [];
      }
      // this.markLineType = "0";
      this.lightInfo = {
        type: "1",
        distribute: "1",
        shap: "1",
        delay: 3
      };
      this.selectedShape = null;
    },
    //画箭头
    drawArrow: function(
      c1,
      c2,
      theta,
      headlen,
      width,
      color,
      layer,
      group,
      line
    ) {
      theta = typeof theta != "undefined" ? theta : 30;
      headlen = typeof theta != "undefined" ? headlen : 10;
      width = typeof width != "undefined" ? width : 1;
      color = typeof color != "color" ? color : "#000";

      // 计算各角度和对应的P2,P3坐标
      var angle = (Math.atan2(c1[1] - c2[1], c1[0] - c2[0]) * 180) / Math.PI,
        angle1 = ((angle + theta) * Math.PI) / 180,
        angle2 = ((angle - theta) * Math.PI) / 180,
        topX = headlen * Math.cos(angle1),
        topY = headlen * Math.sin(angle1),
        botX = headlen * Math.cos(angle2),
        botY = headlen * Math.sin(angle2);

      var arrowX = c1[0] - topX,
        arrowY = c1[1] - topY;

      // let line = this.drawLine({x:c1[0],y:c1[1]},{x:c2[0],y:c2[1]},color)
      line.attrs.name = "centerLine";
      arrowX = c2[0] + topX;
      arrowY = c2[1] + topY;

      let line1 = this.drawLine(
        { x: c2[0], y: c2[1] },
        { x: arrowX, y: arrowY },
        color,
        3
      );
      arrowX = c2[0] + botX;
      arrowY = c2[1] + botY;

      let line2 = this.drawLine(
        { x: c2[0], y: c2[1] },
        { x: arrowX, y: arrowY },
        color,
        3
      );
      group.add(line);
      group.add(line1);
      group.add(line2);

      layer.add(group);
      layer.draw();
    },
    //生成车道
    drawRoad: function() {
      if (this.roadFlag === true) return;
      if (this.roadFlag === false) {
        this.$alert("车道线有修改,请逐一检查车道属性是否正确", "提示", {
          confirmButtonText: "确定"
        });
      }
      let childs = this.roadLayer.children;
      //清空层内非中线图形
      const num = childs.length - 1;
      for (let i = num; i > -1; i--) {
        const element = childs[i];
        element.destroy();
      }
      this.roadLayer.draw();

      try {
        console.log("蓝色车道线");
        console.log(this.blueLines);
        // this.blueLines.forEach((ele, index) => {
        //   if (ele.attrs.points[1] - ele.attrs.points[3] > 0) {
        //     var copypoint = Array.from(ele.attrs.points);
        //     ele.attrs.points[0] = copypoint[copypoint.length - 2];
        //     ele.attrs.points[1] = copypoint[copypoint.length - 1];
        //     ele.attrs.points[2] = copypoint[0];
        //     ele.attrs.points[3] = copypoint[1];
        //     console.log('*******蓝色车道线*******')
        //     console.log(ele)
        //   }
        // });
        //车道线根据坐标排序
        // eslint-disable-next-line no-inner-declarations
        function sortBlueLine(arr) {
          var len = arr.length;
          for (var i = 0; i < len; i++) {
            for (var j = 0; j < len - 1 - i; j++) {
              let startpointx = arr[j].attrs.points[0];
              let endpointx = arr[j].attrs.points[arr[j].attrs.points.length -2];
              let centerx =  (endpointx - startpointx) /2 + startpointx;
              let nextstartpointx = arr[j+1].attrs.points[0];
              let nextendpointx = arr[j + 1].attrs.points[arr[j + 1].attrs.points.length -2];
              let nextcenterx =  (nextstartpointx - nextendpointx) /2 + nextstartpointx;
              // let startpointy = arr[j].attrs.points[1];
              // let endpointy = arr[j].attrs.points[arr[j].attrs.points.length -2];
              // let centery = (endpointy -startpointy) /2 + startpointy;
              if (centerx > nextcenterx) {
                //相邻元素两两对比
                var temp = arr[j + 1]; //元素交换
                arr[j + 1] = arr[j];
                arr[j] = temp;
              }
            }
          }
          return arr;
        }
        //  this.blueLines = sortBlueLine(this.blueLines);
        console.log("蓝色车道线",this.blueLines);
        // console.log(sortBlueLine(this.blueLines));
        this.blueLines.forEach((ele, index) => {
          let points = this.sortLinePoints(ele.attrs.points);
          if (index > 0) {
            //绘制车道
            let lastPoints = this.sortLinePoints(
              this.blueLines[index - 1].attrs.points
            );
            let num1 =
              Math.pow(points[0] - lastPoints[0], 2) +
              Math.pow(points[1] - lastPoints[1], 2) +
              Math.pow(
                points[points.length - 2] - lastPoints[lastPoints.length - 2],
                2
              ) +
              Math.pow(
                points[points.length - 1] - lastPoints[lastPoints.length - 1],
                2
              );
            let num2 =
              Math.pow(points[0] - lastPoints[lastPoints.length - 2], 2) +
              Math.pow(points[1] - lastPoints[lastPoints.length - 1], 2) +
              Math.pow(points[points.length - 2] - lastPoints[0], 2) +
              Math.pow(points[points.length - 1] - lastPoints[1], 2);
            let mPoints;
            if (num1 < num2) {
                var arr = [];
                var len = lastPoints.length
                for(var i = len; 0 < i ; i--) {
                  if(i%2 == 0){
                    arr.push(lastPoints[i-2])
                    arr.push(lastPoints[i-1])
                  }
                }
              // mPoints = points.concat([
              //   lastPoints[lastPoints.length - 2],
              //   lastPoints[lastPoints.length - 1],
              //   lastPoints[0],
              //   lastPoints[1]
              // ]);
               mPoints = points.concat(arr)
            } else {
                let arr = [];
                let len = lastPoints.length
                for(let i = 0; i < len; i++) {
                  if(i%2 == 0){
                    a.push(lastPoints[i])
                    a.push(lastPoints[i+1])
                  }
                }
                mPoints = points.concat(arr)
              // mPoints = points.concat([
              //   lastPoints[0],
              //   lastPoints[1],
              //   lastPoints[lastPoints.length - 2],
              //   lastPoints[lastPoints.length - 1]
              // ]);
            }
            let rect = this.drawRect(
              "morePoints",
              mPoints,
              this.color[1],
              false
            );
            rect.roadIndex = index - 1;
            this.roadLayer.add(rect);
            //绘制车道
            debugger
            if (!this.roads[index - 1]) {
              this.roads[index - 1] = {};
            }
            var newmPoints = mPoints.filter(item => item);
            let road = this.roads[index - 1];
            let cPoints = [
              (newmPoints[0] + newmPoints[newmPoints.length -2]) / 2,
              (newmPoints[1] + newmPoints[newmPoints.length -1]) / 2,
              (newmPoints[2] + newmPoints[newmPoints.length - 4]) / 2,
              (newmPoints[3] + newmPoints[newmPoints.length -3]) / 2
            ];
            road.cPoints = cPoints;
            let cLine = this.drawLine("morePoints", cPoints, this.color[2]);
            this.greenLines[index - 1] = cLine;

            if (road.direct == undefined) {
              this.roadLayer.add(cLine);
            } else if (road.direct == "1") {
              this.drawArrow(
                [cPoints[0], cPoints[1]],
                [cPoints[cPoints.length - 2], cPoints[cPoints.length - 1]],
                30,
                20,
                3,
                this.color[2],
                this.roadLayer,
                new Kinetic.Group({ name: "arr" }),
                cLine
              );
            } else if (road.direct == "0") {
              this.drawArrow(
                [cPoints[cPoints.length - 2], cPoints[cPoints.length - 1]],
                [cPoints[0], cPoints[1]],
                30,
                20,
                3,
                this.color[2],
                this.roadLayer,
                new Kinetic.Group({ name: "arr" }),
                cLine
              );
            }
          }
        });
        this.roadFlag = true;
      } catch (error) {
        console.log(error);
      }
      this.roadLayer.draw();
    },
    lightNext: function() {
      this.childCirAry = this.$refs.lightCanvas.cirAry;
      this.typeFlag = 2;
    },
    lightLast: function() {
      this.typeFlag = 3;
      let that = this;
      setTimeout(function() {
        that.$refs.lightCanvas.cirAry = that.childCirAry;
        that.$refs.lightCanvas.bgUrl = that.childUrl;
        that.$refs.lightCanvas.draw();
      }, 0);
    },
    childCancle: function() {
      this.$refs.lightCanvas.cancle();
    },
    save: function() {
      this.cancleSelectedGroup();
      //车牌检测区域
      let testAry = [];
      try {
        const testPoints = this.testLayer.get(".rect")[0].attrs.points;
        for (let i = 0; i < testPoints.length; i += 2) {
          testAry.push({
            point_seq: i / 2 + 1,
            x: (testPoints[i] / 800).toFixed(6),
            y: (testPoints[i + 1] / 500).toFixed(6)
          });
        }
      } catch (error) {}

      this.roiBody.flow_roi = {
        flow_type: "",
        flow_region: {
          polygon_point_count: testAry.length,
          point: testAry
        }
      };
      //新增新增
      this.roiBody.plate_detect_region = {
        detect_polygon: {
          polygon_point_count: testAry.length,
          point: testAry
        }
      };
      //车道线
      let lineAry = [];
      try {
        this.blueLines.forEach((ele, index) => {
          let points = ele.attrs.points;
          let pointarr = [];
          for (let i = 0; i < points.length / 2; i++) {
            let obj = {
              point_seq: i + 1,
              x: (points[2 * i] / 800).toFixed(6),
              y: (points[2 * i + 1] / 500).toFixed(6)
            };
            pointarr.push(obj);
          }
          console.log("pointarr", pointarr);
          lineAry.push({
            line_seq: index + 1,
            lane_no: 1,
            line_type: ele.line_type,
            points: {
              point_count: pointarr.length,
              point: pointarr
              // [
              //   {
              //     point_seq: 1,
              //     x: (points[0] / 800).toFixed(6),
              //     y: (points[1] / 500).toFixed(6)
              //   },
              //   {
              //     point_seq: 2,
              //     x: (points[2] / 800).toFixed(6),
              //     y: (points[3] / 500).toFixed(6)
              //   }
              // ]
            }
          });
        });
      } catch (error) {
        console.log(error);
      }
      try {
        this.lineLayer.get(".line").forEach((ele, index) => {
          if (ele.line_type != 0 && ele.line_type != 1 && ele.line_type != 7) {
            let points = ele.attrs.points;
            let ary = [];
            for (let i = 0; i < points.length; i += 2) {
              ary.push({
                point_seq: i / 2 + 1,
                x: (points[i] / 800).toFixed(6),
                y: (points[i + 1] / 500).toFixed(6)
              });
            }
            lineAry.push({
              line_seq: lineAry.length + 1,
              lane_no: 1,
              line_type: ele.line_type,
              points: {
                point_count: points.length / 2,
                point: ary
              }
            });
          }
        });
      } catch (error) {
        console.log(error);
      }
      this.roiBody.lane_line = {
        line_count: lineAry.length,
        line: lineAry
      };

      //车道
      let roadAry = [];
      let lanaAry = [];
      console.log(this.roads);
      try {
        console.log(this.roads);
        this.blueLines.forEach((ele, index) => {
          if (index != this.blueLines.length - 1) {
            let midLine = this.roads[index],
              points =
                midLine.direct != "1"
                  ? [
                      midLine.cPoints[2],
                      midLine.cPoints[3],
                      midLine.cPoints[0],
                      midLine.cPoints[1]
                    ]
                  : midLine.cPoints,
              rectPoints1 = this.sortLinePoints(ele.attrs.points),
              rectPoints2 = this.sortLinePoints(
                this.blueLines[index + 1].attrs.points
              );
              debugger
            let options = {
              lane_seq: index + 1,
              lane_no: midLine.index,
              line: {
                polygon_point_count: 2,
                point: [
                  {
                    point_seq: 1,
                    x: points ? (points[0] / 800).toFixed(6) : "",
                    y: points ? (points[1] / 500).toFixed(6) : ""
                  },
                  {
                    point_seq: 2,
                    x: points ? (points[2] / 800).toFixed(6) : "",
                    y: points ? (points[3] / 500).toFixed(6) : ""
                  }
                ]
              },
              direction_polygon: {
                polygon_point_count: 2,
                point: [
                  {
                    point_seq: 1,
                    x: points ? (points[0] / 800).toFixed(6) : "",
                    y: points ? (points[1] / 500).toFixed(6) : ""
                  },
                  {
                    point_seq: 2,
                    x: points ? (points[2] / 800).toFixed(6) : "",
                    y: points ? (points[3] / 500).toFixed(6) : ""
                  }
                ]
              },
              lane_polygon: {
                polygon_point_count: 4,
                point: [
                  {
                    point_seq: 1,
                    x: (rectPoints1[2] / 800).toFixed(6),
                    y: (rectPoints1[3] / 500).toFixed(6)
                  },
                  {
                    point_seq: 2,
                    x: (rectPoints1[0] / 800).toFixed(6),
                    y: (rectPoints1[1] / 500).toFixed(6)
                  },
                  {
                    point_seq: 3,
                    x: (rectPoints2[0] / 800).toFixed(6),
                    y: (rectPoints2[1] / 500).toFixed(6)
                  },
                  {
                    point_seq: 4,
                    x: (rectPoints2[2] / 800).toFixed(6),
                    y: (rectPoints2[3] / 500).toFixed(6)
                  }
                ]
              }
            };
            let linetype = "";
            if (midLine.lane_use_type == 0) {
              // linetype = this.lanuse;
              switch (midLine.lane_guiding_type) {
                case "0":
                  linetype = 2;
                  break;
                case "1":
                  linetype = 0;
                  break;
                case "2":
                  linetype = 1;
                  break;
                case "3":
                  linetype = 3;
                  break;
                case "4":
                  linetype = 4;
                  break;
                case "5":
                  linetype = 5;
                  break;
                default:
                  break;
              }
            } else if (
              midLine.lane_use_type != "" &&
              midLine.lane_use_type != 0
            ) {
              //  linetype = this.lanuse;
              switch (midLine.lane_use_type) {
                case "1":
                  linetype = 8;
                  break;
                case "2":
                  linetype = 9;
                  break;
                case "3":
                  linetype = 10;
                  break;
                case "4":
                  linetype = 13;
                  break;
                case "5":
                  linetype = 14;
                  break;
                default:
                  break;
              }
            }
            options.lane_type = linetype;
            roadAry.push(options);
            //新增
            let L = JSON.stringify(options);
            let lanaOptions = JSON.parse(L);
            console.log(this.lanuse);

            lanaOptions.lane_use_type = midLine.lane_use_type;
            lanaOptions.lane_guiding_type = midLine.lane_guiding_type;
            lanaOptions.lane_type = linetype;
            lanaOptions.lane_user_id = options.lane_no;
            lanaOptions.lane_middle_line = {
              polygon_point_count: 2,
              point1: {
                x: points ? (points[0] / 800).toFixed(6) : "",
                y: points ? (points[1] / 500).toFixed(6) : ""
              },
              point2: {
                x: points ? (points[2] / 800).toFixed(6) : "",
                y: points ? (points[3] / 500).toFixed(6) : ""
              }
            };
            lanaOptions.lane_directions = {
              lane_direction_count: "1",
              lane_direction: {
                lane_direction_type: midLine.direct,
                lane_direction_time: "00:00:00-23:59:59"
              }
            };
            lanaAry.push(lanaOptions);
          }
        });
      } catch (error) {
        console.log(error);
      }

      //对向车道
      try {
        this.subtendLayer.get(".rect").forEach((el, index) => {
          let bicAry = [];
          let points = el.attrs.points;
          for (let i = 0; i < points.length; i += 2) {
            bicAry.push({
              point_seq: i / 2 + 1,
              x: (points[i] / 800).toFixed(6),
              y: (points[i + 1] / 500).toFixed(6)
            });
          }

          roadAry.push({
            lane_no: 1,
            lane_seq: roadAry.length + 1,
            lane_type: 11,
            lane_polygon: {
              polygon_point_count: bicAry.length,
              point: bicAry
            }
          });
          lanaAry.push({
            lane_no: 1,
            lane_seq: roadAry.length + 1,
            lane_use_type: 6,
            lane_type: 11,
            lane_polygon: {
              polygon_point_count: bicAry.length,
              point: bicAry
            }
          });
        });
      } catch (error) {
        console.log(error);
      }
      console.log("#######################");
      console.log(lanaAry);
      console.log("#######################");
      this.roiBody.lanes = {
        lane_count: lanaAry.length ? lanaAry.length : 0,
        lane: lanaAry ? lanaAry : []
      };
      // 红绿灯区域
      let lightAry = [];
      try {
        this.lightLayer.get(".rect").forEach((ele, index) => {
          lightAry.push({
            light_seq: index + 1,
            light_type: ele.light_type,
            light_id: ele.light_type,
            light_distribute: ele.light_distribute,
            light_number_type: ele.light_distribute,
            light_yellow_delay: Number(ele.light_delay),
            light_yellow_interval: Number(ele.light_delay),
            light_shape: ele.light_shape,
            light_shape_type: ele.light_shape,
            light_regions: ele.light_regions
          });
        });
      } catch (error) {
        console.log(error);
      }
      this.roiBody.lights = {
        light_count: lightAry.length,
        light: lightAry
      };

      //违停区域
      let noStopRois = this.noStopLayer.get(".rect");
      let noStopAry = [];
      try {
        noStopRois.forEach((el, index) => {
          let points = el.attrs.points;
          let ary = [];
          for (let i = 0; i < points.length; i += 2) {
            ary.push({
              point_seq: i / 2 + 1,
              x: (points[i] / 800).toFixed(6),
              y: (points[i + 1] / 500).toFixed(6)
            });
          }
          noStopAry.push({
            polygon_seq: index + 1,
            polygon_point_count: ary.length,
            point: ary
          });
        });
      } catch (error) {
        console.log(error);
      }

      this.roiBody.no_stop_region = {
        region_count: noStopAry.length,
        no_stop_polygon: noStopAry
      };

      //行人检测区域
      let bicArys = [];
      try {
        this.bicyLayer.get(".rect").forEach((el, index) => {
          let bicAry = [];
          let points = el.attrs.points;
          for (let i = 0; i < points.length; i += 2) {
            bicAry.push({
              point_seq: i / 2 + 1,
              x: (points[i] / 800).toFixed(6),
              y: (points[i + 1] / 500).toFixed(6)
            });
          }
          roadAry.push({
            lane_no: 1,
            lane_seq: roadAry.length + 1,
            lane_type: 12,
            lane_polygon: {
              polygon_point_count: bicAry.length,
              point: bicAry
            }
          });
          bicArys.push({
            polygon_id: el.polygon_id,
            polygon_name: el.polygon_name,
            polygon_point_count: bicAry.length,
            point: bicAry
          });
        });
      } catch (error) {
        console.log(error);
      }

      this.roiBody.pedestrian_detection_region = {
        region_count: bicArys.length,
        polygon: bicArys
      };
      this.roiBody.median_lines = {
        lane_count: roadAry.length ? roadAry.length : 0,
        lane: roadAry ? roadAry : []
      };

      //行人密度检测区域
      let densityAry = [];
      try {
        this.densityLayer.get(".rect").forEach((el, index) => {
          let denAry = [];
          let points = el.attrs.points;
          for (let i = 0; i < points.length; i += 2) {
            denAry.push({
              point_seq: i / 2 + 1,
              x: (points[i] / 800).toFixed(6),
              y: (points[i + 1] / 500).toFixed(6)
            });
          }
          densityAry.push({
            polygon_id: el.polygon_id,
            polygon_name: el.polygon_name,
            polygon_point_count: denAry.length,
            point: denAry
          });
        });
      } catch (error) {
        console.log(error);
      }

      this.roiBody.pedestrian_density_region = {
        region_count: densityAry.length,
        polygon: densityAry
      };

      //异物检测区域
      let foreignAry = [];
      try {
        this.foreignLayer.get(".rect").forEach((el, index) => {
          let foAry = [];
          let points = el.attrs.points;
          for (let i = 0; i < points.length; i += 2) {
            foAry.push({
              point_seq: i / 2 + 1,
              x: (points[i] / 800).toFixed(6),
              y: (points[i + 1] / 500).toFixed(6)
            });
          }
          foreignAry.push({
            polygon_id: el.polygon_id,
            polygon_name: el.polygon_name,
            polygon_point_count: foAry.length,
            point: foAry
          });
        });
      } catch (error) {
        console.log(error);
      }

      this.roiBody.foreign_detection_region = {
        region_count: foreignAry.length,
        polygon: foreignAry
      };

      //测试检测区域
      let testRegion = [];
      try {
        this.testRegionLayer.get(".rect").forEach((el, index) => {
          let foAry = [];
          let points = el.attrs.points;
          for (let i = 0; i < points.length; i += 2) {
            foAry.push({
              point_seq: i / 2 + 1,
              x: (points[i] / 800).toFixed(6),
              y: (points[i + 1] / 500).toFixed(6)
            });
          }
          testRegion.push({
            polygon_id: el.polygon_id,
            polygon_name: el.polygon_name,
            polygon_point_count: foAry.length,
            point: foAry
          });
        });
      } catch (error) {
        console.log(error);
      }

      this.roiBody.test_result_region = {
        region_count: foreignAry.length,
        polygon: testRegion
      };

      console.log(this.roiBody);
      return this.oParse.writeXML({ roi: this.roiBody });
    },
    clear: function() {
      (this.blueLines = []),
        (this.roads = []),
        (this.drawState = -1),
        (this.smallWindow = false),
        (this.roadFlag = ""),
        (this.needRect = false),
        (this.needLine = false),
        (this.canvasState = 0),
        (this.polygon_name = ""),
        (this.polygon_id = ""),
        (this.polyline = 0);
      $(".modal-lt button").removeClass("active");
    },
    sortLinePoints(pointarr) {
      try {
        let newpoint = [];
        if (pointarr[1] - pointarr[pointarr.length - 1] > 0) {
          newpoint[0] = pointarr[pointarr.length - 2];
          newpoint[1] = pointarr[pointarr.length - 1];
          newpoint[pointarr.length - 2] = pointarr[0];
          newpoint[pointarr.length - 1] = pointarr[1];
        } else {
          newpoint = pointarr;
        }
        return newpoint;
      } catch (err) {
        console.log(err);
      }
    },
    changetestid() {
      this.eventData.forEach(ele => {
        if (ele.value == this.polygon_id) {
          this.polygon_name = ele.name;
        }
      });
    }
  },
  mounted() {
    // console.log(eventJson);
    // this.eventData = eventJson;

    // this.stageInit()
    key("alt+1", () => {
      if (this.istest) {
        this.istest = false;
         this.typeData.splice(-1,1)
      } else {
        this.istest = true;
        this.typeData.push("测试区域")
      }
    });
  }
};
</script>

<style scoped>
button {
  cursor: pointer;
}
.modal-title {
  float: left;
  width: 93%;
  overflow: hidden;
}

.modal-body {
  height: 540px !important;
}
.modal-lt {
  width: 100%;
  margin-bottom: 10px;
  text-align: center;
  overflow: hidden;
}
.modal-lt button {
  outline: none;
  height: 30px;
  line-height: 30px;
  float: left;
  padding: 0 10px;
  border-radius: 15px;
  margin: 0 0px 10px 15px;
  background: #d7edff;
  border: 1px solid rgba(59, 183, 255, 1);
  cursor: pointer;
  color: #666666;
}
.modal-lt .curmodal {
  background: #d7edff !important;
  border: 1px solid rgba(59, 183, 255, 1);
  color: #3bb7ff;
}

.modal-editbox {
  position: relative;
  float: right;
  min-height: 450px;
  width: 22%;
  color: #fff;
}
.modal-editbox .modal-lb {
  position: absolute;
  bottom: 0;
  width: 150px;
}
.modal-right {
  position: relative;
  float: left;
  text-align: center;
}

.modal-editbox button {
  display: block;
  margin: 10px;
}

.modal-lb button {
  float: left;
  width: 90px;
  margin-left: 15px;
}

#zone_list button.active {
  background: #fff;
  color: #3d6797;
}

#line_type {
  display: none;
  position: fixed;
  top: 50%;
  left: 50%;
  width: 500px;
  height: 340px;
  margin-left: -250px;
  margin-top: -150px;
  z-index: 52;
  color: #fff;
  text-align: center;
  line-height: 35px;
  /* background: #409eff; */
  background: rgba(1, 20, 51, 0.9);
}

#line_type.active {
  display: block;
  z-index: 1001;
  opacity: 1;
}

#line_type p {
  padding: 15px;
  font-size: 17px;
  font-weight: bold;
}
#line_type input {
  width: 150px;
}
el-select {
  width: 90px !important;
}
#line_type button {
  color: #fff;
  margin: 50px 2%;
  width: 100px;
  height: 35px;
  line-height: 35px;
  background: #3a51f2;
  color: #fff;
  border: 0;
}

#c1 {
  position: absolute;
  top: 0;
  left: 0;
}

.pic {
  position: absolute;
  top: 0;
  left: 0;
}

.pic img {
  width: 800px;
  height: 500px;
  margin: 0;
  padding: 0;
}

canvas {
  margin: 0;
  padding: 0;
}

.title {
  /*background: url('../../../assets/18.png') no-repeat;*/
  width: 24%;
  height: 70px;
  line-height: 50px;
  margin: 0;
  margin-left: 3.5%;
  font-size: 25px;
  letter-spacing: 10px;
  display: inline-block;
}

.shadow {
  display: none;
  position: fixed;
  left: 0;
  top: 0;
  z-index: 1000;
  width: 100%;
  height: 100%;
  background: #000;
  filter: alpha(opacity=50);
  -moz-opacity: 0.5;
  opacity: 0.5;
}

ul {
  padding: 10px;
}

li {
  width: 130px;
  text-align: center;
}

.item {
  width: 50%;
  margin: 10px auto;
}
.item span {
  display: inline-block;
  width: 28%;
  text-align: right;
}
.item div {
  display: inline-block;
  width: 70%;
}
.w120 {
  width: 120px;
}
.mt10 {
  margin-top: 10px;
}
.pedestrian-area-attr {
  position: fixed;
  top: 50%;
  left: 50%;
  width: 500px;
  height: 300px;
  margin-left: -250px;
  margin-top: -150px;
  z-index: 52;
  color: #fff;
  text-align: center;
  line-height: 35px;
}
.pedestrian-area-attr .label {
  width: 80px;
}
.pedestrian-area-attr input {
  width: 200px !important;
  opacity: 0.8;
  height: 30px;
  line-height: 30px;
  border: 0px;
}
.mt40 {
  margin-top: 40px;
}
.btn-box button {
  height: 30px;
  line-height: 30px;
  width: 100px;
  border: 0;
  cursor: pointer;
  background: #145b93;
  color: #ffffff;
}

.delbtn {
  color: #fff;
  background: #e5e5e5;
}
</style>
b