routes-operation.js 127 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 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853
var RoutesOperation = (function () {
    var lineId, versions, directions = 0, status;
    var lineRegions = [];
    var city = '成都市大邑县';
    // 百度地图对象
    var baiduMap;
    // 进出场路段编辑时当前选中的路段
    var currentSection = {};
    var addStationRoute = {}, editStationRoute = {};
    // 进出场中名称和场站信息的映射
    var name2Point = {};
    var stationMarkers = {};
    var stationDrawingManager, sectionDrawingManager;
    var map_status = 0;
    var sectionArray = {}, stationArray = {};
    // 新增站点时添加的覆盖物, 站点点击和双击的setTimeout值
    var overlays = new Array(), setTimeoutId;
    // 信息窗口打开状态的路段
    var road_win_show_p;
    // 被编辑的路段
    var editPolyline;
    // 前置站点
    var premise;
    var styleOptions = {
        strokeColor : "blue",
        fillColor : "blue",
        strokeWeight : 3,
        strokeOpacity : 0.8,
        fillOpacity : 0.6,
        strokeStyle : 'solid'
    };
    var lineStyle = {
        strokeColor: "blue",
        strokeWeight: 2,
        strokeOpacity: 0.7
    }
    var polygonDmOptions = {
        isOpen : false,
        enableDrawingTool : false,
        drawingToolOptions : {
            anchor : BMAP_ANCHOR_TOP_RIGHT,
            offset : new BMap.Size(5, 5),
            scale : 0.8
        },
        polygonOptions : styleOptions
    }
    var operation = {
        getAddStationRoute: function () {
            return addStationRoute;
        },
        getEditStationRoute: function () {
            return editStationRoute;
        },
        getCurrentSection: function () {
            return currentSection;
        },
        getProperties: function () {
            return {
                lineId: lineId,
                versions: versions,
                directions: directions,
                status: status
            }
        },
        getBaiduMap: function () {
            return baiduMap;
        },
        getStationArray: function () {
            return stationArray;
        },
        setStationArray : function (s) {
            stationArray = s;
        },
        setMap_status : function (i) {
            map_status = i;
        },
        /***************************************************reload*******************************************************/
        initPage: function () {
            if (!$('body').hasClass('page-sidebar-closed')) {
                $('.menu-toggler.sidebar-toggler').click();
            }
            lineId = $.url().param('no');
            if (!lineId) {
                this.illegalParamHandle();
                return;
            }
            RoutesService.getAllLineVersions(lineId, function(lineVersions) {
                $('#versions option').remove();
                for (var i = 0, selected = 0;i < lineVersions.length;i++) {
                    var lineVersion = lineVersions[i];
                    if (lineVersion.status == 1 || i == lineVersions.length - 1) {
                        selected++;
                    }
                    $('#versions').append('<option value="' + lineVersion.versions + '" status="' + lineVersion.status + (selected === 1 ? '" selected' : '"') + '>' + lineVersion.name + ' (' + lineVersion.versions + ')' + '</option>');
                    if (selected === 1) {
                        operation.TreeUpOrDown(lineId, '0', lineVersion.versions);
                        operation.TreeUpOrDown(lineId, '1', lineVersion.versions);
                        versions = lineVersion.versions;
                        status = lineVersion.status;
                    }
                }
                operation.setTiteText(lineId);
                operation.registerEvents();
            });
        },
        illegalParamHandle: function () {
            layer.confirm('【ID缺失,请点击返回,重新进行操作】', {
                btn : [ '返回' ],
                icon : 3,
                title : '提示'
            }, function(index) {
                layer.close(index);
                loadPage('/pages/base/line/list.html');
            });
        },
        registerEvents: function() {
            $('#esc_edit_div').on('click', function() {
                var index = layer.open({
                    title: '退出提示',
                    content: '退出编辑模式后,当前没有保存的所有操作将被还原,确定要退出吗!',
                    btn: [ '确定', '取消' ],
                    yes: function(index) {
                        operation.resjtreeDate(lineId, directions, versions);
                        operation.editMapStatusRemove();
                        layer.msg("已退出编辑模式!");
                        layer.close(index);
                    },
                    btn2: function() {
                        layer.closeAll(index);
                        layer.msg("您没有退出编辑模式,请继续完成您未完成的操作!")
                    }
                });
            })

            $('#versions').on('change', function() {
                debugger
                versions = $(this).val();
                status = $('option:selected', $(this)).attr('status');
                $('#upLine').click();

                if (status > 0) {
                    $(".table-toolbar").show();
                } else {
                    $(".table-toolbar").hide();
                }
            })

            $('.green-seagreen dropdown-toggle').click(function() {
                $('.dropdown-menu').css("display", "block");
            });

            // 系统规划上行站点点击事件
            $('.upManual').on('click',function() {
                $.get('addstationstemplate.html', function(m){
                    $(pjaxContainer).append(m);
                    $('#add_station_template_modal').trigger('modal.show');
                });
            });

            // 系统规划上行站点点击事件
            $('.upSystem').on('click',function() {
                $('#upToolsMobal').hide();
                layer.load(0,{offset:['200px', '280px']});
                operation.lineNameIsHaveInterval(0);
            });

            $('.gpsRoute').on('click',function() {
                // 加载其它规划选择弹出层modal页面
                $.get('add_routes_template.html', function(m){
                    $(pjaxContainer).append(m);
                    $('#add_routes_template_modal').trigger('modal.show');
                });
            });

            $('.stationSelectGenerate').on('click', function () {
                $.get('station_select_generate.html', function(m){
                    $(pjaxContainer).append(m);
                    $('#station_select_generate_modal').trigger('modal.show');
                });
            });

            // 上行站点新增事件
            $('.module_tools #addUpStation').on('click', function() {
                operation.addStationInit();
                addStationRoute.directions = 0;
                $.get('add_stationroute_step1.html', function(m){
                    $(pjaxContainer).append(m);
                    $('#add_stationroute_step1_modal').trigger('modal.show');
                });
            });

            // 修改上行站点modal页面 @已弃用
            /*$('.module_tools #editUpStation').on('click', function(){
                var sel = PublicFunctions.getCurrSelNode(0);
                if(sel.length == 0 || sel[0].original.chaildredType != 'station'){
                    layer.msg('请先选择要编辑的上行站点!');
                    return;
                }
                $.get('edit_select.html', function(m){
                    $(pjaxContainer).append(m);
                    $('#edit_select_mobal').trigger('editSelectMobal_show', [WorldsBMap,DrawingManagerObj,GetAjaxData,EditStationObj,LineObj,PublicFunctions,directionUpValue]);
                });
            });*/

            // 撤销上行站点 @已弃用
            /*$('.module_tools #deleteUpStation').on('click', function() {
                PublicFunctions.stationRevoke(0);
            });*/

            // 上行批量撤销事件
            $('.module_tools #batchUpDelete').on('click', function() {
                $.get('destroy_routes.html', function(m){
                    $(pjaxContainer).append(m);
                    $('#delete_select_modal').trigger('modal.show');
                });
            });

            // 上行批量恢复事件
            $('.module_tools #upBatchRecover').on('click', function() {
                $.get('recover_routes.html', function(m){
                    $(pjaxContainer).append(m);
                    $('#recover_select_modal').trigger('modal.show');
                });
            });

            // 交换上下行站点和路段路由
            $('.retweet').on('click', function() {
                layer.confirm('您是否确定将【上、下】行站点和路段进行对换!', {
                    btn : [ '确认提示并提交', '取消' ]
                },function () {
                    layer.closeAll();
                    var index = layer.load(1, {
                        shade: [0.1, '#fff']
                    });
                    $post('/api/lsstationroute/exchangeDirection', {lineId: lineId, version: versions}, function(data) {
                        layer.close(index);
                        if (data.status == 'SUCCESS') {
                            layer.msg('操作成功...');
                        } else {
                            layer.msg('操作成功...');
                        }
                        operation.clearMarkAndOverlays();
                        $('#upLine').click();
                    });
                });
            });

            $('#wrenchUpDis').on('click',function() {
                RoutesService.findRoutes(lineId, directions, versions, function(routes) {
                    $.get('tzzj.html', function(m){
                        $(pjaxContainer).append(m);
                        $('#tzzj_mobal').trigger('modal.show', [routes.stationRoutes]);
                    });
                });
            })

            $('#wrenchDownDis').on('click',function() {
                RoutesService.findRoutes(lineId, directions, versions, function(routes) {
                    $.get('tzzj.html', function(m){
                        $(pjaxContainer).append(m);
                        $('#tzzj_mobal').trigger('modal.show', [routes.stationRoutes]);
                    });
                });
            });

            $('#quoteDown').on('click',function() {
                var index = layer.load(1, {
                    shade: [0.1,'#fff']
                });
                var params = {lineId: lineId, version: versions, direction: 0, otherDirection: 1};
                quote(params, index);
            });

            $('#quoteUp').on('click',function() {
                var index = layer.load(1, {
                    shade: [0.1,'#fff']
                });
                var params = {lineId: lineId, version: versions, direction: 1, otherDirection: 0};
                quote(params, index);
            });

            function quote(params, index) {
                $post('/api/lssectionroute/quoteOtherSide', params, function(data) {
                    layer.close(index);
                    if(data.status == 'SUCCESS') {
                        layer.msg('操作成功...');
                    } else {
                        layer.msg('操作失败...');
                    }
                    operation.clearMarkAndOverlays();
                    operation.resjtreeDate(lineId, directions, versions);
                });
            }

            // 编辑线路上行走向 @弃用
            /*$('.module_tools #editUplineTrend').on('click', function() {
                operation.editLinePlan(directionUpValue);
            });*/

            // 线路上行
            $('#leftUpOrDown #upLine').on('click', function(){
                directions = 0;
                operation.resjtreeDate(lineId, directions, versions);
            });

            // 系统规划上行站点点击事件
            $('.downManual').on('click',function() {
                $.get('addstationstemplate.html', function(m){
                    $(pjaxContainer).append(m);
                    $('#add_station_template_modal').trigger('modal.show');
                });
            });

            // 系统规划下行站点
            $('.downSystem').on('click',function() {
                $('#downToolsMobal').hide();
                layer.load(0,{offset:['200px', '280px']});
                operation.lineNameIsHaveInterval(1);
            });

            // 下行站点新增事件
            $('.module_tools #addDownStation').on('click', function() {
                operation.addStationInit();
                addStationRoute.directions = 1;
                $.get('add_stationroute_step1.html', function(m){
                    $(pjaxContainer).append(m);
                    $('#add_stationroute_step1_modal').trigger('modal.show');
                });
            });

            // 修改下行站点mobal页面 @弃用
            /*$('.module_tools #editDownStation').on('click', function(){
                var sel = PublicFunctions.getCurrSelNode(directionDownValue);
                if(sel.length==0 || sel[0].original.chaildredType !='station'){
                    layer.msg('请先选择要编辑的下行站点!');
                    return;
                }
                $.get('edit_select.html', function(m){
                    $(pjaxContainer).append(m);
                    $('#edit_select_mobal').trigger('editSelectMobal_show', [WorldsBMap,DrawingManagerObj,GetAjaxData,EditStationObj,LineObj,PublicFunctions,directionDownValue]);
                });
            });*/

            // 撤销下行站点 @弃用
            /*$('.module_tools #deleteDownStation').on('click', function() {
                PublicFunctions.stationRevoke(directionDownValue);
            });*/

            // 下行批量撤销事件
            $('.module_tools #batchDownDelete').on('click', function() {
                $.get('destroy_routes.html', function(m){
                    $(pjaxContainer).append(m);
                    $('#delete_select_modal').trigger('modal.show');
                });
            });

            // 下行批量恢复事件
            $('.module_tools #downBatchRecover').on('click', function() {
                $.get('recover_routes.html', function(m){
                    $(pjaxContainer).append(m);
                    $('#recover_select_modal').trigger('modal.show');
                });
            });

            // 编辑线路下行走向 @弃用
            /*$('.module_tools #editDownlineTrend').on('click', function() {
                PublicFunctions.editLinePlan(directionDownValue);
            });*/

            // 线路下行
            $('#leftUpOrDown #downLine').on('click', function(){
                directions = 1;
                operation.resjtreeDate(lineId, directions, versions);
            });

            // 生成行单 @弃用
            /*$('.module_tools #createUsingSingle').on('click', function() {
                var lineIdEvents = LineObj.getLineObj();
                var params = {lineId:lineIdEvents.id};
                GetAjaxData.createUsingSingle(params,function(data) {
                    if(data.status=='SUCCESS') {
                        // 弹出生成成功提示消息
                        layer.msg('生成成功...');
                    }else {
                        // 弹出生成失败提示消息
                        layer.msg('生成失败...');
                    }
                });
            });*/

            $('#scrllmouseEvent').on('mousemove',function() {
                $('.defeat-scroll').css('overflow','auto');
            }).on('mouseleave',function() {
                $('.defeat-scroll').css('overflow','hidden');
            });

            // 进出场规划
            $('#leftUpOrDown #inoutLine').on('click', function(){
                directions = 3
                operation.resjtreeDate(lineId, directions, versions);
            });

            // 环线首末站编码处理
            $('#circularRouteHandle').on('click', function() {
                RoutesService.circularRouteHandle(lineId, versions, function() {
                    layer.msg('操作成功');
                    operation.resjtreeDate(lineId, directions, versions);
                })
            })

            $('#regionDesign').on('click', function() {
                operation.loadLineRegion();
            })

            $('#regionSelect').on('change', function() {
                var stationRoutes = lineRegions[$(this).val()].stationRoutes;
                $('#region-station-body-table').html(template('line-region-station-template', {list: stationRoutes}));
                RoutesService.findSectionRoutes(lineId, directions, versions, function(sectionRoutes) {
                    operation.clearMarkAndOverlays();
                    if (stationRoutes.length > 0) {
                        var centerPointWkt = stationRoutes[0].station.centerPointWkt;
                        centerPointWkt = centerPointWkt.substring(6, centerPointWkt.length - 1);
                        var coordinates = centerPointWkt.split(' ');
                        //center = new BMap.Point(coordinates[0], coordinates[1]);
                        for (var i = 0;i < stationRoutes.length;i++) {
                            operation.drawingUpStationPoint(stationRoutes[i], i + 1);
                        }
                    }
                    if (sectionRoutes.length > 0) {
                        operation.drawingUpline01(sectionRoutes);
                    }
                })
            })
            
            // 区间添加
            $('#regionAddBtn').on('click', function () {
                $.get('add_line_region.html', function (m) {
                    $(pjaxContainer).append(m);
                    $('#add_line_region_modal').trigger('modal.show');
                });
            })

            // 区间编辑
            $('#regionEditBtn').on('click', function () {
                $.get('edit_line_region.html', function (m) {
                    $(pjaxContainer).append(m);
                    $('#edit_line_region_modal').trigger('modal.show', lineRegions[$('#regionSelect').val()]);
                });
            })
        },

        /***************************************************map*******************************************************/
        initMap: function () {
            baiduMap = new BMap.Map('routes_list_map_container' , {enableMapClick: false});
            baiduMap.centerAndZoom(city, 14);
            baiduMap.enableDragging();
            baiduMap.enableScrollWheelZoom();
            baiduMap.disableDoubleClickZoom();
            baiduMap.enableKeyboard();
        },
        /**
         * 打开站点路由信息窗口
         * @param stationRoute
         */
        openStationRouteInfoWin : function (stationRoute) {
            if (stationRoute) {
                var shapes = stationRoute.shapedType;
                var centerPointWkt = stationRoute.station.centerPointWkt;
                centerPointWkt = centerPointWkt.substring(6, centerPointWkt.length - 1);
                var coordinates = centerPointWkt.split(' ');
                var point = new BMap.Point(coordinates[0], coordinates[1]);
                var width = operation.strGetLength(stationRoute.stationName) * 11;
                var opts = {
                    width: (width < 240 ? 240 : width),
                    offset: new BMap.Size(10,-20),
                    enableMessage: false,
                    enableCloseOnClick: false,
                    enableAutoPan: false
                };

                var stationMark = '';
                if (stationRoute.stationMark == 'B') {
                    stationMark = '起点站';
                } else if (stationRoute.stationMark == 'Z') {
                    stationMark = '中途站';
                } else if (stationRoute.stationMark == 'E') {
                    stationMark = '终点站';
                }
                var htm = '<span style="color: #ff8355;font-size: 20px; overflow: hidden; white-space: nowrap; text-overflow:ellipsis;display: -webkit-box; -webkit-box-orient: vertical;">' + stationRoute.stationName + '</span>' +
                    '<span class="help-block" >站点编码:' + stationRoute.stationCode + '</span>' +
                    '<span class="help-block" >行业编号:' + (stationRoute.industryCode == null ? "":stationRoute.industryCode)+ '</span>' +
                    '<span class="help-block" >站点序号:' + stationRoute.stationRouteCode + '</span>' +
                    '<span class="help-block" >站点类型:' + stationMark + '</span>' +
                    '<span class="help-block" >经度:&nbsp&nbsp' + coordinates[0] + '</span>' +
                    '<span class="help-block" >纬度:&nbsp&nbsp' + coordinates[1] + '</span>' +
                    '<span class="help-block" >到站时间:' + stationRoute.toTime + '&nbsp;分钟</span>' +
                    '<span class="help-block" >到站距离:' + stationRoute.distances + '&nbsp;公里</span>' +
                    '<span class="help-block" >缓冲区形状:' + (shapes == 'r' ? '圆形' : '多边形') + '</span>' +
                    (shapes=="r" ?  ("<span class='help-block' >半径&nbsp&nbsp:" + stationRoute.radius + "</span>") : " ")+
                    '<span class="help-block" >版本号&nbsp&nbsp:' + stationRoute.versions + '</span>';

                if(status > 0){
                    htm += '<div>' +
                        '<button class="info_win_btn" onclick="RoutesOperation.editStation(' + stationRoute.id+','+stationRoute.directions + ')">修改</button>' +
                        '<button class="info_win_btn" onclick="RoutesOperation.destroyStation('+ stationRoute.id + ','+stationRoute.line.id+','+stationRoute.directions+')">撤销</button>' +
                        '<button class="info_win_btn" onclick="RoutesOperation.editCenterPoint(' + stationRoute.id+','+stationRoute.directions + ')">站级中心点</button>';
                        if (stationRoute.stationMark == 'E') {
                            htm += '<button class="info_win_btn" onclick="RoutesOperation.geoPremise(' + stationRoute.id + ')">前置电子围栏</button></div>';
                        } else {
                            htm += '<button class="info_win_btn" id="addBetweenStationRoad" onclick="RoutesOperation.addBetweenStationRoad(' + stationRoute.id + ')">添加站点间路段</button></div>';
                        }
                }
                // 创建信息窗口
                var infoWindow = new BMap.InfoWindow(htm, opts);
                infoWindow.addEventListener('close', function() {
                    if (premise) {
                        baiduMap.removeOverlay(premise);
                    }
                })
                setTimeout(function () {
                    //开启信息窗口
                    baiduMap.openInfoWindow(infoWindow, point);
                }, 100);
                // 将地图的中心点更改为给定的点。
                baiduMap.panTo(point);
            }
        },

        /**
         * 打开站点信息窗口
         * @param station
         */
        openStationInfoWin: function(station) {
            if (station) {
                var centerPointWkt = station.centerPointWkt;
                centerPointWkt = centerPointWkt.substring(6, centerPointWkt.length - 1);
                var coordinates = centerPointWkt.split(' ');
                var centerPoint = new BMap.Point(coordinates[0], coordinates[1]);
                var width = operation.strGetLength(station.stationName) * 11;
                var opts = {
                    width: (width < 240 ? 240 : width),
                    offset: new BMap.Size(10,-20),
                    enableMessage: false,
                    enableCloseOnClick: false,
                    enableAutoPan: false
                };

                var html = new Array();
                html.push('<span style="color: #ff8355;font-size: 20px; overflow: hidden; white-space: nowrap; text-overflow:ellipsis;display: -webkit-box; -webkit-box-orient: vertical;">' + station.stationName + '</span>');
                html.push('<span class="help-block" >站点编号:' + (station.stationCode ? station.stationCode : '')+ '</span>');
                html.push('<span class="help-block" >途经线路:' + (station.passLines ? station.passLines : '') + '</span>');

                var infoWindow = new BMap.InfoWindow(html.join(''), opts);
                setTimeout(function () {
                    baiduMap.openInfoWindow(infoWindow, centerPoint);
                }, 100);
                baiduMap.panTo(centerPoint);
            }
        },

        /**
         * 根据地理名称获取百度经纬度坐标
         */
        localSearchFromAdreesToPoint: function (Address, callback) {
            var localSearch = new BMap.LocalSearch(baiduMap);
            localSearch.setSearchCompleteCallback(function (searchResult) {
                var resultPoints = '';
                if (searchResult) {
                    // 返回索引指定的结果。索引0表示第1条结果
                    var poi = searchResult.getPoi(0);
                    if (poi) {
                        //获取经度和纬度
                        resultPoints = poi.point.lng + ' ' + poi.point.lat;
                        callback && callback(resultPoints);
                    } else {
                        callback && callback(false);
                    }
                } else {
                    callback && callback(false);
                }
            });
            localSearch.search(Address);
        },

        /**
         * 站级缓冲区编辑
         */
        editShapes: function (stationRoute) {
            // 关闭信息窗口
            baiduMap.closeInfoWindow();
            var shapedType = editStationRoute.shapedType;
            //setDragMarker(stationMarkers[editStationRoute.id]);

            var centerPointWkt = editStationRoute.station.centerPointWkt;
            centerPointWkt = centerPointWkt.substring(6, centerPointWkt.length - 1);
            var coordinates = centerPointWkt.split(' ');
            var center = new BMap.Point(coordinates[0], coordinates[1]);
            if (shapedType == 'r') {
                var circle = new BMap.Circle(center, editStationRoute.radius, lineStyle);
                baiduMap.centerAndZoom(center, 18);
                baiduMap.addOverlay(circle);
                circle.enableEditing();
                circle.addEventListener('dblclick', function () {
                    editStationRoute.centerPointWkt = circle.getCenter().lng + ' ' + circle.getCenter().lat;
                    editStationRoute.shapedType = 'r';
                    editStationRoute.radius = Math.round(circle.getRadius());
                    // 加载编辑页面
                    $.get('edit_stationroute_step2.html', function (m) {
                        $(pjaxContainer).append(m);
                        $('#edit_stationroute_step2_modal').trigger('modal.show');
                    });
                });
            } else if (shapedType == 'd') {
                var bufferPolygonWkt = editStationRoute.bufferPolygonWkt;
                bufferPolygonWkt = bufferPolygonWkt.substring(9, bufferPolygonWkt.length - 2);
                var points = bufferPolygonWkt.split(',');
                var polygonPoints = new Array();
                for (var i = 0; i < points.length; i++) {
                    var coordinates = points[i].split(' ');
                    polygonPoints.push(new BMap.Point(coordinates[0], coordinates[1]));
                }
                var polygon = new BMap.Polygon(polygonPoints, lineStyle);
                baiduMap.centerAndZoom(center, 18);
                baiduMap.addOverlay(polygon);
                polygon.enableEditing();
                polygon.addEventListener('dblclick', function (e) {
                    var bufferPolygonWkt = new Array(), points = polygon.getPath();
                    for(var i = 0;i < points.length;i++) {
                        bufferPolygonWkt.push(points[i].lng + ' ' + points[i].lat)
                    }
                    bufferPolygonWkt.push(points[0].lng + ' ' + points[0].lat)
                    editStationRoute.centerPointWkt = center.lng + ' ' + center.lat;
                    editStationRoute.shapedType = 'd';
                    editStationRoute.radius = 0;
                    editStationRoute.bufferPolygonWkt = bufferPolygonWkt.join(',');
                    $.get('edit_stationroute_step2.html', function (m) {
                        $(pjaxContainer).append(m);
                        $('#edit_stationroute_step2_modal').trigger('modal.show');
                    });
                });
            }
        },

        /**
         * 画路段走向
         */
        drawingUpline01: function (sectionRoutes) {
            if (sectionRoutes) {
                sectionArray = [];
                for (var d = 0; d < sectionRoutes.length; d++) {
                    var data = sectionRoutes[d];
                    var polylineArray = [];
                    var sectionBsectionVectorStr = data.section.bsectionVectorWkt;
                    if (sectionBsectionVectorStr == null)
                        continue;
                    var tempStr = sectionBsectionVectorStr.substring(11, sectionBsectionVectorStr.length - 1);
                    var lineArray = tempStr.split(',');
                    for (var i = 0; i < lineArray.length; i++) {
                        polylineArray.push(new BMap.Point(lineArray[i].split(' ')[0], lineArray[i].split(' ')[1]));
                    }
                    var polyUpline01 = 'polyline' + '_' + data.id;
                    polyUpline01 = new BMap.Polyline(polylineArray, {
                        strokeColor: "red",
                        strokeWeight: 6,
                        strokeOpacity: 0.7
                    });
                    polyUpline01.data = data;
                    polyUpline01.ct_source = '1';
                    baiduMap.addOverlay(polyUpline01);
                    polyUpline01.addEventListener('mousemove', function (e) {
                        if (this != editPolyline)
                            this.setStrokeColor("#20bd26");
                    });
                    polyUpline01.addEventListener('mouseout', function (e) {
                        if (this != editPolyline && this != road_win_show_p)
                            this.setStrokeColor("red");
                    });
                    polyUpline01.addEventListener('onclick', function (e) {
                        if (map_status != 1)
                            operation.openSectionInfoWin(this);
                    });
                    sectionArray.push(polyUpline01);
                }
            }
        },

        /**
         * 在地图上画点 @param:<point_center:中心坐标点>
         */
        drawingUpStationPoint: function (stationRoute, seq, isView) {
            var centerPointWkt = stationRoute.station.centerPointWkt;
            centerPointWkt = centerPointWkt.substring(6, centerPointWkt.length - 1);
            var coordinates = centerPointWkt.split(' ');
            var stationName = stationRoute.stationName;
            var center = new BMap.Point(coordinates[0], coordinates[1]);
            var html2 = '<div style="position: absolute; margin: 0pt; padding: 0pt; width: 160px; height: 26px; left: -10px; top: -35px; overflow: hidden;">'
                + '<img class="rm3_image" style="border:none;left:0px; top:0px; position:absolute;" src="/pages/base/stationroute/css/img/back160.png">'
                + '</div>'
                + '<label class=" BMapLabel" unselectable="on" style="position: absolute; -moz-user-select: none; display: inline; cursor: inherit; border: 0px none; padding: 2px 1px 1px; white-space: nowrap; font: 12px arial,simsun; z-index: 80; color: rgb(255, 102, 0); left: 15px; top: -35px;"><span style="float: left; color: #fdfdfd; margin-left: -22px;  font-size: 11px;">' + seq + '</span>' + stationName + '</label>';

            var myRichMarker1 = new BMapLib.RichMarker(html2, center, {
                "title": stationName,
                "anchor": new BMap.Size(-10, 8),
                "enableDragging": true
            });
            myRichMarker1.disableDragging();
            myRichMarker1.ct_source = '1';
            baiduMap.addOverlay(myRichMarker1);
            myRichMarker1.addEventListener('click', function () {
                if(map_status != 1 && !isView)
                    operation.openStationRouteInfoWin(stationRoute);
            });
            stationArray[stationRoute.id] = stationRoute;
            stationMarkers[stationRoute.id] = myRichMarker1;
        },

        /**
         * 站点名称获取百度坐标(手动规划)
         * @param arra
         * @param callback
         */
        stationsNameToPoints: function (arra, callback) {
            // 获取长度
            var len = arra.length;
            var stationList = [];
            // 是否为 站点\t经度\t纬度
            var standard = true;
            for (var i = 0; i < arra.length;i++) {
                var item = arra[i];
                if (!item.wgs.x || !item.wgs.y) {
                    standard = false;
                    stationList = [];
                    break;
                }
                stationList.push({
                    name: item.name.replace('公交车站', ''),
                    wgs: item.wgs,
                    potion: CoordinateConverter.transformFromWGSToBaidu(CoordinateConverter.locationMake(item.wgs.x, item.wgs.y))
                });
            }
            if (standard) {
                callback && callback(stationList);
                return;
            }
            (function () {
                if (!arguments.callee.count) {
                    arguments.callee.count = 0;
                }
                arguments.callee.count++;
                var index = parseInt(arguments.callee.count) - 1;
                if (index >= len) {
                    callback && callback(stationList);
                    return;
                }
                var f = arguments.callee;
                if (arra[index].name != '') {
                    var localSearch = new BMap.LocalSearch(baiduMap);
                    localSearch.search(arra[index].name);
                    localSearch.setSearchCompleteCallback(function (searchResult) {
                        var poi = searchResult.getPoi(0);
                        if (poi) {
                            stationList.push({
                                name: arra[index].name.replace('公交车站', ''),
                                wgs: arra[index].wgs,
                                potion: {lng: poi.point.lng, lat: poi.point.lat}
                            });
                        } else {
                            stationList.push({
                                name: arra[index].name.replace('公交车站', ''),
                                wgs: arra[index].wgs,
                                potion: {lng: arra[index].wgs.x, lat: arra[index].wgs.y}
                            });
                        }
                        f();
                    });
                } else {
                    f();
                }
            })();
        },

        /**
         * 根据坐标点获取两点之间的时间与距离(手动规划)
         * @param stationList
         * @param cb
         */
        getDistanceAndTotime: function (stationList, cb) {
            stationList[0].distance = '';
            stationList[0].duration = '';
            // var sectionList = [];
            // 获取长度
            var len = stationList.length;
            (function () {
                if (!arguments.callee.count) {
                    arguments.callee.count = 0;
                }
                arguments.callee.count++;
                var index = parseInt(arguments.callee.count) - 1;
                if (index >= len - 1) {
                    // cb && cb(stationList,sectionList);
                    cb && cb(stationList);
                    return;
                }
                var f = arguments.callee;
                var poiOne = new BMap.Point(stationList[index].potion.lng, stationList[index].potion.lat);
                var poiTwo = new BMap.Point(stationList[index + 1].potion.lng, stationList[index + 1].potion.lat);
                var transit = new BMap.TransitRoute(baiduMap, {
                    renderOptions: {map: baiduMap},
                    onSearchComplete: searchComplete
                });

                transit.search(poiOne, poiTwo);
                function searchComplete(results) {
                    var plan = results.getPlan(0);
                    if (transit.getStatus() != BMAP_STATUS_SUCCESS) {
                        stationList[index + 1].distance = 0;
                        stationList[index + 1].duration = 0;
                    } else {
                        stationList[index + 1].distance = 0;//plan.getDistance(true);
                        stationList[index + 1].duration = 0;//plan.getDuration(true);
                    }
                    f();
                }
            })();
        },

        /**
         * 根据坐标点获取两点之间的折线路段(手动规划)
         * @param stationsPoint
         * @param cb
         */
        getSectionListPlonly: function (stationsPoint, cb) {
            var len = stationsPoint.length;
            var sectionList = [];
            (function () {
                if (!arguments.callee.count) {
                    arguments.callee.count = 0;
                }
                arguments.callee.count++;
                var index = parseInt(arguments.callee.count) - 1;
                if (index >= len - 1) {
                    cb && cb(sectionList);
                    return;
                }
                var f = arguments.callee;
                var poiOne = new BMap.Point(stationsPoint[index].potion.lng, stationsPoint[index].potion.lat);
                var poiTwo = new BMap.Point(stationsPoint[index + 1].potion.lng, stationsPoint[index + 1].potion.lat);
                /* var transit = new BMap.TransitRoute(mapB, {renderOptions: {map: mapB},onPolylinesSet: searchPolylinesSet});*/
                var transit = new BMap.DrivingRoute(baiduMap, {
                    renderOptions: {map: baiduMap},
                    onPolylinesSet: searchPolylinesSet
                });
                function searchPolylinesSet(results) {
                    if (transit.getStatus() != BMAP_STATUS_SUCCESS) {
                    } else {
                        var sectionArrayList = [];
                        for (i = 0; i < results.length; i++) {
                            // console.log(results[i].getPolyline().getPath());
                            sectionArrayList = sectionArrayList.concat(results[i].getPolyline().getPath());
                        }
                        var sectionName = stationsPoint[index].name + '至' + stationsPoint[index + 1].name;
                        sectionList.push({sectionName: sectionName, points: sectionArrayList});
                    }
                    f();
                }
                transit.search(poiOne, poiTwo);
            })();
        },

        /**
         * 定位站点 按名称检索出的站点
         * @param stationName
         * @param cb
         */
        localtionPoint: function (stationName, cb) {
            baiduMap.closeInfoWindow();
            RoutesService.findStationByName(stationName, function (stations) {
                var marker;
                if (stations.length > 0) {
                    var points = new Array();
                    for (var i = 0;i < stations.length;i++) {
                        var station = stations[i];
                        var centerPointWkt = station.centerPointWkt;
                        centerPointWkt = centerPointWkt.substring(6, centerPointWkt.length - 1);
                        var stationName = station.stationName;
                        var coordinates = centerPointWkt.split(' ');
                        var centerPoint = new BMap.Point(coordinates[0], coordinates[1]);
                        points.push(centerPoint);
                        var stationMarker = new BMap.Marker(centerPoint, {
                            title: stationName,
                            icon: new BMap.Icon('/pages/base/stationroute/css/img/back160.png', new BMap.Size(160, 26)),
                            offset: new BMap.Size(60, -16),
                            enableDragging: false
                        });
                        var label = new BMap.Label(stationName, {offset: new BMap.Size(25, 0)});
                        label.setStyle({border: '0px'});
                        stationMarker.setLabel(label);
                        stationMarker.ct_source = '1';
                        stationMarker.station = station;
                        baiduMap.addOverlay(stationMarker);
                        overlays.push(stationMarker);
                        stationMarker.addEventListener('click', function (event) {
                            event.domEvent.stopPropagation();
                            if (setTimeoutId) {
                                clearTimeout(setTimeoutId);
                            }
                            setTimeoutId = setTimeout(function(){
                                operation.openStationInfoWin(event.target.station);
                            }, 200);
                        });
                        stationMarker.addEventListener('rightclick', operation.confirmCenterPointHandler);
                    }
                    var center = new BMap.Polyline(points).getBounds().getCenter();
                    baiduMap.panTo(center);
                }

                baiduMap.removeEventListener('click', operation.pickCenterPointHandler);
                baiduMap.addEventListener('click', operation.pickCenterPointHandler);
                cb && cb(marker);
            });
        },

        /**
         *
         * @param sectionName
         * @param callback
         */
        localtionRoad: function (sectionName, callback) {
            // 关闭信息窗口
            baiduMap.closeInfoWindow();
            RoutesService.findSectionByName(sectionName, function (sections) {
                var marker;
                if (sections.length > 0) {
                    var points = new Array();
                    for (var i = 0;i < sections.length;i++) {
                        var section = sections[i];
                        var bsectionVectorWkt = section.bsectionVectorWkt;
                        bsectionVectorWkt = bsectionVectorWkt.substring(11, bsectionVectorWkt.length - 1);
                        var sectionName = section.sectionName;
                        var polyline = operation.wkt2Polyline(bsectionVectorWkt);
                        polyline.section = section;
                        baiduMap.addOverlay(polyline);
                        overlays.push(polyline);
                        polyline.addEventListener('click', function (event) {
                            alert(event.target.section.id)
                        });
                        polyline.addEventListener('rightclick', operation.confirmCenterPointHandler);
                    }
                    var center = polyline.getBounds().getCenter();
                    baiduMap.panTo(center);
                }
            });
        },

        /**
         * wkt转百度Polyline
         * @param wkt
         * @returns {*}
         */
        wkt2Polyline: function (wkt) {
            var points = new Array(), pointWkts = wkt.split(',');
            for (var i = 0;i < pointWkts.length;i++) {
                var coordinates = pointWkts[i].split(' ');
                points.push(new BMap.Point(coordinates[0], coordinates[1]));
            }

            return new BMap.Polyline(points)
        },

        /**
         * 百度Polyline转wkt
         * @param wkt
         * @returns {*}
         */
        polyline2Wkt: function (polyline) {
            var points = polyline.getPath(), arr = new Array();
            for (var i = 0;i < points.length;i++) {
                arr.push(points[i].lng + ' ' + points[i].lat);
            }

            return 'LINESTRING(' + arr.join(',') + ')';
        },

        /**
         * 左键选取站点处理
         * @param e
         */
        pickCenterPointHandler: function(e) {
            baiduMap.removeEventListener('click', operation.pickCenterPointHandler);
            var marker = new BMap.Marker(e.point, {enableDragging: true});
            overlays.push(marker);
            baiduMap.panTo(e.point);
            baiduMap.addOverlay(marker);
            marker.addEventListener('rightclick', operation.confirmCenterPointHandler);
            marker.setAnimation(BMAP_ANIMATION_BOUNCE);
        },

        /**
         * 系统规划抓去数据 @param  lineNameValue:线路名称;i:方向
         */
        getBmapStationNames: function (lineName, i, cb) {
            var busline = new BMap.BusLineSearch(baiduMap, {
                onGetBusListComplete: function (busListResult) {
                    if (busListResult) {
                        var first = busListResult.getBusListItem(i);
                        busline.getBusLine(first);
                    }
                },
                onGetBusLineComplete: function (busLine) {
                    if (busLine) {
                        cb && cb(busLine);
                    }
                }
            });
            busline.getBusList(lineName);
        },

        /**
         * 移动站级中心点
         * @param stationRouteId
         */
        editCenterPoint: function (stationRouteId) {
            jQuery.extend(true, editStationRoute, stationArray[stationRouteId]);
            var centerPointWkt = editStationRoute.centerPointWkt;
            if (!centerPointWkt) {
                centerPointWkt = editStationRoute.station.centerPointWkt;
            }
            centerPointWkt = centerPointWkt.substring(6, centerPointWkt.length - 1);
            var coordindates = centerPointWkt.split(" ")
            var marker = new BMap.Marker(new BMap.Point(coordindates[0], coordindates[1]), {enableDragging: true});
            operation.clearMarkAndOverlays();
            baiduMap.addOverlay(marker);
            marker.setTop(true);
            marker.addEventListener('rightclick', operation.confirmCenterPoint);
            layer.msg('拖动站点至相应位置,然后右击确定中心点!');
        },

        confirmCenterPoint: function(event) {
            var marker = event.target, point = marker.point, centerPointWkt = 'POINT(' + point.lng + ' ' + point.lat + ')';
            marker.removeEventListener('rightclick', operation.confirmCenterPoint);
            RoutesService.modifyStationRoute({id: editStationRoute.id, 'line.id': lineId, versions: versions, 'station.id': editStationRoute.station.id, centerPointWkt: centerPointWkt}, function() {
                stationArray[editStationRoute.id].centerPointWkt = centerPointWkt;
                layer.msg('站级中心点设置成功!');
                RoutesOperation.resjtreeDate(lineId, directions, versions);
            })
        },

        /**
         * 编辑站点路由
         * @param stationRouteId
         */
        editStation: function (stationRouteId) {
            jQuery.extend(true, editStationRoute, stationArray[stationRouteId]);
            $.get('edit_stationroute_step1.html', function (m) {
                $(pjaxContainer).append(m);
                $('#edit_stationroute_step1_modal').trigger('modal.show');
            });
        },

        /**
         * 站间添加路段
         * @param stationRouteId
         */
        addBetweenStationRoad: function (stationRouteId) {
            var version = $("#versions").val();
            // 关闭信息窗口
            baiduMap.closeInfoWindow();
            // 查询下一个站点
            $.get("/api/lsstationroute/findCurrentAndNext", {id: stationRouteId}, function(stationRoutes) {
                if (stationRoutes.length < 2) {
                    layer.msg("您选择的站点后没有站点了,不能生成站点间路段!");
                } else {
                    var startStationRoute = stationRoutes[0], endStationRoute = stationRoutes[1];
                    var startWkt = startStationRoute.station.centerPointWkt, endWkt = endStationRoute.station.centerPointWkt;
                    var startCoordinates = startWkt.substring(6, startWkt.length - 1).split(" "), endCoordinates = endWkt.substring(6, endWkt.length - 1).split(" ")
                    var sectionList = [];
                    var startPoint = new BMap.Point(startCoordinates[0], startCoordinates[1]);
                    var endPoint = new BMap.Point(endCoordinates[0], endCoordinates[1]);
                    // 路径规划保存按钮
                    var label = new BMap.Label("保存路段", {
                        offset: new BMap.Size(13, -53)
                    });
                    label.setStyle({
                        color: '#fff',
                        background: "url(/pages/base/stationroute/css/img/bg.png)",
                        border: '0px solid',
                        textAlign: "center",
                        height: "28px",
                        lineHeight: "26px",
                        width: "80px",
                        maxWidth: "none"
                    });
                    label.addEventListener('click', function () {
                        var params = {};
                        params.lineId = startStationRoute.line.id;
                        params.lineCode = startStationRoute.lineCode;
                        params.directions = startStationRoute.directions;
                        params.stationRouteBegin = startStationRoute.stationName;
                        params.stationRouteFinish = endStationRoute.stationName;
                        layer.confirm('确定保存', {
                            btn : [ '路段调整好了','继续调整','退出'], icon: 3, title:'提示'
                            ,btn3: function(index, layero){
                                operation.resjtreeDate(params.lineId,params.directions);
                                operation.editAChangeCssRemoveDisabled();
                                operation.editMapStatusRemove();
                            }
                        }, function(index, layero){
                            layer.close(index);
                            params.route = $("#routePlanning").val();
                            $.get('doublename_road.html', function (m) {
                                $(pjaxContainer).append(m);
                                $('#doublename_road_modal').trigger('modal.show', [params]);
                            });
                            operation.editMapStatusRemove();
                        });
                    });
                    // 路径规划
                    var transit = new BMap.DrivingRoute(baiduMap, {
                        renderOptions: {
                            map: baiduMap,
                            enableDragging: true
                        },
                        onPolylinesSet: searchPolylinesSet
                    });

                    function searchPolylinesSet(results) {
                        if (transit.getStatus() == BMAP_STATUS_SUCCESS) {
                            var sectionArrayList = [];
                            for (i = 0; i < results.length; i++) {
                                sectionArrayList = sectionArrayList.concat(results[i].getPolyline().getPath());
                            }
                            sectionList = sectionArrayList;//JSON.stringify()
                            $("#routePlanning").val(JSON.stringify(sectionArrayList));
                            var pointMap = new Map();
                            pointMap = sectionArrayList[sectionArrayList.length - 1];
                            var pointLabel = new BMap.Point(pointMap.lng, pointMap.lat);
                            label.enableMassClear();
                            label.setPosition(pointLabel);
                            baiduMap.addOverlay(label);
                        }
                    }
                    transit.search(startPoint, endPoint);
                    transit.disableAutoViewport();
                    // 地图编辑状态
                    operation.editMapStatus(endStationRoute.directions);
                }
            });
        },

        /**
         * 前置电子围栏
         * @param stationRouteId
         */
        geoPremise: function (stationRouteId) {
            if (premise) {
                baiduMap.removeOverlay(premise);
            }
            RoutesService.findGeoPremise(stationRouteId, function (res) {
                if (res.id) {
                    var coords = res.coords.split(', '), points = [];
                    for (var i = 0;i < coords.length;i++) {
                        var coordinates = coords[i].split(' ');
                        points.push(new BMap.Point(coordinates[0], coordinates[1]));
                    }
                    premise = new BMap.Polygon(points);
                    premise.cdata = res;
                    premise.enableEditing(true);
                    premise.addEventListener('dblclick', operation.premiseDblclickHandler);
                    baiduMap.addOverlay(premise);
                } else {
                    layer.confirm('没有电子围栏,是否添加!', {
                        btn : [ '确认', '取消' ]
                    },function () {
                        layer.closeAll();
                        var drawingManager = new BMapLib.DrawingManager(baiduMap, polygonDmOptions);
                        drawingManager.setDrawingMode(BMAP_DRAWING_POLYGON);
                        drawingManager.open();
                        drawingManager.addEventListener('polygoncomplete', function(polygon) {
                            drawingManager.close();
                            baiduMap.removeOverlay(polygon);
                            var points = polygon.getPath();
                            if (points.length < 3) {
                                layer.msg('坐标点不能小于三个,请点击"退出编辑"后重新修改');
                                baiduMap.removeOverlay(polygon);

                                return false;
                            } else {
                                var bufferPolygonWkt = new Array();
                                for(var i = 0;i < points.length;i++) {
                                    bufferPolygonWkt.push(points[i].lng + ' ' + points[i].lat)
                                }
                                bufferPolygonWkt.push(points[0].lng + ' ' + points[0].lat)
                                RoutesService.saveGeoPremise({id: stationRouteId, coords: bufferPolygonWkt.join(', ')}, function(res) {
                                    if (res.status == 'SUCCESS') {
                                        layer.msg('前置电子围栏保存成功!');
                                    } else {
                                        layer.msg('前置电子围栏保存失败!');
                                    }
                                })
                            }
                        });

                    });
                }
            })
        },

        /**
         * 前置围栏双击保存
         */
        premiseDblclickHandler: function (event) {
            var points = event.target.getPath(), cdata = event.target.cdata;
            var bufferPolygonWkt = new Array();
            for(var i = 0;i < points.length;i++) {
                bufferPolygonWkt.push(points[i].lng + ' ' + points[i].lat)
            }
            bufferPolygonWkt.push(points[0].lng + ' ' + points[0].lat)
            RoutesService.saveGeoPremise({id: cdata.id, coords: bufferPolygonWkt.join(', ')}, function(res) {
                if (res.status == 'SUCCESS') {
                    layer.msg('前置电子围栏保存成功!');
                } else {
                    layer.msg('前置电子围栏保存失败!');
                }
            })
        },

        /**
         * 关闭modal时的清理
         * @param station
         */
        closeMobleSetClean: function(station) {
            var dir = station.directions;
            var lineId = station.lineId;

            operation.clearMarkAndOverlays();
            // 刷新左边树
            operation.resjtreeDate(lineId,dir,$("#versions").val());

            // 退出编辑状态
            operation.editMapStatusRemove();
        },

        /**
         * 定位路段
         * @param sectionRouteId
         */
        focusSection: function(sectionRouteId) {
            for (var i = 0, p; p = sectionArray[i++];) {
                if (p.data.id == sectionRouteId) {
                    switch (p.data.directions) {
                        case 3:
                            operation.openSectionInfoWin_inout(p);
                            break;
                        default:
                            operation.openSectionInfoWin(p);
                            break;
                    }

                }
            }
        },

        /**
         * 路段编辑
         * @param sectionRouteId
         * @param dir
         */
        editSection : function(sectionRouteId, dir) {
            layer.confirm('进入编辑状态', {
                btn : [ '确定','返回' ], icon: 3, title:'提示'
            }, function() {
                operation.editMapStatus(dir);
                layer.msg('双击保存路段');
                var polyline;
                for (var i = 0; polyline = sectionArray[i++];) {
                    if (polyline.data.id == sectionRouteId) {
                        baiduMap.closeInfoWindow();//关闭infoWindow
                        polyline.enableEditing();
                        polyline.setStrokeColor('blue');
                        break;
                    }
                }
                // 路段中间点为中心
                var sectionRoute = polyline.data;
                var sectionStr = sectionRoute.section.bsectionVectorWkt.substring(11, sectionRoute.section.bsectionVectorWkt.length - 1);
                // 分割折线坐标字符串
                var lineArray = sectionStr.split(',');
                var sectionPointArray = [];
                for (var i = 0; i < lineArray.length; i++) {
                    sectionPointArray.push(new BMap.Point(lineArray[i].split(' ')[0], lineArray[i].split(' ')[1]));
                }
                // 计算中间点
                var index = parseInt(sectionPointArray.length / 2);
                var centerPoint = sectionPointArray[index];
                baiduMap.centerAndZoom(centerPoint, 17);
                polyline.addEventListener('dblclick', function () {
                    operation.editMapStatusRemove();
                    $.get('edit_sectionroute.html', function(m){
                        $('body').append(m);
                        $('#edit_sectionroute_modal').trigger('modal.show', [polyline]);
                    });
                });
            });
        },

        /**
         * 添加第一个路段
         * @param section
         */
        addSection: function(section) {
            operation.editMapStatus();
            // 把数据填充到模版中
            var addSectionHTML = template('add_draw_polyline-temp');
            $('body .mian-portlet-body').append(addSectionHTML);
            //暂停和开始绘制
            $('.draw_polyline_switch>a').on('click', function () {
                var t = $(this).text();
                if(t=='暂停绘制'){
                    operation.exitDrawStatus();
                    $(this).text('开始绘制');
                }
                else{
                    operation.openDrawStatus();
                    $(this).text('暂停绘制');
                }
            });
            // 开启绘制事件
            operation.showAddSectionPanel();

            //取消
            $('#addSectionCancelBtn').on('click', function () {
                $('.main_left_panel_m_layer').hide();
                $(this).parents('.buffer_edit_body').parent().remove();
                operation.exitDrawStatus();
                operation.editMapStatusRemove();
            });

            //确定
            $('#addSectionSbmintBtn').on('click', function () {
                var btn = this;
                $('#addSectionSbmintBtn').addClass("disabled");
                var sectionName = $('#sectionNameInput').val();
                var bsectionVector = $('#bsectionVectorInput').val();
                var params = {};
                if(sectionName && bsectionVector) {
                    operation.exitDrawStatus();
                    RoutesService.getSectionCode(function(sectionCode) {
                        var sectionRoute = {};
                        sectionRoute['line.id'] = lineId;
                        sectionRoute.sectionCode = sectionCode;
                        sectionRoute.roadCoding = '';
                        sectionRoute.sectionrouteCode = 100;
                        sectionRoute.sectionTime = 0;
                        sectionRoute.sectionDistance = 0;
                        sectionRoute.speedLimit = 60;
                        sectionRoute.versions = versions;
                        sectionRoute.destroy = 0;
                        sectionRoute.directions = directions;
                        sectionRoute.status = status;
                        sectionRoute.start = section.start;
                        sectionRoute.end = section.end;
                        sectionRoute['section.id'] = sectionCode;
                        sectionRoute['section.sectionCode'] = sectionCode;
                        sectionRoute['section.sectionName'] = sectionName;
                        sectionRoute['section.bsectionVectorWkt'] = bsectionVector;

                        if (directions == 3) {
                            RoutesService.inoutSectionSave(sectionRoute, function (result) {
                                if(result.status =="SUCCESS"){
                                    $('.main_left_panel_m_layer').hide();
                                    $(btn).parents('.buffer_edit_body').parent().remove();
                                    operation.editMapStatusRemove();
                                    $('#inoutSearch').click();
                                    operation.editAChangeCssRemoveDisabled();
                                    layer.msg("添加成功!");
                                } else if(result.status == "ERROR") {
                                    layer.msg("添加失败!");
                                }
                            });
                        } else {
                            RoutesService.sectionSave(sectionRoute, function (result) {
                                if(result.status =="SUCCESS"){
                                    $('.main_left_panel_m_layer').hide();
                                    $(btn).parents('.buffer_edit_body').parent().remove();
                                    operation.editMapStatusRemove();
                                    $(directions == 0 ? '#upLine' : '#downLine').click();
                                    operation.editAChangeCssRemoveDisabled();
                                    layer.msg("添加成功!");
                                } else if(result.status == "ERROR") {
                                    layer.msg("添加失败!");
                                }
                            });
                        }
                    });
                } else if(!sectionName){
                    layer.msg('请填写路段名字!');
                } else if(!bsectionVector){
                    layer.msg('请先绘制路段!');
                }
                setTimeout(function () {
                    $("#addSectionSbmintBtn").removeClass("disabled");
                },1000);
            });
        },

        /**
         * 已有路段后添加路段
         * @param sectionRouteId
         */
        addSectionAfter: function(sectionRouteId) {
            /*$.get('add_sectionroute_step1.html', function(m){
                $(pjaxContainer).append(m);
                $('#add_sectionroute_step1_modal').trigger('modal.show', [WorldsBMap,DrawingManagerObj,RoutesService,AddStationObj,LineObj,operation]);
            });*/
            var lastSectionRoute;
            // 关闭信息窗口
            baiduMap.closeInfoWindow();
            operation.editMapStatus();
            // 把数据填充到模版中
            var addSectionHTML = template('add_draw_polyline-temp',{ 'id': sectionRouteId});
            $('body .mian-portlet-body').append(addSectionHTML);
            //暂停和开始绘制
            $('.draw_polyline_switch>a').on('click', function () {
                var t = $(this).text();
                if(t=='暂停绘制'){
                    operation.exitDrawStatus();
                    $(this).text('开始绘制');
                } else {
                    operation.openDrawStatus();
                    $(this).text('暂停绘制');
                }
            });

            //取消
            $('#addSectionCancelBtn').on('click', function () {
                $('.main_left_panel_m_layer').hide();
                $(this).parents('.buffer_edit_body').parent().remove();
                operation.exitDrawStatus();
                operation.editMapStatusRemove();
            });
            RoutesService.getSectionRouteInfoById(sectionRouteId, function(data) {
                operation.showAddSectionPanel(data);
                lastSectionRoute = data;
            });

            //确定
            $('#addSectionSbmintBtn').on('click', function () {
                var btn = this;
                $('#addSectionSbmintBtn').addClass("disabled");
                var sectionName = $('#sectionNameInput').val();
                var bsectionVectorWkt = $('#bsectionVectorInput').val();
                var params = {};
                if(sectionName && bsectionVectorWkt) {
                    operation.exitDrawStatus();
                    RoutesService.getSectionCode(function(sectionCode) {
                        params = {'section.id': sectionCode, 'section.sectionCode': sectionCode, 'section.sectionName': sectionName, 'section.bsectionVectorWkt': bsectionVectorWkt, 'section.speedLimit': 0, 'section.distance': 0, 'line.id': lastSectionRoute.line.id, sectionCode: sectionCode, lineCode: lastSectionRoute.lineCode, roadCoding: '', sectionrouteCode: parseInt(lastSectionRoute.sectionrouteCode) + 1, versions: lastSectionRoute.versions, destroy: 0, directions: lastSectionRoute.directions};

                        RoutesService.sectionSave(params, function (result) {
                            if(result.status =="SUCCESS"){
                                $('.main_left_panel_m_layer').hide();
                                $(btn).parents('.buffer_edit_body').parent().remove();
                                operation.editMapStatusRemove();
                                operation.resjtreeDate(lastSectionRoute.line.id, lastSectionRoute.directions, $("#versions").val());
                                operation.editAChangeCssRemoveDisabled();
                                layer.msg("添加成功!");
                            } else if(result.status =="ERROR") {
                                layer.msg("添加失败!");
                            }
                        });
                    });
                } else if(!sectionName){
                    layer.msg('请填写路段名字!');
                } else if(!bsectionVector)
                    layer.msg('请先绘制路段!');
                setTimeout(function () {
                    $("#addSectionSbmintBtn").removeClass("disabled");
                },1000);
            });
        },

        /**
         * 撤销站点
         * @param stationRouteId
         * @param lineId
         * @param dir
         */
        destroyStation: function(stationRouteId, lineId, dir) {
            layer.confirm('你确定要撤销此站点吗?', {
                btn : [ '撤销','返回' ], icon: 3, title:'提示'
            }, function(){
                $.post('/api/lsstationroute/destroy', {id: stationRouteId}, function(res) {
                    if (res.status == 'SUCCESS') {
                        // 弹出添加成功提示消息
                        layer.msg('撤销成功!');
                    } else {
                        // 弹出添加失败提示消息
                        layer.msg('撤销失败!');
                    }
                    // 刷新左边树
                    var version = $("#verions").val();
                    operation.resjtreeDate(lineId, dir, version);
                });
            });
        },

        /**
         * 撤销路段
         * @param sectionRouteId
         * @param lineId
         * @param dir
         */
        destroySection: function(sectionRouteId,lineId,dir) {
            layer.confirm('你确定要撤销此路段吗?', {
                btn : [ '撤销','返回' ], icon: 3, title:'提示'
            }, function(){
                $.post('/api/lssectionroute/destroy',{id: sectionRouteId},function(res) {
                    if (res.status == 'SUCCESS') {
                        // 弹出添加成功提示消息
                        layer.msg('撤销成功!');
                    } else {
                        // 弹出添加失败提示消息
                        layer.msg('撤销失败!');
                    }
                    // 刷新左边树
                    var version = $("#verions").val();
                    operation.resjtreeDate(lineId, dir, version);
                });
            });
        },
        /**
         * 打开路段信息窗口
         * @param p
         */
        openSectionInfoWin: function(p) {
            var sectionRoute = p.data;
            var dir = sectionRoute.directions;
            var width = operation.strGetLength(sectionRoute.section.sectionName) * 10;
            // 信息窗口参数属性
            var opts = {
                width: (width < 200 ? 200 : width),
                height: 150,
                enableMessage: false,
                enableCloseOnClick: false,
                enableAutoPan: false
            };
            var htm = '<span style="color: #ff8355;font-size: 18px;">' + sectionRoute.section.sectionName + '</span>' +
                '<span class="help-block" >路段编码:' + sectionRoute.sectionCode + '</span>' +
                '<span class="help-block" >路段序号:' + sectionRoute.sectionrouteCode + '</span>' +
                '<span class="help-block" >版本号&nbsp&nbsp:' + sectionRoute.versions + '</span>' +
                '<div >';

            if($($("#versions").find("option:selected")[0]).attr("status") > 0){
                htm += '<button class="info_win_btn" id="editStation" onclick="RoutesOperation.editSection(' + sectionRoute.id +','+dir+ ')">修改</button>' +
                    '<button  class="info_win_btn" id="addBetweenStationRoad" onclick="RoutesOperation.destroySection('+ sectionRoute.id + ','+sectionRoute.line.id+','+sectionRoute.directions+')">撤销</button>' +
                    '<button class="info_win_btn" id="addSectionAfter" onclick="RoutesOperation.addSectionAfter('+sectionRoute.id+')">添加路段(之后)</button>' +
                    '</div>';
            }

            var infoWindow_target = new BMap.InfoWindow(htm, opts);
            var sectionStr = sectionRoute.section.bsectionVectorWkt.substring(11, sectionRoute.section.bsectionVectorWkt.length - 1);
            var lineArray = sectionStr.split(',');
            var sectionArray = [];
            for (var i = 0; i < lineArray.length; i++) {
                sectionArray.push(new BMap.Point(lineArray[i].split(' ')[0], lineArray[i].split(' ')[1]));
            }
            var index = parseInt(sectionArray.length / 2);
            var centerPoint = sectionArray[index];
            infoWindow_target.addEventListener('close', function (e) {
                p.setStrokeColor("red");
                road_win_show_p = null;
            });
            infoWindow_target.addEventListener('open', function (e) {
                p.setStrokeColor("#20bd26");
                road_win_show_p = p;
            });
            baiduMap.openInfoWindow(infoWindow_target, centerPoint);
            baiduMap.panTo(centerPoint);
        },
        /**
         * 绘制新增路段
         * @param section
         */
        showAddSectionPanel : function (section) {
            var point;
            if(section){
                var sectionBsectionVectorStr = section.section.bsectionVectorWkt;
                var line = sectionBsectionVectorStr.substring(11, sectionBsectionVectorStr.length - 1),
                    points = line.split(','),
                    pointStr = points[points.length-1].split(' ');

                point = new BMap.Point(pointStr[0], pointStr[1]);
            }

            baiduMap.centerAndZoom(point, 18);

            sectionDrawingManager = new BMapLib.DrawingManager(baiduMap, {
                polylineOptions: styleOptions
            });

            sectionDrawingManager.open();
            sectionDrawingManager.setDrawingMode('polyline');

            //绘制完成
            sectionDrawingManager.addEventListener('polylinecomplete', function (e) {
                sectionDrawingManager.close();
                var polyline = new BMap.Polyline(e.getPath(), {strokeWeight: 7, strokeColor: 'blue', strokeOpacity: 0.7});
                baiduMap.removeOverlay(e);
                baiduMap.addOverlay(polyline);
                polyline.enableEditing();
                editPolyline = polyline;

                $('#bsectionVectorInput').val(operation.points2Wkt(e.getPath()));
            });
        },
        /**
         * 点转wkt
         * @param points
         * @returns {string}
         */
        points2Wkt: function (points) {
            var wkt = new Array();
            for (var i = 0;i < points.length;i++) {
                wkt.push(points[i].lng + ' ' + points[i].lat);
            }

            return 'LINESTRING(' + wkt.join(',') + ')';
        },
        /**
         * 退出图形编辑
         */
        exitDrawStatus : function () {
            if (sectionDrawingManager) {
                $('#bsectionVectorInput').val("");
                operation.clearOtherOverlay();
                sectionDrawingManager.close();
            }
        },
        /**
         * 打开图形编辑
         */
        openDrawStatus : function () {
            if (sectionDrawingManager) {
                $('#bsectionVectorInput').val("");
                operation.clearOtherOverlay();
                sectionDrawingManager.open();
            }
        },
        /**
         * 清除覆盖物
         */
        clearOtherOverlay : function () {
            var all = baiduMap.getOverlays();
            for (var i = 0, obj; obj = all[i++];) {
                if (obj.ct_source && obj.ct_source == '1')
                    continue;
                baiduMap.removeOverlay(obj);
            }
        },

        /**
         * 清除覆盖物
         */
        clearMarkAndOverlays: function () {
            // 清楚地图覆盖物
            baiduMap.clearOverlays();
            baiduMap.removeOverlay();
            sectionArray = [];
        },
        clearMark: function () {
            // 清楚地图覆盖物
            baiduMap.removeOverlay();
        },
        /**
         * 计算字符串长度
         * @param str
         * @returns {*}
         */
        strGetLength: function (str) {
            return str.replace(/[\u0391-\uFFE5]/g, "aa").length;  //先把中文替换成两个字节的英文,在计算长度
        },
        /**
         * 根据坐标匹配库中的站点
         * @param stations
         * @param callback
         */
        stationsPointsToLibraryPoint : function(stations, callback) {
            $.ajax('/station/matchStation', {
                method: 'POST',
                data: JSON.stringify(stations),
                contentType: 'application/json',
                success: function (res) {
                    callback && callback(res.data);
                    return;
                }
            });
        },
        /**
         * 从百度地图抓去站点与路段数据
          */
        lineInfoPanl : function(lineNameValue,i,cb) {
            /** 根据线路名称与方向从百度地图获取站点与路段  @param lineNameValue:线路名称;i:方向<0:上行;1:下行>  */
            operation.getBmapStationNames(lineNameValue,i,function(BusLine){
                return cb && cb(BusLine);
            });

        },
        /** 获取距离与时间 @param <points:坐标点集合> */
        getDistanceAndDuration : function(stations,callback){
            var stationRoutes = new Array();
            stations.forEach(function (item) {
                var stationRoute = { stationName: item.stationName, station: item, shapedType: 'r', radius: 80 };
                item.distance = 0;
                item.duration = 0;
                stationRoutes.push(stationRoute);
            });
            callback(stationRoutes);
        },

        /**
         * 画圆
         * point(lng,lat) 中心点
         * radius 半径(m)
         * isMark 是否加站名
         */
        drawCircle: function (point, radius, stationName, isMark) {
            var center = new BMap.Point(point.lng, point.lat);
            var circle = new BMap.Circle(center, radius ,{strokeColor:"blue", strokeWeight:2, strokeOpacity:0.5});
            baiduMap.addOverlay(circle);
            if (isMark) {
                var html = '<div style="position: absolute; margin: 0pt; padding: 0pt; width: 160px; height: 26px; left: -3px; top: -30px; overflow: hidden;">'
                    + '<img class="rm3_image" style="border:none;left:0px; top:0px; position:absolute;" src="/pages/base/stationroute/css/img/back160.png">'
                    + '</div>'
                    + '<label class=" BMapLabel" unselectable="on" style="position: absolute; -moz-user-select: none; display: inline; cursor: inherit; border: 0px none; padding: 2px 1px 1px; white-space: nowrap; font: 12px arial,simsun; z-index: 80; color: rgb(255, 102, 0); left: 20px; top: -30px;">' + stationName + '</label>';

                var myRichMarker = new BMapLib.RichMarker(html, center, {
                    "title": stationName,
                    "anchor": new BMap.Size(-10, 8),
                    "enableDragging": true
                });
                myRichMarker.disableDragging();
                myRichMarker.ct_source = '1';
                baiduMap.addOverlay(myRichMarker);
            }
        },

        /**
         * 画多边形
         * points 点数组
         */
        drawPolygon: function (points, stationName, isMark) {
            var bdPoints = new Array(), i = 0, point;
            for (i = 0;i < points.length;i++) {
                point = points[i].split(' ');
                bdPoints.push(new BMap.Point(point[0], point[1]));
            }
            var polygon = new BMap.Polygon(bdPoints), center = bdPoints[0];
            baiduMap.addOverlay(polygon);
            if (isMark) {
                var html = '<div style="position: absolute; margin: 0pt; padding: 0pt; width: 160px; height: 26px; left: -3px; top: -30px; overflow: hidden;">'
                    + '<img class="rm3_image" style="border:none;left:0px; top:0px; position:absolute;" src="/pages/base/stationroute/css/img/back160.png">'
                    + '</div>'
                    + '<label class=" BMapLabel" unselectable="on" style="position: absolute; -moz-user-select: none; display: inline; cursor: inherit; border: 0px none; padding: 2px 1px 1px; white-space: nowrap; font: 12px arial,simsun; z-index: 80; color: rgb(255, 102, 0); left: 20px; top: -30px;">' + stationName + '</label>';

                var myRichMarker = new BMapLib.RichMarker(html, center, {
                    "title": stationName,
                    "anchor": new BMap.Size(-10, 8),
                    "enableDragging": true
                });
                myRichMarker.disableDragging();
                myRichMarker.ct_source = '1';
                baiduMap.addOverlay(myRichMarker);
            }
        },

        /**
         * 画线
         * @param points
         * @param data
         * @param start
         * @param end
         */
        drawPolyLine: function (points, data, start, end) {
            var bdPoints = new Array(), i = 0, point, polyline;
            for (i = 0;i < points.length;i++) {
                point = points[i].split(' ');
                bdPoints.push(new BMap.Point(point[0], point[1]));
            }
            // 创建线路走向
            polyline = new BMap.Polyline(bdPoints, {
                strokeColor: 'red',
                strokeWeight: 6,
                strokeOpacity: 0.7
            });

            polyline.data = data;
            polyline.start = start;
            polyline.end = end;
            polyline.ct_source = '1';
            // 把折线添加到地图上
            baiduMap.addOverlay(polyline);
            // 聚焦事件
            polyline.addEventListener('mousemove', function (e) {
                if (this != editPolyline)
                    this.setStrokeColor("#20bd26");
            });
            // 失去焦点
            polyline.addEventListener('mouseout', function (e) {
                if (this != editPolyline && this != road_win_show_p)
                    this.setStrokeColor("red");
            });
            // 添加单击事件
            polyline.addEventListener('onclick', function (e) {
                // 打开信息窗口
                if (map_status != 1)
                    operation.openSectionInfoWin_inout(this);
            });
            // 添加右击事件
            polyline.addEventListener('rightclick', function (e) {
                if (currentSection.enableEditing) {
                    this.disableEditing();
                    operation.saveSection_inout(this);
                }
            });
            sectionArray.push(polyline);
        },

        /**
         * 打开进出场路段信息窗口
         * @param p
         */
        openSectionInfoWin_inout: function(p) {
            var sectionRoute = p.data;
            var dir = sectionRoute.directions;
            var width = operation.strGetLength(sectionRoute.section.sectionName) * 10;
            var opts = {
                width: (width < 200 ? 200 : width),
                height: 150,
                enableMessage: false,
                enableCloseOnClick: false,
                enableAutoPan: false
            };
            var htm = '<span style="color: #ff8355;font-size: 18px;">' + sectionRoute.section.sectionName + '</span>' +
                '<span class="help-block" >路段编码:' + sectionRoute.sectionCode + '</span>' +
                '<span class="help-block" >路段序号:' + sectionRoute.sectionrouteCode + '</span>' +
                '<span class="help-block" >版本号&nbsp&nbsp:' + sectionRoute.versions + '</span>' +
                '<div >';

            if($($("#versions").find("option:selected")[0]).attr("status") > 0){
                htm += '<button class="info_win_btn" id="editStation" onclick="RoutesOperation.editSection_inout(' + sectionRoute.id +','+dir+ ')">修改</button>' +
                    '<button  class="info_win_btn" id="addBetweenStationRoad" onclick="RoutesOperation.destroySection_inout('+ sectionRoute.id + ','+sectionRoute.line.id+','+sectionRoute.directions+')">撤销</button>' +
                    '<button class="info_win_btn" id="addSectionAfter" onclick="RoutesOperation.addSectionAfter_inout('+sectionRoute.id+')">添加路段(之后)</button>' +
                    '</div>';
            }

            var infoWindow_target = new BMap.InfoWindow(htm, opts);
            var sectionStr = sectionRoute.section.bsectionVectorWkt.substring(11, sectionRoute.section.bsectionVectorWkt.length - 1);
            var lineArray = sectionStr.split(',');
            var sectionArray = [];
            for (var i = 0; i < lineArray.length; i++) {
                sectionArray.push(new BMap.Point(lineArray[i].split(' ')[0], lineArray[i].split(' ')[1]));
            }
            var index = parseInt(sectionArray.length / 2);
            var centerPoint = sectionArray[index];
            infoWindow_target.addEventListener('close', function (e) {
                p.setStrokeColor("red");
                road_win_show_p = null;
            });
            infoWindow_target.addEventListener('open', function (e) {
                p.setStrokeColor("#20bd26");
                road_win_show_p = p;
            });
            baiduMap.openInfoWindow(infoWindow_target, centerPoint);
            baiduMap.panTo(centerPoint);
        },

        /**
         * 进出场路段设置为编辑状态
         */
        editSection_inout: function(sectionRouteId) {
            layer.confirm('进入编辑状态', {
                btn : [ '确定','返回' ], icon: 3, title:'提示'
            }, function() {
                operation.editMapStatus(dir);
                layer.msg('双击保存路段');
                var p;
                for (var i = 0; p = sectionArray[i++];) {
                    if (p.data.id == sectionRouteId) {
                        baiduMap.closeInfoWindow();//关闭infoWindow
                        p.enableEditing();
                        p.setStrokeColor('blue');
                        editPolyline = p;
                        break;
                    }
                }
                var sectionRoute = p.data;
                var sectionStr = sectionRoute.section.bsectionVectorWkt.substring(11, sectionRoute.section.bsectionVectorWkt.length - 1);
                var lineArray = sectionStr.split(',');
                var sectionPointArray = [];
                for (var i = 0; i < lineArray.length; i++) {
                    sectionPointArray.push(new BMap.Point(lineArray[i].split(' ')[0], lineArray[i].split(' ')[1]));
                }
                var index = parseInt(sectionPointArray.length / 2);
                var centerPoint = sectionPointArray[index];
                baiduMap.centerAndZoom(centerPoint, 17);
                p.addEventListener('dblclick', function (event) {
                    var polyline = event.target;
                    polyline.data.section.bsectionVectorWkt = operation.polyline2Wkt(polyline)
                    operation.editMapStatusRemove();
                    $.get('editsection_inout.html', function(m){
                        $('body').append(m);
                        $('#edit_section_modal').trigger('modal.show', [polyline]);
                    });
                });
            });
        },

        /**
         * 撤销进出场路段
         * @param sectionRouteId
         */
        destroySection_inout : function(sectionRouteId) {
            layer.confirm('你确定要撤销此路段吗?', {
                btn : [ '撤销','返回' ], icon: 3, title:'提示'
            }, function(){
                var status = $($("#versions").find("option:selected")[0]).attr("status");
                $.post('/inout/destroy',{'id': sectionRouteId, status:status},function(res) {
                    if (res.status == 'SUCCESS') {
                        layer.msg('撤销成功!');
                    } else {
                        layer.msg('撤销失败!');
                    }
                    // 刷新左边树
                    $('#inoutSearch').click();
                });
            });
        },

        /**
         * 进出场 在已有路段后添加路段
         * @param sectionRouteId
         */
        addSectionAfter_inout : function(sectionRouteId) {
            //order = after  before;
            var beforeSection;
            // 关闭信息窗口
            baiduMap.closeInfoWindow();
            operation.editMapStatus();
            // 把数据填充到模版中
            var addSectionHTML = template('add_draw_polyline-temp',{ 'id': sectionRouteId});
            $('body .mian-portlet-body').append(addSectionHTML);
            //暂停和开始绘制
            $('.draw_polyline_switch>a').on('click', function () {
                var t = $(this).text();
                if(t=='暂停绘制'){
                    operation.exitDrawStatus();
                    $(this).text('开始绘制');
                }
                else{
                    operation.openDrawStatus();
                    $(this).text('暂停绘制');
                }
            });

            //取消
            $('#addSectionCancelBtn').on('click', function () {
                $('.main_left_panel_m_layer').hide();
                $(this).parents('.buffer_edit_body').parent().remove();
                operation.exitDrawStatus();
                operation.editMapStatusRemove();
            });
            RoutesService.getRouteInfoById(sectionRouteId, function(data){
                beforeSection = data;
                beforeSection.sectionBsectionVector = beforeSection.section.bsectionVectorWkt;
                operation.showAddSectionPanel(beforeSection);
            });

            //确定
            $('#addSectionSbmintBtn').on('click', function () {
                var btn = this;
                $('#addSectionSbmintBtn').addClass("disabled");
                var sectionName = $('#sectionNameInput').val();
                var bsectionVector = $('#bsectionVectorInput').val();
                var sectionRoute = {};
                if(sectionName && bsectionVector) {
                    operation.exitDrawStatus();
                    RoutesService.getSectionCode(function(sectionCode) {
                        sectionRoute['line.id'] = lineId;
                        sectionRoute.sectionCode = sectionCode;
                        sectionRoute.roadCoding = '';
                        sectionRoute.sectionrouteCode = beforeSection.sectionrouteCode + 1;
                        sectionRoute.sectionTime = 0;
                        sectionRoute.sectionDistance = 0;
                        sectionRoute.speedLimit = 60;
                        sectionRoute.versions = versions;
                        sectionRoute.destroy = 0;
                        sectionRoute.directions = directions;
                        sectionRoute.status = status;
                        sectionRoute.start = beforeSection.start;
                        sectionRoute.end = beforeSection.end;
                        sectionRoute['section.id'] = sectionCode;
                        sectionRoute['section.sectionCode'] = sectionCode;
                        sectionRoute['section.sectionName'] = sectionName;
                        sectionRoute['section.bsectionVectorWkt'] = bsectionVector;
                        sectionRoute.status = status;

                        RoutesService.inoutSectionSave(sectionRoute, function (result) {
                            if(result.status == "SUCCESS"){
                                $('.main_left_panel_m_layer').hide();
                                $(btn).parents('.buffer_edit_body').parent().remove();
                                operation.editMapStatusRemove();
                                $('#inoutSearch').click();
                                operation.editAChangeCssRemoveDisabled();
                                layer.msg("添加成功!");
                            } else if(result.status == "ERROR") {
                                layer.msg("添加失败!");
                            }
                        });
                    });
                } else if(!sectionName){
                    layer.msg('请填写路段名字!');
                } else if(!bsectionVector)
                    layer.msg('请先绘制路段!');
                setTimeout(function () {
                    $("#addSectionSbmintBtn").removeClass("disabled");
                },1000);
            });
        },
        /**
         * 保存进出场路段
         */
        saveSection_inout: function () {
            $.get('editsection_inout.html', function(m){
                $('body').append(m);
                $('#edit_section_modal').trigger('modal.show', [currentSection]);
            });
        },
        /**
         * 添加站点时marker右键事件监听
         * 确认站点中心点
         */
        confirmCenterPointHandler: function (event) {
            // 清除覆盖物
            baiduMap.closeInfoWindow();
            baiduMap.clearOverlays();
            baiduMap.removeEventListener('click', operation.pickCenterPointHandler);

            var marker = event.target;
            var position = marker.getPosition(), station = marker.station;
            marker.disableDragging();
            baiduMap.addOverlay(marker);
            if (station) {
                var label = new BMap.Label(station.stationName, {offset: new BMap.Size(25, 0)});
                label.setStyle({border: '0px'});
                marker.setLabel(label);
                addStationRoute.id = station.id;
                addStationRoute.stationCode = station.stationCode;
                addStationRoute.stationName = station.stationName;
                addStationRoute.centerPointWkt = position.lng + ' ' + position.lat;
                layer.msg('已选定站点!');
            } else {
                delete addStationRoute.id;
                delete addStationRoute.stationCode;
                addStationRoute.centerPointWkt = position.lng + ' ' + position.lat;
                layer.msg('已确定中心点!');
            }
            marker.removeEventListener('rightclick', operation.confirmCenterPointHandler);
            if (addStationRoute.shapedType === 'd') {
                operation.openDrawingManager();
                operation.editMapStatus(directions);
                layer.msg('请点击选择多边形区域');
            } else {
                marker.addEventListener('dblclick', operation.formCenterPointHandler);
                layer.msg('请双击中心点图标进行下一步操作');
            }
        },
        /**
         * 确认中心点之后 填写附加字段
         */
        formCenterPointHandler: function () {
            if (setTimeoutId) {
                clearTimeout(setTimeoutId);
            }
            $.get('add_stationroute_step2.html', function(m){
                $(pjaxContainer).append(m);
                $('#add_stationroute_step2_modal').trigger('modal.show');
            });
        },
        /**
         * 添加站点前初始化
         */
        addStationInit: function () {
            addStationRoute = {};
            for (var i = 0;i < overlays.length;i++) {
                baiduMap.removeOverlay(overlays[i]);
            }
            overlays = new Array();
        },

        /***************************************************function*******************************************************/
        /** 初始化线路标题与ID */
        setTiteText : function(lineId) {
            // 根据线路ID获取线路名称
            RoutesService.getIdLineName(lineId,function(data) {
                // 定义线路名称
                var lineNameV = data.name;
                $('.portlet-title .caption').text(lineNameV);
            });
        },
        /** @param direction 方向  @return array */
        getCurrSelNode : function(direction){
            // 定义Obj
            var array = [];
            try {
                // 上行
                if(direction=='0'){
                    // 获取上行选中节点
                    array = $.jstree.reference("#station_Up_tree").get_selected(true);
                    // 下行
                }else if(direction=='1'){
                    // 获取下行选中节点
                    array = $.jstree.reference("#station_Down_tree").get_selected(true);
                }
            } catch (e) {
                console.log(e);
            }
            // 返回Obj
            return array;
        },
        startOrEndPoint: function(points, carpark) {
            var harr = new Array, i = 0;
            for (i = 0;i < points.length;i++) {
                harr.push('<option value="', points[i].stationName, '_station">', points[i].stationName, '</option>');
                points[i].bdPoint = points[i].station.centerPointWkt;
                points[i].bdPoints = points[i].bufferPolygonWkt;
                points[i].shapedType = points[i].shapedType;
                points[i].radius = points[i].radius;
                name2Point[points[i].stationName + '_station'] = points[i];
            }
            harr.push('<option value="', carpark.parkName, '_park">', carpark.parkName, '</option>');
            carpark.bdPoint = carpark.bCenterPoint;
            carpark.bdPoints = carpark.bParkPoint;
            carpark.stationName = carpark.parkName;
            carpark.shapedType = carpark.shapesType;
            name2Point[carpark.parkName + '_park'] = carpark;

            return harr.join('');
        },
        /** @param id:线路ID ;directionData:方向 */
        resjtreeDate : function(id, direction, version){
            if(!version){
                version = $("#versions").val();
            }

            var status = $($("#versions").find("option:selected")[0]).attr("status");
            if (direction == 3) {
                // 隐藏上行规划
                $('#upToolsMobal').hide();
                // 隐藏上行树
                $('#uptreeMobal').hide();
                // 隐藏下行规划
                $('#downToolsMobal').hide();
                // 隐藏下行树
                $('#DowntreeMobal').hide();
                //
                $('#InoutCarparktreeMobal .table-toolbar').hide();

                RoutesService.getStartEndByLine(id, version, function (result) {
                    if (result.data) {
                        $('#InoutCarparktreeMobal').show();
                        var formHtml = template('inout-carpark-search-form');
                        $('.inout-search').html(formHtml);

                        $('#startPoint').html(operation.startOrEndPoint(result.data.start, result.data.carpark));
                        $('#endPoint').html(operation.startOrEndPoint(result.data.end, result.data.carpark));
                        $('#startPoint').on('change', function () {
                            $('#InoutCarparktreeMobal .table-toolbar').hide();
                        });
                        $('#endPoint').on('change', function () {
                            $('#InoutCarparktreeMobal .table-toolbar').hide();
                        });
                        $('#inoutSearch').on('click', function () {
                            var start = $('#startPoint').val().split('_'), end = $('#endPoint').val().split('_');
                            if (start[1] == end[1]) {
                                layer.msg('进出场的站点不可能同时为站点或停车场');
                                return;
                            }

                            $('#inout_carpark_tree').show();
                            $('#InoutCarparktreeMobal .table-toolbar').show();

                            RoutesService.getRouteByStartEnd(id, version, start[0], end[0], function (result1) {
                                var routes = result1.data.routes, rootNode;
                                operation.clearMarkAndOverlays();
                                var startPoint = name2Point[start.join('_')], endPoint = name2Point[end.join('_')], point, points;
                                if (startPoint.shapedType === 'r') {
                                    point = startPoint.bdPoint.replace('POINT(', '').replace(')', '').split(' ');
                                    operation.drawCircle({lng : point[0], lat : point[1]}, startPoint.radius, startPoint.stationName, true);
                                } else if (startPoint.shapedType === 'd') {
                                    points = startPoint.bdPoints;
                                    points = points.replace('POLYGON ((', '').replace('POLYGON((', '').replaceAll(', ', ',').replace('))', '');
                                    points = points.split(',')
                                    operation.drawPolygon(points, startPoint.stationName, true);
                                }

                                if (endPoint.shapedType === 'r') {
                                    point = endPoint.bdPoint.replace('POINT(', '').replace(')', '').split(' ');
                                    operation.drawCircle({lng : point[0], lat : point[1]}, endPoint.radius, endPoint.stationName, true);
                                } else if (endPoint.shapedType === 'd') {
                                    points = endPoint.bdPoints;
                                    points = points.replace('POLYGON ((', '').replace('POLYGON((', '').replaceAll(', ', ',').replace('))', '');
                                    points = points.split(',')
                                    operation.drawPolygon(points, endPoint.stationName, true);
                                }

                                rootNode = {id: -1, pId: null, name: '路段', text: '路段', icon: null, groupType: 2, container : 'pjax-container', enable : true};
                                if (routes.length > 0) {
                                    for (var i = 0,route;i < routes.length;i++) {
                                        route = routes[i];
                                        points = route.section.bsectionVectorWkt.replace('LINESTRING(', '').replace(')', '');
                                        points = points.split(',');
                                        operation.drawPolyLine(points, route, start[0], end[0]);
                                    }
                                    rootNode.children = operation.formatSectionRoutes(routes, '-1');
                                } else {
                                    rootNode.children = [{id: 0, pId: -1, name: '添加路段', text: '添加路段', lineId: id, lineCode: id, versions: version, dir: 3, start: start[0], end: end[0], icon: null, groupType: 3, enable : true, type: 'addSection', sectionBsectionVector: 'LINESTRING(' + startPoint.bdPoint + ')'}];
                                }
                                operation.inoutInit([rootNode]);
                                operation.inoutreloadeTree([rootNode]);
                            });
                        });
                    } else {
                        layer.msg(result.msg);
                    }
                });
            } else {
                $('#InoutCarparktreeMobal').hide();
                $('#inout_carpark_tree').hide();
            }

            // 获取树数据
            RoutesService.findRoutes(id, direction, version, function(routes) {
                // 获取数据长度
                var len = routes.stationRoutes.length;
                // 上行
                if(direction == 0){
                    // 长度大于零
                    if (len > 0) {
                        // 隐藏上行规划
                        $('#upToolsMobal').hide();
                        // 显示树
                        $('#uptreeMobal').show();
                        // 刷新树
                        operation.reloadUp(routes);
                    } else {
                        if (status > 0) {
                            // 显示上行规划
                            $('#upToolsMobal').show();
                        } else {
                            $('#upToolsMobal').hide();
                        }
                        // 隐藏上行树
                        $('#uptreeMobal').hide();
                    }
                } else if (direction == 1) {
                    // 如果长度大于
                    if(len > 0) {
                        // 隐藏下行规划
                        $('#downToolsMobal').hide();
                        // 显示下行树
                        $('#DowntreeMobal').show();
                        // 跟新树
                        operation.reloadDown(routes);
                    } else {
                        if (status > 0) {
                            // 显示下行规划
                            $('#downToolsMobal').show();
                        } else {
                            $('#downToolsMobal').hide();
                        }
                        // 隐藏下行树
                        $('#DowntreeMobal').hide();
                    }
                }

                operation.linePanlThree(id, routes, direction, version, function (center) {
                    baiduMap.panTo(center);
                });
            });
        },

        /** 修正线路名称 @param:<directionUpValue:方向(0:上行;1:下行)> */
        lineNameIsHaveInterval : function(direction) {
            var lineName = $('.portlet-title .caption').text();
            if (lineName.indexOf('区间') > 0 || lineName.indexOf('定班') > 0) {
                lineName = lineName.replace('区间','').replace('定班', '');
                layer.confirm('系统无法生成该线路【'+lineName+'】的站点与路段!自动修改为如下线路名称【' + lineName + '】生成', {
                    btn : [ '确认提示并提交', '取消' ]
                }, function(index) {
                    layer.close(index);
                    operation.systemLineStation(lineName,direction);
                },function(){
                    layer.closeAll();
                    if(direction==0){
                        // 显示上行规划
                        $('#upToolsMobal').show();
                    }else if(direction==1){
                        // 显示下行规划
                        $('#downToolsMobal').show();
                    }
                });
            } else {
                operation.systemLineStation(lineName,direction);
            }
        },

        locations2LinestringWkt: function (locations) {
            var wkt = new Array();
            wkt.push('LINESTRING(')
            for (var i = 0,len = locations.length;i < len;i++) {
                wkt.push(locations[i].lng);
                wkt.push(' ');
                wkt.push(locations[i].lat);
                if (i != len - 1) { wkt.push(','); }
            }
            wkt.push(')');

            return wkt.join('');
        },

        systemLineStation: function(lineName, direction) {
            operation.getBmapStationNames(lineName, direction,function(busLine){
                // 如果线路信息不为空
                if(busLine && busLine.getNumBusStations()) {
                    var sectionRoutes = new Array(), stations = new Array();
                    sectionRoutes.push({sectionrouteCode: 100, section: {sectionName: lineName, bsectionVectorWkt: operation.locations2LinestringWkt(busLine.getPath())}})
                    var stationNumber = busLine.getNumBusStations();
                    // 遍历
                    for(var i = 0 ; i < stationNumber; i++) {
                        var station = busLine.getBusStation(i), station1 = {stationName: station.name, centerPointWkt: 'POINT(' + station.position.lng + ' ' + station.position.lat + ')'};
                        stations.push(station1);
                    }
                    // 获取站点之间的距离与时间
                    operation.getDistanceAndDuration(stations,function(stationRoutes) {
                        // 参数集合
                        var params = {lineId: lineId, directions: direction, versions: versions, stationRoutes: stationRoutes, sectionRoutes: sectionRoutes};
                        if (!params.versions) {
                            params.versions = '1';
                        }
                        RoutesService.collectionSave(params,function(rd) {
                            // 关闭弹出层
                            layer.closeAll();
                            if (rd.status == 'SUCCESS') {
                                layer.msg('保存成功!');
                            } else {
                                layer.msg('保存失败!');
                            }
                            // 刷新树
                            operation.resjtreeDate(lineId, direction, versions);
                        });
                    });
                } else {
                    layer.msg('百度地图中没有此线路,无法系统规划!');
                    setTimeout(function() {
                        // 关闭弹出层
                        layer.closeAll();
                        // 上行
                        if(direction==0){
                            // 显示上行规划
                            $('#upToolsMobal').show();
                            // 下行
                        }else if(direction==1){
                            // 显示下行规划
                            $('#downToolsMobal').show();
                        }
                    }, 3000);
                }
            });
        },

        // @弃用
        /*stationRevoke : function(directionV_) {
            // 获取树选中节点对象
            var obj = operation.getCurrSelNode(directionV_);
            // 是否选中,选中节点是否为站点
            if(obj.length == 0 || obj[0].original.chaildredType !='station'){
                // 弹出提示层
                layer.msg('请先选择要删除的站点!');
                return;
            }
            // 弹出是否撤销提示框
            layer.confirm('你确定要撤销【'+obj[0].text+'】站点吗?', {btn : [ '确定撤销','返回' ],icon: 3, title:'提示' }, function(index){


                // 站点路由ID
                var stationRouteId = obj[0].original.stationRouteId;

                var Line = LineObj.getLineObj();

                clonsole.log(Line);

                // 撤销参数集合
                var params = {stationRouteId:stationRouteId,destroy:'1',status:Line.status};
                // 方向
                var stationRouteDirections = obj[0].original.stationRouteDirections;
                // 撤销
                RoutesService.stationRouteIsDestroy(params,function(result) {
                    // 关闭弹出框
                    layer.close(index);
                    if(result.status=='SUCCESS'){
                        layer.msg('撤销'+(directionV_==0?"上行":"下行")+'站点【'+obj[0].text+'】成功!');
                    }else{
                        layer.msg('撤销'+(directionV_==0?"上行":"下行")+'站点【'+obj[0].text+'】失败!');
                    }
                    WorldsBMap.clearMarkAndOverlays();

                    var ver = $("#versions").val();

                    operation.resjtreeDate(Line.id,stationRouteDirections,ver);
                });
            });
        },*/

        // @弃用
        /*editLinePlan : function(direction_) {
            var sel = operation.getCurrSelNode(direction_);
            if(sel.length==0 || sel[0].original.chaildredType !='section'){
                if(direction_=='0') {
                    layer.msg('请先选中要编辑的上行路段!');
                }else if(direction_=='1') {
                    layer.msg('请先选中要编辑的下行路段!');
                }
                return;
            }
            $('#downLine').addClass('btn disabled');
            $('.btn-circle').addClass('disabled');
            $('#upLine').addClass('btn disabled');
            var editSectionV = sel[0].original;
            EditSectionObj.setEitdSection(editSectionV);
            // 弹出添加失败提示消息,2秒关闭(如果不配置,默认是3秒)
            var yindex = layer.msg('编辑完线路走向后,请双击线路走向区域保存',{ offset: '126px',shift: 0,time: 10000});
            WorldsBMap.editPolyUpline();
        },*/

        setFormValue : function(editStationRoute) {
            $('#edit_stationroute_form input,select,textarea').each(function () {
                if (this.name) {
                    $(this).val(eval('editStationRoute.' + this.name));
                    if ('shapedType' === this.name) {
                        $(this).val(editStationRoute.shapedType == 'r' ? '圆形' : '多边形')
                    }
                    if ('radius' === this.name) {
                        $(this).val(editStationRoute.radius ? editStationRoute.radius : 80);
                    }
                }
            })
        },

        setSectionFormValue : function(sectionRoute) {
            $('#edit_sectionroute_form input').each(function() {
                if (this.name) {
                    $(this).val(eval('sectionRoute.' + this.name));
                }
            });
        },

        /** 在地图上画出线路走向  @param:<Line.id:线路Id;0:上行;data:路段数据> */
        linePanlThree : function(lineId, routes, direction, version, callback) {
            operation.clearMarkAndOverlays();
            var i = 0, center;
            if (routes.stationRoutes.length > 0) {
                var centerPointWkt = routes.stationRoutes[0].station.centerPointWkt;
                centerPointWkt = centerPointWkt.substring(6, centerPointWkt.length - 1);
                var coordinates = centerPointWkt.split(' ');
                center = new BMap.Point(coordinates[0], coordinates[1]);
                for (;i < routes.stationRoutes.length;i++) {
                    operation.drawingUpStationPoint(routes.stationRoutes[i], i + 1);
                }
            }
            if (routes.sectionRoutes.length > 0) {
                operation.drawingUpline01(routes.sectionRoutes);
            }

            callback && center && callback(center);
        },

        /** 加载树 @param:<lineId:线路ID;direction:方向(0:上行;1:下行)> */
        TreeUpOrDown : function(lineId,direction,version) {
            /** 获取树结果数据 @param:<lineId:线路ID;direction:方向;callback:回调函数> */
            RoutesService.findRoutes(lineId,direction,version,function(result) {
                var len = result.stationRoutes.length;
                if(direction == 0) {
                    operation.upInit(result);
                    if(len>0) {
                        $('#upToolsMobal').hide();
                        $('#uptreeMobal').show();
                    }else {
                        $('#upToolsMobal').show();
                        $('#uptreeMobal').hide();
                    }

                    operation.linePanlThree(lineId, result, direction, version, function (center) {
                        baiduMap.panTo(center);
                    });
                }else if(direction ==1) {
                    operation.downInit(result);
                    if(len>0) {
                        $('#downToolsMobal').hide();
                        $('#DowntreeMobal').show();
                    }else {
                        $('#downToolsMobal').show();
                        $('#DowntreeMobal').hide();
                    }
                }
            });
        },

        isHaveStationName : function(data) {
            if(data.length>0) {
                layer.confirm('系统已存在【'+ data[0].stationName +'】该站点位置名称,请选择【系统引用】或者更改站点名称进行新增!', {btn : [ '返回' ],icon: 3, title:'提示' }, function(index){
                    layer.close(index);
                });
                return false;
            }else {
                return true;
            }
        },

        // 地图处于编辑状态
        editMapStatus : function (dir) {
            operation.setMap_status(1);
            // 有方向就显示退出编辑模式按钮
            if (dir != null && dir != 'null') {
                $('#esc_edit_div').show();
            }
            $('.protlet-box-layer').show();
        },

        // 地图处于编辑状态
        editMapStatusRemove : function () {
            operation.setMap_status(0);
            $('.protlet-box-layer').hide();
            $('#esc_edit_div').hide();
            // 退出绘画模式
            operation.exitDrawStatus();
        },

        // 选项鎖死解除
        editAChangeCssRemoveDisabled : function() {
            $('#downLine').removeClass('btn disabled');
            $('.btn-circle').removeClass('disabled');
            $('#upLine').removeClass('btn disabled');
        },

        // 方向代码转名称.
        dirdmToName : function(value){
            var srStr = '';
            if(value=='0')
                srStr = '上行';
            else if(value=='1')
                srStr = '下行';
            return srStr;
        },

        /**
         * 加载线路区间
         */
        loadLineRegion: function() {
            RoutesService.findLineRegion(lineId, versions, function(res) {
                lineRegions = res;
                var html = [];
                if (lineRegions.length > 0) {
                    lineRegions.forEach(function (item, idx) {
                        html.push('<option value="', idx, '">', item.regionAlias, '(', item.seq, ')</option>');
                    })
                    $('#regionSelect').html(html.join(''));
                    $('#regionSelect').trigger('change');
                }
            })
        },

        /***************************************************drawingmanager*******************************************************/
        initStationDrawingManager: function() {
            stationDrawingManager = new BMapLib.DrawingManager(baiduMap, polygonDmOptions);

            // 添加绘画完成事件
            stationDrawingManager.addEventListener('polygoncomplete', function(polygon) {
                stationDrawingManager.close();
                var points = polygon.getPath();
                if (points.length < 3) {
                    layer.msg('坐标点不能小于三个,请点击"退出编辑"后重新修改');
                    baiduMap.removeOverlay(polygon);

                    return false;
                } else {
                    var bufferPolygonWkt = new Array();
                    for(var i = 0;i < points.length;i++) {
                        bufferPolygonWkt.push(points[i].lng + ' ' + points[i].lat)
                    }
                    bufferPolygonWkt.push(points[0].lng + ' ' + points[0].lat)
                    if(!$.isEmptyObject(addStationRoute)){
                        addStationRoute.shapedType = 'd';
                        addStationRoute.radius = 0;
                        addStationRoute.bufferPolygonWkt = bufferPolygonWkt.join(',');

                        $.get('add_stationroute_step2.html', function (m) {
                            $(pjaxContainer).append(m);
                            $('#add_stationroute_step2_modal').trigger('modal.show');
                        });
                    }

                    if(!$.isEmptyObject(editStationRoute)){
                        editStationRoute.shapedType = 'd';
                        editStationRoute.radius = 0;
                        editStationRoute.bufferPolygonWkt = bufferPolygonWkt.join(',');

                        $.get('edit_stationroute_step2.html', function(m){
                            $(pjaxContainer).append(m);
                            $('#edit_stationroute_step2_modal').trigger('modal.show');
                        });
                    }
                }
            });

            return stationDrawingManager;
        },

        openDrawingManager : function() {
            stationDrawingManager.open();
            stationDrawingManager.setDrawingMode(BMAP_DRAWING_POLYGON);
        },

        closeDrawingManager : function() {
            stationDrawingManager.close();
        },

        /***************************************************treedata*******************************************************/
        TreeOnclickEvent: function (nodes) {
            if(nodes == null || nodes.length < 1) {
                return;
            }

            var original = nodes[0].original, type = original.type;

            if (type == "section") {
                operation.focusSection(original.cdata.id);
            } else if(type == "station") {
                operation.openStationRouteInfoWin(original.cdata);
            } else if(type == "addSection") {
                operation.addSection(original);
            }
        },
        format: function(routes) {
            var sectionRoutes = operation.formatSectionRoutes(routes.sectionRoutes, 'section-routes');
            if (sectionRoutes.length == 0) {
                sectionRoutes = [{id: 0, pId: -1, name: '添加路段', text: '添加路段', groupType: 3, enable : true, type: 'addSection'}];
            }
            return {
                groupType: 1,
                enable: true,
                name: '站点与路段',
                id: 'root',
                text: '站点与路段',
                children: [{
                    groupType: 2,
                    enable: true,
                    name: '站点',
                    id: 'station-routes',
                    pid: 'root',
                    text: '站点',
                    children: operation.formatStationRoutes(routes.stationRoutes, 'station-routes')
                }, {
                    groupType: 2,
                    enable: true,
                    name: '路段',
                    id: 'section-routes',
                    pid: 'root',
                    text: '路段',
                    children: sectionRoutes
                }]};
        },
        formatStationRoutes: function(stationRoutes, pid) {
            var result = new Array(), i = 0;
            for (;i < stationRoutes.length;i++) {
                var stationRoute = stationRoutes[i];
                result.push({
                    groupType: 3,
                    enable: true,
                    id: stationRoute.id,
                    pid: pid,
                    text: stationRoute.stationName,
                    type: 'station',
                    cdata: stationRoute
                })
            }

            return result;
        },
        formatSectionRoutes: function(sectionRoutes, pid) {
            var result = new Array(), i = 0;
            for (;i < sectionRoutes.length;i++) {
                var sectionRoute = sectionRoutes[i];
                result.push({
                    groupType: 3,
                    enable: true,
                    id: sectionRoute.id,
                    pid: pid,
                    text: sectionRoute.section.sectionName,
                    type: 'section',
                    cdata: sectionRoute
                })
            }

            return result;
        },
        upInit: function(routes) {
            if(routes) {
                $('#station_Up_tree').on('loaded.jstree', function(e, data){
                    $.jstree.reference("#station_Up_tree").open_all();
                }).jstree({
                    'core' : {
                        'themes' : {
                            'responsive': false
                        },
                        'data': operation.format(routes),
                        'multiple':false
                    },
                    'types' : {
                        "default" : {
                            "icon" : false
                        },
                        'enable_true' : {
                            "icon" : 'fa fa-check  icon-lg'
                        },
                        'enable_false' : {
                            'icon' : 'fa fa-close  icon-lg'
                        },
                        'group':{
                            'icon' : 'fa fa-object-group  icon-lg'
                        }
                    },
                    'plugins': ['types']
                }).bind('click.jstree', function(event) {
                    var nodes = $.jstree.reference("#station_Up_tree").get_selected(true);
                    operation.TreeOnclickEvent(nodes);
                });
            }
        },
        downInit: function(routes) {
            if(routes) {
                $('#station_Down_tree').on('loaded.jstree', function(e, data){
                    $.jstree.reference("#station_Down_tree").open_all();
                }).jstree({
                    'core' : {
                        'themes' : {
                            'responsive': false
                        },
                        'data': this.format(routes),
                        'multiple':false
                    },
                    'types' : {
                        "default" : {
                            "icon" : false
                        },
                        'enable_true' : {
                            "icon" : 'fa fa-check  icon-lg'
                        },
                        'enable_false' : {
                            'icon' : 'fa fa-close  icon-lg'
                        },
                        'group':{
                            'icon' : 'fa fa-object-group  icon-lg'
                        }
                    },
                    'plugins': ['types']
                }).bind('click.jstree', function(event) {
                    var treeOjb = $.jstree.reference("#station_Down_tree").get_selected(true);
                    operation.TreeOnclickEvent(treeOjb);
                });
            }
        },
        inoutInit : function(treeDateJson) {
            if(treeDateJson) {
                $('#inout_carpark_tree').on('loaded.jstree', function(e, data){
                    $.jstree.reference("#inout_carpark_tree").open_all();
                }).jstree({
                    'core' : {
                        'themes' : {
                            'responsive': false
                        },
                        'data': treeDateJson,
                        'multiple':false
                    },
                    'types' : {
                        "default" : {
                            "icon" : false
                        },
                        'enable_true' : {
                            "icon" : 'fa fa-check  icon-lg'
                        },
                        'enable_false' : {
                            'icon' : 'fa fa-close  icon-lg'
                        },
                        'group':{
                            'icon' : 'fa fa-object-group  icon-lg'
                        }
                    },
                    'plugins': ['types']
                }).bind('click.jstree', function(event) {
                    var treeOjb = $.jstree.reference("#inout_carpark_tree").get_selected(true);
                    operation.TreeOnclickEvent(treeOjb);
                });
            }
        },
        reloadUp : function (routes) {
            // 获取上行树
            var tree = $.jstree.reference('#station_Up_tree');
            // 赋值数据
            tree.settings.core.data = this.format(routes);
            // 刷新上行树
            tree.refresh();
            // 展开树
            setTimeout(function () {
                tree.open_all();
            },500);
        },
        reloadDown : function (routes) {
            // 获取下行树
            var tree = $.jstree.reference('#station_Down_tree');
            // 赋值数据
            tree.settings.core.data = this.format(routes);
            // 刷行下行树
            tree.refresh();
            // 展开树
            setTimeout(function () {
                tree.open_all();
            },500);
        },
        inoutreloadeTree : function (treeDateJson) {
            // 获取下行树
            var tree = $.jstree.reference('#inout_carpark_tree');
            // 赋值数据
            tree.settings.core.data = treeDateJson;
            // 刷行下行树
            tree.refresh();
            // 展开树
            setTimeout(function () {
                tree.open_all();
            },500);
        }
    }

    return operation;
})()