analysis_trafficTransfer.html 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878
  1. <!--********************************************************************
  2. * Copyright© 2000 - 2021 SuperMap Software Co.Ltd. All rights reserved.
  3. *********************************************************************-->
  4. <!DOCTYPE html>
  5. <html>
  6. <head>
  7. <meta charset="utf-8">
  8. <title data-i18n="resources.title_trafficTransfer"></title>
  9. <style type="text/css">
  10. body {
  11. margin: 0;
  12. overflow: hidden;
  13. background: #fff;
  14. width: 100%;
  15. height: 100%
  16. }
  17. #map {
  18. position: absolute;
  19. width: 100%;
  20. height: 100%;
  21. }
  22. #toolbar {
  23. position: absolute;
  24. top: 50px;
  25. right: 10px;
  26. width: 380px;
  27. text-align: center;
  28. z-index: 100;
  29. border-radius: 4px;
  30. }
  31. </style>
  32. </head>
  33. <body>
  34. <div id="toolbar" class="panel panel-primary toolbar">
  35. <div class='panel-heading'><h5 class='panel-title text-center' data-i18n="resources.text_trafficTransfer">
  36. </h5></div>
  37. <div class='panel'>
  38. <div class='input-group'>
  39. <div id='result' style="width: 360px" class='container'></div>
  40. </div>
  41. </div>
  42. <div id="func" style="margin: 10px 0 10px 0;"></div>
  43. </div>
  44. <div id="map"></div>
  45. <script type="text/javascript" include="bootstrap,widgets.alert" src="../js/include-web.js"></script>
  46. <script type="text/javascript" exclude="iclient-classic" src="../../dist/classic/include-classic.js"></script>
  47. <script>
  48. var map, layer, start, end, vectorLayer, markerLayer, startLayer, endLayer, tempRedLayer,
  49. globeStartName, globeEndName, popwin,
  50. noStart = false, noEnd = false, isStartKey = false, isEndKey = false,
  51. styleLine = {
  52. strokeColor: "blue",
  53. strokeWidth: 3,
  54. strokeLinecap: "round",
  55. strokeDashstyle: "solid"
  56. },
  57. styleLineRed = {
  58. strokeColor: "red",
  59. strokeWidth: 4,
  60. strokeLinecap: "round",
  61. strokeDashstyle: "solid"
  62. };
  63. var size = new SuperMap.Size(21, 21);
  64. var offset = new SuperMap.Pixel(-(size.w / 2), -size.h);
  65. var iconstart = new SuperMap.Icon("../img/start_trans.png", size, offset);
  66. var iconend = new SuperMap.Icon("../img/end_trans.png", size, offset);
  67. //起点搜索文本提示信息框
  68. function addStartSugText() {
  69. var inputDiv = $("<div class='start_end_input'></div>")
  70. $("<span>" + resources.text_startPoint + ":" + "</span>").appendTo(inputDiv);
  71. var input = $("<input type='search' width='60px' id='startInput' value='省汽修' text='26,3111.42533851,-5527.73795456'/>");
  72. var p = new SuperMap.Geometry.Point(3111.42533851, -5527.73795456);
  73. startLayer.addMarker(new SuperMap.Marker(new SuperMap.LonLat(p.x, p.y), iconstart));
  74. input.keyup(findStartStops);
  75. input.keydown(updateStartInputByResult);
  76. input.appendTo(inputDiv);
  77. inputDiv.appendTo($("#func"));
  78. var dataList = $("<div id='startSugPopup' class='sugpopup'></div>");
  79. $("<ul id='startSugList' class='dropList'></ul>").appendTo(dataList);
  80. dataList.appendTo(inputDiv);
  81. function findStartStops(event) {
  82. clear();
  83. var code = event.keyCode;
  84. if (isStartKey) return;
  85. if (code === 37 || code === 38 || code === 39 || code === 40 || code === 13) return;
  86. markerLayer.clearMarkers();
  87. startLayer.clearMarkers();
  88. vectorLayer.removeAllFeatures();
  89. $("#startInput").attr("text", "");
  90. var txt = $("#endInput").attr("text");
  91. if (txt) {
  92. var end = txt.split(",");
  93. endLayer.addMarker(new SuperMap.Marker(new SuperMap.LonLat(end[1], end[2]), iconend));
  94. }
  95. var list = $("#startSugList");
  96. list.empty();
  97. var popup = $("#startSugPopup");
  98. var startName = event.target.value;
  99. if (!startName) {
  100. popup.css("display", "none");
  101. return;
  102. }
  103. var params = new SuperMap.REST.StopQueryParameters({
  104. keyWord: startName,
  105. returnPosition: true
  106. });
  107. var iserver = new SuperMap.REST.StopQueryService(traffic_transfer, {
  108. eventListeners: {
  109. processCompleted: stopQuerySucceed,
  110. processFailed: stopQueryFailed
  111. }
  112. });
  113. iserver.processAsync(params);
  114. //返回根据模糊的地名搜索得到的跟地名有关的所有公交站点的结果
  115. function stopQuerySucceed(stopQueryEvent) {
  116. popup.addClass("show").css("display", "block");
  117. if (!stopQueryEvent.result.transferStopInfos.length) {
  118. $("<li>" + resources.text_notFindSPoint + "</li>").appendTo(list);
  119. noStart = true;
  120. } else {
  121. noStart = false;
  122. for (var i = 0, len = stopQueryEvent.result.transferStopInfos.length; i < len; i++) {
  123. var station = stopQueryEvent.result.transferStopInfos[i];
  124. var value = station.stopID + "," + station.position.x + "," + station.position.y;
  125. $("<li id='" + value + "'>" + station.name + "</li>").appendTo(list);
  126. list.find("li").click(function () {
  127. var input = $("#startInput");
  128. input.val($(this).text());
  129. input.attr("text", $(this).attr("id"));
  130. $("#startSugList").empty();
  131. popup.removeClass("show");
  132. var arr = $(this).attr("id").split(",");
  133. startLayer.addMarker(new SuperMap.Marker(new SuperMap.LonLat(arr[1], arr[2]), iconstart));
  134. map.setCenter(new SuperMap.LonLat(arr[1], arr[2]), 0);
  135. }).hover(
  136. function () {
  137. $("#startSugList li.dropListMouseOver").removeClass("dropListMouseOver");
  138. $(this).addClass("dropListMouseOver");
  139. },
  140. function () {
  141. $(this).removeClass("dropListMouseOver");
  142. }
  143. );
  144. }
  145. }
  146. }
  147. function stopQueryFailed(result) {
  148. widgets.alert.showAlert(result, false);
  149. }
  150. }
  151. function updateStartInputByResult(event) {
  152. clear();
  153. var code = event.keyCode, current, input;
  154. if (code === 38 || code === 40) {
  155. isStartKey = true;
  156. } else if (code === 13) {
  157. } else {
  158. isStartKey = false;
  159. return;
  160. }
  161. current = $("#startSugList li.dropListMouseOver");
  162. input = $("#startInput");
  163. if (code === 13) {
  164. if (current.length !== 0) {
  165. input.val(current.text());
  166. input.attr("text", current.attr("id"));
  167. $("#startSugList").empty();
  168. $("#startSugPopup").removeClass("show");
  169. var arr = current.attr("id").split(",");
  170. startLayer.clearMarkers();
  171. startLayer.addMarker(new SuperMap.Marker(new SuperMap.LonLat(arr[1], arr[2]), iconstart));
  172. map.setCenter(new SuperMap.LonLat(arr[1], arr[2]), 0);
  173. }
  174. return;
  175. }
  176. if (code === 38) {
  177. if (current.length !== 0) {
  178. current.removeClass("dropListMouseOver");
  179. current = current.prev();
  180. if (current.length === 0) {
  181. current = $("#startSugPopup li:last-child");
  182. }
  183. } else {
  184. current = $("#startSugPopup li:last-child");
  185. }
  186. current.addClass("dropListMouseOver");
  187. input.val(current.text());
  188. input.attr("text", current.attr("id"));
  189. } else if (code === 40) {
  190. if (current.length !== 0) {
  191. current.removeClass("dropListMouseOver");
  192. current = current.next();
  193. if (current.length === 0) {
  194. current = $("#startSugPopup li:first-child");
  195. }
  196. } else {
  197. current = $("#startSugPopup li:first-child");
  198. }
  199. current.addClass("dropListMouseOver");
  200. input.val(current.text());
  201. input.attr("text", current.attr("id"));
  202. }
  203. }
  204. }
  205. //终点搜索文本提示信息框
  206. function addEndSugText() {
  207. var inputDiv = $("<div class='start_end_input'></div>")
  208. $("<span>" + resources.text_endPoint + ":" + "</span>").appendTo(inputDiv);
  209. var input = $("<input type='search' width='60px' id='endInput' value='中安大厦' text='180,6055.3431955,-4270.0725196'/>");
  210. var p = new SuperMap.Geometry.Point(6055.3431955, -4270.0725196);
  211. startLayer.addMarker(new SuperMap.Marker(new SuperMap.LonLat(p.x, p.y), iconend));
  212. input.keyup(findEndStops);
  213. input.keydown(updateEndInputByResult);
  214. input.appendTo(inputDiv);
  215. inputDiv.appendTo($("#func"));
  216. var dataList = $("<div id='endSugPopup' class='sugpopup'></div>");
  217. $("<ul id='endSugList' class='dropList'></ul>").appendTo(dataList);
  218. dataList.appendTo(inputDiv);
  219. function findEndStops(event) {
  220. clear();
  221. var code = event.keyCode;
  222. if (isEndKey) return;
  223. if (code === 37 || code === 38 || code === 39 || code === 40 || code === 13) return;
  224. markerLayer.clearMarkers();
  225. vectorLayer.removeAllFeatures();
  226. endLayer.clearMarkers();
  227. $("#endInput").attr("text", "");
  228. var txt = $("#startInput").attr("text");
  229. if (txt) {
  230. var start = txt.split(",");
  231. startLayer.addMarker(new SuperMap.Marker(new SuperMap.LonLat(start[1], start[2]), iconstart));
  232. }
  233. var list = $("#endSugList");
  234. list.empty();
  235. var popup = $("#endSugPopup");
  236. var endName = event.target.value;
  237. if (!endName) {
  238. popup.css("display", "none");
  239. return;
  240. }
  241. var params = new SuperMap.REST.StopQueryParameters({
  242. keyWord: endName,
  243. returnPosition: true
  244. });
  245. var iserver = new SuperMap.REST.StopQueryService(traffic_transfer, {
  246. eventListeners: {
  247. processCompleted: stopQuerySucceed,
  248. processFailed: stopQueryFailed
  249. }
  250. });
  251. iserver.processAsync(params);
  252. function stopQuerySucceed(stopQueryEvent) {
  253. popup.addClass("show").css("display", "block");
  254. if (!stopQueryEvent.result.transferStopInfos.length) {
  255. $("<li>" + resources.text_notFindEPoint + "</li>").appendTo(list);
  256. noEnd = true;
  257. } else {
  258. noEnd = false;
  259. for (var i = 0, len = stopQueryEvent.result.transferStopInfos.length; i < len; i++) {
  260. var station = stopQueryEvent.result.transferStopInfos[i];
  261. var value = station.stopID + "," + station.position.x + "," + station.position.y;
  262. $("<li id='" + value + "'>" + station.name + "</li>").appendTo(list);
  263. list.find("li").click(function () {
  264. var input = $("#endInput");
  265. input.val($(this).text());
  266. input.attr("text", $(this).attr("id"));
  267. $("#endSugList").empty();
  268. popup.removeClass("show");
  269. var arr = $(this).attr("id").split(",");
  270. endLayer.addMarker(new SuperMap.Marker(new SuperMap.LonLat(arr[1], arr[2]), iconend));
  271. map.setCenter(new SuperMap.LonLat(arr[1], arr[2]), 0);
  272. }).hover(
  273. function () {
  274. $("#endSugList li.dropListMouseOver").removeClass("dropListMouseOver");
  275. $(this).addClass("dropListMouseOver");
  276. },
  277. function () {
  278. $(this).removeClass("dropListMouseOver");
  279. }
  280. );
  281. }
  282. }
  283. }
  284. function stopQueryFailed(result) {
  285. widgets.alert.showAlert(result, false);
  286. }
  287. }
  288. function updateEndInputByResult(event) {
  289. clear();
  290. var code = event.keyCode, current, input;
  291. if (code === 38 || code === 40) {
  292. isStartKey = true;
  293. } else if (code === 13) {
  294. } else {
  295. isStartKey = false;
  296. return;
  297. }
  298. current = $("#endSugList li.dropListMouseOver");
  299. input = $("#endInput");
  300. if (code === 13) {
  301. if (current.length !== 0) {
  302. input.val(current.text());
  303. input.attr("text", current.attr("id"));
  304. $("#endSugList").empty();
  305. $("#endSugPopup").removeClass("show");
  306. var arr = current.attr("id").split(",");
  307. endLayer.clearMarkers();
  308. endLayer.addMarker(new SuperMap.Marker(new SuperMap.LonLat(arr[1], arr[2]), iconend));
  309. map.setCenter(new SuperMap.LonLat(arr[1], arr[2]), 0);
  310. }
  311. return;
  312. }
  313. if (code === 38) {
  314. if (current.length !== 0) {
  315. current.removeClass("dropListMouseOver");
  316. current = current.prev();
  317. if (current.length === 0) {
  318. current = $("#endSugList li:last-child");
  319. }
  320. } else {
  321. current = $("#endSugList li:last-child");
  322. }
  323. current.addClass("dropListMouseOver");
  324. input.val(current.text());
  325. input.attr("text", current.attr("id"));
  326. } else if (code === 40) {
  327. if (current.length !== 0) {
  328. current.removeClass("dropListMouseOver");
  329. current = current.next();
  330. if (current.length === 0) {
  331. current = $("#endSugList li:first-child");
  332. }
  333. } else {
  334. current = $("#endSugList li:first-child");
  335. }
  336. current.addClass("dropListMouseOver");
  337. input.val(current.text());
  338. input.attr("text", current.attr("id"));
  339. }
  340. }
  341. }
  342. var host = window.isLocal ? window.server : "https://iserver.supermap.io",
  343. changChun_Map = host + "/iserver/services/map-changchun/rest/maps/长春市区图",
  344. traffic_transfer = host + "/iserver/services/traffictransferanalyst-sample/restjsr/traffictransferanalyst/Traffic-Changchun";
  345. init();
  346. function init() {
  347. map = new SuperMap.Map("map", {
  348. controls: [
  349. new SuperMap.Control.ScaleLine(),
  350. new SuperMap.Control.Zoom(),
  351. new SuperMap.Control.MousePosition(),
  352. new SuperMap.Control.Navigation({
  353. dragPanOptions: {
  354. enableKinetic: true
  355. }
  356. })]
  357. });
  358. vectorLayer = new SuperMap.Layer.Vector("Vector Layer");
  359. tempRedLayer = new SuperMap.Layer.Vector("Red Layer");
  360. markerLayer = new SuperMap.Layer.Markers("Marker Layer");
  361. startLayer = new SuperMap.Layer.Markers("start Layer");
  362. endLayer = new SuperMap.Layer.Markers("end Layer");
  363. layer = new SuperMap.Layer.TiledDynamicRESTLayer("World", changChun_Map, {
  364. transparent: true,
  365. cacheEnabled: true
  366. }, {maxResolution: "auto"});
  367. layer.events.on({"layerInitialized": addLayer});
  368. function addLayer() {
  369. map.addLayers([layer, vectorLayer, markerLayer, startLayer, endLayer, tempRedLayer]);
  370. map.setCenter(new SuperMap.LonLat(4503.6240321526, -3861.911472192499), 0);
  371. addStartSugText();
  372. addEndSugText();
  373. addDropDownMenu(resources.text_transferScheme);
  374. addDropDownMenuItem(resources.text_minTime, lessTime);
  375. addDropDownMenuItem(resources.text_minDistance, minDistance);
  376. addDropDownMenuItem(resources.text_lessWalk, lessWalk);
  377. addDropDownMenuItem(resources.text_lessTransfer, lessTransfer);
  378. }
  379. function getStartEndStopID() {
  380. if (!$("#startInput").attr("value")) {
  381. widgets.alert.showAlert(resources.msg_query + resources.msg_selectSPoint, true);
  382. return;
  383. }
  384. if (!$("#endInput").attr("value")) {
  385. widgets.alert.showAlert(resources.msg_query + resources.msg_selectEPoint, true);
  386. return;
  387. }
  388. var start = $("#startInput").attr("text");
  389. var startList = $("#startSugList li");
  390. if (startList.length === 1 && startList.html() !== resources.text_notFindSPoint) {
  391. $("#startInput").attr("text", startList.attr("id"));
  392. $("#startInput").attr("value", startList.html());
  393. start = startList.attr("id").split(",")[0];
  394. } else {
  395. if (start) {
  396. start = parseInt(start.split(",")[0]);
  397. } else {
  398. var startStop = $("#startSugList").find("li")[0];
  399. var startStopID = startStop.getAttribute("id");
  400. var startStopName = startStop.innerHTML;
  401. if (!startStopID) {
  402. widgets.alert.showAlert(resources.msg_query + resources.msg_noSInfo, false);
  403. return;
  404. }
  405. $("#startInput").attr("text", startStopID);
  406. $("#startInput").attr("value", startStopName);
  407. start = parseInt(startStopID.split(",")[0]);
  408. }
  409. }
  410. var end = $("#endInput").attr("text");
  411. var endList = $("#endSugList li");
  412. if (endList.length === 1 && endList.html() !== resources.text_notFindEPoint) {
  413. $("#endInput").attr("text", endList.attr("id"));
  414. $("#endInput").attr("value", endList.html());
  415. end = endList.attr("id").split(",")[0];
  416. } else {
  417. if (end) {
  418. end = parseInt(end.split(",")[0]);
  419. } else {
  420. var endStop = $("#endSugList").find("li")[0];
  421. var endStopID = endStop.getAttribute("id");
  422. var endStopName = endStop.innerHTML;
  423. if (!endStopID) {
  424. widgets.alert.showAlert(resources.msg_query + resources.msg_noEInfo, false);
  425. return;
  426. }
  427. $("#endInput").attr("text", endStopID);
  428. $("#endInput").attr("value", endStopName);
  429. end = parseInt(endStopID.split(",")[0]);
  430. }
  431. }
  432. $("#startSugList").empty();
  433. $("#startSugPopup").removeClass("show");
  434. $("#endSugList").empty();
  435. $("#endSugPopup").removeClass("show");
  436. return [start, end];
  437. }
  438. //最小时间公交换乘
  439. function lessTime() {
  440. clear();
  441. window.closeWindow();
  442. var stopIDs = getStartEndStopID();
  443. if (stopIDs) {
  444. executeTrafficTransfer(stopIDs, SuperMap.REST.TransferTactic.LESS_TIME);
  445. }
  446. }
  447. //最短距离的公交换乘
  448. function minDistance() {
  449. clear();
  450. window.closeWindow();
  451. var stopIDs = getStartEndStopID();
  452. if (stopIDs) {
  453. executeTrafficTransfer(stopIDs, SuperMap.REST.TransferTactic.MIN_DISTANCE);
  454. }
  455. }
  456. //最少步行公交换乘
  457. function lessWalk() {
  458. clear();
  459. window.closeWindow();
  460. var stopIDs = getStartEndStopID();
  461. if (stopIDs) {
  462. executeTrafficTransfer(stopIDs, SuperMap.REST.TransferTactic.LESS_WALK);
  463. }
  464. }
  465. //少换乘公交换乘
  466. function lessTransfer() {
  467. clear();
  468. window.closeWindow();
  469. var stopIDs = getStartEndStopID();
  470. if (stopIDs) {
  471. executeTrafficTransfer(stopIDs, SuperMap.REST.TransferTactic.LESS_TRANSFER);
  472. }
  473. }
  474. //定义公交换乘,points表示起始点坐标,transferTactic表示换乘策略类型
  475. //包括时间最短、距离最短、最少换乘、最少步行四种选择
  476. function executeTrafficTransfer(points, transferTactic) {
  477. if (noStart) {
  478. widgets.alert.showAlert(resources.msg_query + resources.text_notFindSPoint, false);
  479. return;
  480. }
  481. if (noEnd) {
  482. widgets.alert.showAlert(resources.msg_query + resources.text_notFindEPoint, false);
  483. return;
  484. }
  485. window.paths = {};
  486. window.paths["points"] = points;
  487. vectorLayer.removeAllFeatures();
  488. execTransSolutionsQuery(points, transferTactic, "NONE");
  489. }
  490. }
  491. //transGuide代表换乘方式,transSolutions代表换乘方案,indexX代表方案索引号
  492. function fillTransferInfo(transGuide, transSolutions, indexX) {
  493. markerLayer.clearMarkers();
  494. vectorLayer.removeAllFeatures();
  495. tempRedLayer.removeAllFeatures();
  496. if (popwin) map.removePopup(popwin);
  497. if (transGuide && transGuide.items.length) {
  498. var items = transGuide.items;
  499. for (var itemIndex = 0, itemLen = items.length; itemIndex < itemLen; itemIndex++) {
  500. var feature = new SuperMap.Feature.Vector();
  501. feature.geometry = items[itemIndex].route;
  502. feature.style = styleLine;
  503. vectorLayer.addFeatures(feature);
  504. }
  505. markerLayer.addMarker(new SuperMap.Marker(new SuperMap.LonLat(items[0].startPosition.x, items[0].startPosition.y), iconstart));
  506. markerLayer.addMarker(new SuperMap.Marker(new SuperMap.LonLat(items[items.length - 1].endPosition.x, items[items.length - 1].endPosition.y), iconend));
  507. }
  508. var table = $("<table id='trafficRes' class='table table-bordered'></table>");
  509. var startStop = $("<tr></tr>");
  510. $("<td class='start_transfer' ></td>").appendTo(startStop);
  511. $("<td colspan='2'><span class='busLink bgSpan'><span style='display:none'>" + transGuide.items[0].startPosition.x + "," + transGuide.items[0].startPosition.y + "</span>" + transGuide.items[0].startStopName + "</span></td>").appendTo(startStop);
  512. startStop.appendTo(table);
  513. var indexY = 0;
  514. for (var iiii = 0, iiiiLen = transGuide.items.length; iiii < iiiiLen; iiii++) {
  515. var item = transGuide.items[iiii];
  516. var tr2 = $("<tr></tr>");
  517. if (item.isWalking) {
  518. $("<td class='step_transfer' ></td>").appendTo(tr2);
  519. $("<td>" + resources.text_walkTO + "<a class='busLink'><span style='display:none'>" + item.endPosition.x + "," + item.endPosition.y + "</span>" + item.endStopName + "</a></td>").appendTo(tr2);
  520. $("<td>" + parseInt(item.distance) + resources.msg_m + "</td>").appendTo(tr2);
  521. } else {
  522. var otherLines = transSolutions[indexX].linesItems[indexY],
  523. links = "";
  524. if (otherLines && otherLines.lineItems.length > 1) {
  525. links = "</br>" + resources.text_alsoRide;
  526. for (var oti = 0, otLen = otherLines.lineItems.length; oti < otLen; oti++) {
  527. var line = otherLines.lineItems[oti];
  528. if (item.lineName !== line.lineName) {
  529. var other = indexX + "," + indexY + "," + oti + ",0";
  530. links += "<a class='busLink'><span style='display:none'>" + other + "</span>" + line.lineName + "</a>";
  531. }
  532. }
  533. }
  534. $("<td class='bus_transfer'></td>").appendTo(tr2);
  535. var points = item.route.components, pointStr = "";
  536. for (var i = 0; i < points.length; i++) {
  537. pointStr += points[i].x + " " + points[i].y;
  538. if (i != points.length - 1) {
  539. pointStr += ",";
  540. }
  541. }
  542. $("<td>" + resources.text_ride + "<a class='busLink'>" + item.lineName + "<span style='display:none'>" + pointStr + "</span></a>" + resources.text_debus1 + "<a class='busLink'><span style='display:none'>" + item.endPosition.x + "," + item.endPosition.y + "</span>" + item.endStopName + "</a>" + resources.text_debus2 + links + "</td>").appendTo(tr2);
  543. $("<td>" + item.passStopCount + resources.text_stops + "</td>").appendTo(tr2);
  544. indexY++;
  545. }
  546. tr2.appendTo(table);
  547. }
  548. var endStop = $("<tr></tr>");
  549. endStop.appendTo(table);
  550. $("<td class='end_transfer' ></td>").appendTo(endStop);
  551. $("<td colspan='2'><span class='busLink bgSpan'><span style='display:none'>" + transGuide.items[transGuide.items.length - 1].endPosition.x + "," + transGuide.items[transGuide.items.length - 1].endPosition.y + "</span>" + transGuide.items[transGuide.items.length - 1].endStopName + "</span></td>").appendTo(endStop);
  552. return table;
  553. }
  554. function execTransSolutionsQuery(points, tactic, preference, chked) {
  555. //配置公交换乘参数
  556. var params = new SuperMap.REST.TransferSolutionParameters({
  557. solutionCount: 6,//最大换乘导引数量
  558. transferTactic: tactic,//公交换乘策略类型
  559. transferPreference: preference,
  560. walkingRatio: 10,//步行与公交的消耗权重比
  561. points: points //起始点坐标
  562. });
  563. // 配置公交换乘服务,监听两个事件,processCompleted和processFailed,服务端成功返回查询结果时触发
  564. //processCompleted 事件,服务端返回查询结果失败时触发 processFailed 事件。
  565. var iserver = new SuperMap.REST.TransferSolutionService(traffic_transfer, {
  566. eventListeners: {
  567. processCompleted: transferSolutionsSucceed,
  568. processFailed: transferSolutionsFailed
  569. }
  570. });
  571. //execute
  572. iserver.processAsync(params);
  573. //执行公交换乘成功返回结果
  574. function transferSolutionsSucceed(event) {
  575. $("#result").empty();
  576. markerLayer.clearMarkers();
  577. startLayer.clearMarkers();
  578. endLayer.clearMarkers();
  579. //在地图上叠加符号信息
  580. var transGuide = event.result.transferGuide,
  581. transSolutions = event.result.solutionItems,
  582. Solutions = [];
  583. for (var j = 0; j < transSolutions.length; j++) {
  584. var linesItems = transSolutions[j].linesItems, transSolution = [];
  585. for (var jj = 0; jj < linesItems.length; jj++) {
  586. var lineItems = linesItems[jj].lineItems, items = [];
  587. for (var jjj = 0; jjj < lineItems.length; jjj++) {
  588. var lineItem = lineItems[jjj];
  589. items.push("{'lineID':" + lineItem.lineID + ",'startStopIndex':" + lineItem.startStopIndex + ",'endStopIndex':" + lineItem.endStopIndex + "}");
  590. }
  591. transSolution.push(items);
  592. }
  593. Solutions.push(transSolution);
  594. }
  595. window.paths["transSolutions"] = transSolutions;
  596. window.paths["solutions"] = Solutions;
  597. if (!transGuide || !transSolutions) return;
  598. var transRes = $("<div class='transferResult'></div>");
  599. var solution, lines, line,
  600. dispStatus = "block",
  601. strMessage = "";
  602. for (var i = 0, iLen = transSolutions.length; i < iLen; i++) {
  603. solution = transSolutions[i];
  604. var title = "";
  605. for (var ii = 0, iiLen = solution.linesItems.length; ii < iiLen; ii++) {
  606. lines = solution.linesItems[ii];
  607. for (var iii = 0, iiiLen = lines.lineItems.length; iii < iiiLen; iii++) {
  608. line = lines.lineItems[iii];
  609. if (iii !== iiiLen - 1) {
  610. title += line.lineName + "/";
  611. } else {
  612. title += line.lineName;
  613. }
  614. }
  615. if (ii !== iiLen - 1) {
  616. title += " → ";
  617. }
  618. }
  619. //存放默认路径,默认取数组的第一个元素
  620. var path = "[", pLine;
  621. var pathLines = solution.linesItems;
  622. for (var pi = 0, pLen = pathLines.length; pi < pLen; pi++) {
  623. pLine = pathLines[pi].lineItems[0];
  624. path += "{'lineID':" + pLine.lineID + ",'startStopIndex':" + pLine.startStopIndex + ",'endStopIndex':" + pLine.endStopIndex + "}";
  625. if (pi !== pLen - 1) path += ",";
  626. }
  627. path += "]";
  628. var index = "solutions_" + i;
  629. window.paths[index] = path;
  630. $("<div class='transferSolution' id='transferSolution-" + i + "'><span class='transferIndex'>" + resources.text_scheme + (i + 1) + ":</span>" + title + "</div>").appendTo(transRes);
  631. if (i !== 0) {
  632. dispStatus = "none";
  633. }
  634. var list = $("<div class='transferInfo' id='transferInfo-" + i + "' style='display:" + dispStatus + "'></div>").appendTo(transRes);
  635. list.appendTo(transRes);
  636. if (i !== 0) {
  637. } else {
  638. fillTransferInfo(transGuide, transSolutions, 0, 0).appendTo(list);
  639. }
  640. }
  641. strMessage += transRes.html();
  642. showWindow(strMessage, chked);
  643. bindSolutionsClickEvent();
  644. bindPreferenceClickEvent();
  645. setPopup();
  646. function bindSolutionsClickEvent() {
  647. for (var i = 0; i < 6; i++) {
  648. $("#transferSolution-" + i).click(toggleGuideItems);
  649. }
  650. function toggleGuideItems(e) {
  651. for (var i = 0; i < 6; i++) {
  652. $("#transferInfo-" + i).hide(500);
  653. }
  654. var id = parseInt(e.currentTarget.id.split("-")[1]);
  655. $("#transferInfo-" + id).show(500);
  656. var transLines = window.paths["solutions_" + id];
  657. execTransPathQuery(id, transLines);
  658. }
  659. }
  660. function bindPreferenceClickEvent() {
  661. $("#preferenceCheck").click(setTransferPreference);
  662. function setTransferPreference(e) {
  663. var preference = SuperMap.REST.TransferPreference.NONE;
  664. var chked = "unchecked";
  665. if (e.currentTarget.checked) {
  666. preference = SuperMap.REST.TransferPreference.NO_SUBWAY;
  667. chked = "checked";
  668. }
  669. execTransSolutionsQuery(points, tactic, preference, chked);
  670. }
  671. }
  672. }
  673. //执行公交换乘失败返回结果
  674. function transferSolutionsFailed(event) {
  675. widgets.alert.showAlert("错误提示:" + event.error.errorMsg, false);
  676. }
  677. }
  678. function execTransPathQuery(id, transLines) {
  679. var params = new SuperMap.REST.TransferPathParameters({
  680. points: window.paths["points"],
  681. transferLines: transLines
  682. });
  683. var iserver = new SuperMap.REST.TransferPathService(traffic_transfer, {
  684. eventListeners: {
  685. processCompleted: transferPathSucceed,
  686. processFailed: transferPathFailed
  687. }
  688. });
  689. iserver.processAsync(params);
  690. function transferPathSucceed(event) {
  691. $("#transferInfo-" + id).empty();
  692. var transGuide = event.result.transferGuide;
  693. transSolutions = window.paths["transSolutions"];
  694. map.setCenter(new SuperMap.LonLat(4503.6240321526, -3861.911472192499), 0);
  695. fillTransferInfo(transGuide, transSolutions, id).appendTo($("#transferInfo-" + id));
  696. setPopup();
  697. }
  698. function transferPathFailed(event) {
  699. }
  700. }
  701. function setPopup() {
  702. $(".busLink").click(function () {
  703. if (popwin) map.removePopup(popwin);
  704. tempRedLayer.removeAllFeatures();
  705. var points = this.children[0].innerText.split(","), lonLat;
  706. if (points.length === 2) {
  707. lonLat = new SuperMap.LonLat(points[0], points[1]);
  708. var contentHTML = "<div style='font-size:.8em; opacity: 0.8; overflow-y:hidden;'><br>";
  709. contentHTML += this.innerHTML + "<br></div>";
  710. //初始化一个弹出窗口,当某个地图要素被选中时会弹出此窗口,用来显示选中地图要素的属性信息
  711. if (popwin) map.removePopup(popwin);
  712. popwin = new SuperMap.Popup.FramedCloud("chicken",
  713. lonLat,
  714. null,
  715. contentHTML,
  716. null,
  717. true,
  718. null,
  719. true);
  720. map.addPopup(popwin);
  721. map.setCenter(lonLat, 2);
  722. } else if (points.length === 4 && points[3] === "0") {
  723. var linesItems = window.paths["solutions"][points[0]], lineStr = "[";
  724. for (var i = 0; i < linesItems.length; i++) {
  725. var lineItem = linesItems[i][0], j = parseInt(points[1]);
  726. if (i !== j) {
  727. lineStr += lineItem;//"{'lineID':" + lineItem.lineID + ",'startStopIndex':" + lineItem.startStopIndex + ",'endStopIndex':" + lineItem.endStopIndex + "}";
  728. } else if (i === j) {
  729. lineItem = linesItems[points[1]][points[2]];
  730. lineStr += lineItem;//"{'lineID':" + lineItem.lineID + ",'startStopIndex':" + lineItem.startStopIndex + ",'endStopIndex':" + lineItem.endStopIndex + "}"
  731. }
  732. if (i !== linesItems.length - 1) {
  733. lineStr += ",";
  734. }
  735. }
  736. lineStr += "]";
  737. $("#transferInfo-" + points[0]).hide(500);
  738. execTransPathQuery(points[0], lineStr);
  739. $("#transferInfo-" + points[0]).show(500);
  740. } else {
  741. var linePoints = [];
  742. for (var i = 0; i < points.length; i++) {
  743. var arr = points[i].split(" ");
  744. var point = new SuperMap.Geometry.Point(arr[0], arr[1]);
  745. linePoints.push(point);
  746. }
  747. var lineString = new SuperMap.Geometry.LineString(linePoints);
  748. var feature = new SuperMap.Feature.Vector();
  749. feature.geometry = lineString;
  750. feature.style = styleLineRed;
  751. tempRedLayer.addFeatures(feature);
  752. lonLat = lineString.getBounds().getCenterLonLat();
  753. map.setCenter(lonLat, 2);
  754. map.zoomToExtent(lineString.getBounds());
  755. }
  756. });
  757. }
  758. function clear() {
  759. $('div').remove('#mapAlert');
  760. tempRedLayer.removeAllFeatures();
  761. vectorLayer.removeAllFeatures();
  762. popwin && map && map.removePopup(popwin);
  763. }
  764. function showWindow(winMessage, chked) {
  765. if (document.getElementById("popupWin")) {
  766. $("#popupWin").css("display", "block");
  767. } else {
  768. $("<div id='popupWin'></div>").addClass("popupWindow").appendTo($("#result"));
  769. }
  770. if (chked !== "checked") {
  771. chked = "unchecked";
  772. }
  773. var str = "";
  774. str += '<div class="winTitle" onMouseDown="startMove(this,event)" onMouseUp="stopMove(this,event)"><span class="title_left">' + resources.text_trafficTransferScheme + '</span><span class="title_right"><a href="javascript:closeWindow()" title="关闭窗口">' + resources.text_close + '</a></span><br style="clear:right"/></div>'; //标题栏
  775. str += '<div class="transferPreference"><span class="floatLeft">' + resources.text_ridePreference + '</span><input type="checkbox" class="floatLeft" id="preferenceCheck" ' + chked + '/><span class="floatLeft">' + resources.text_noSubway + '</span></div>';
  776. str += '<div class="winContent" style="overflow-y: auto;">';
  777. str += winMessage;
  778. str += '</div>';
  779. $("#popupWin").html(str);
  780. }
  781. window.closeWindow = function () {
  782. $("#result").empty();
  783. $("#popupWin").css("display", "none");
  784. $("#win_bg").css("display", "none");
  785. }
  786. window.startMove = function (o, e) {
  787. var wb;
  788. if (SuperMap.Browser.name === "msie" && e.button === 1) wb = true;
  789. else if (e.button === 0) wb = true;
  790. if (wb) {
  791. var x_pos = parseInt(e.clientX - o.parentNode.offsetLeft);
  792. var y_pos = parseInt(e.clientY - o.parentNode.offsetTop);
  793. if (y_pos <= o.offsetHeight) {
  794. document.documentElement.onmousemove = function (mEvent) {
  795. var eEvent = (SuperMap.Browser.name === "msie") ? event : mEvent;
  796. o.parentNode.style.left = eEvent.clientX - x_pos + "px";
  797. o.parentNode.style.top = eEvent.clientY - y_pos + "px";
  798. }
  799. }
  800. }
  801. }
  802. window.stopMove = function (o, e) {
  803. document.documentElement.onmousemove = null;
  804. }
  805. //添加下拉菜单
  806. function addDropDownMenu(name) {
  807. $("<div class='btn-group'><a class='btn btn-info dropdown-toggle' data-toggle='dropdown' href='#'>" + name + "<span class='caret'></span></a><ul class='dropdown-menu' id='menuList'></ul>").appendTo($("#func"));
  808. }
  809. function addDropDownMenuItem(name, callback) {
  810. var li = $("<li><a href='javascript:void(0)'>" + name + "</a></li>");
  811. li.click(callback);
  812. li.appendTo($("#menuList"));
  813. }
  814. </script>
  815. </body>
  816. </html>