123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878 |
- <!--********************************************************************
- * Copyright© 2000 - 2021 SuperMap Software Co.Ltd. All rights reserved.
- *********************************************************************-->
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <title data-i18n="resources.title_trafficTransfer"></title>
- <style type="text/css">
- body {
- margin: 0;
- overflow: hidden;
- background: #fff;
- width: 100%;
- height: 100%
- }
- #map {
- position: absolute;
- width: 100%;
- height: 100%;
- }
- #toolbar {
- position: absolute;
- top: 50px;
- right: 10px;
- width: 380px;
- text-align: center;
- z-index: 100;
- border-radius: 4px;
- }
- </style>
- </head>
- <body>
- <div id="toolbar" class="panel panel-primary toolbar">
- <div class='panel-heading'><h5 class='panel-title text-center' data-i18n="resources.text_trafficTransfer">
- </h5></div>
- <div class='panel'>
- <div class='input-group'>
- <div id='result' style="width: 360px" class='container'></div>
- </div>
- </div>
- <div id="func" style="margin: 10px 0 10px 0;"></div>
- </div>
- <div id="map"></div>
- <script type="text/javascript" include="bootstrap,widgets.alert" src="../js/include-web.js"></script>
- <script type="text/javascript" exclude="iclient-classic" src="../../dist/classic/include-classic.js"></script>
- <script>
- var map, layer, start, end, vectorLayer, markerLayer, startLayer, endLayer, tempRedLayer,
- globeStartName, globeEndName, popwin,
- noStart = false, noEnd = false, isStartKey = false, isEndKey = false,
- styleLine = {
- strokeColor: "blue",
- strokeWidth: 3,
- strokeLinecap: "round",
- strokeDashstyle: "solid"
- },
- styleLineRed = {
- strokeColor: "red",
- strokeWidth: 4,
- strokeLinecap: "round",
- strokeDashstyle: "solid"
- };
- var size = new SuperMap.Size(21, 21);
- var offset = new SuperMap.Pixel(-(size.w / 2), -size.h);
- var iconstart = new SuperMap.Icon("../img/start_trans.png", size, offset);
- var iconend = new SuperMap.Icon("../img/end_trans.png", size, offset);
- //起点搜索文本提示信息框
- function addStartSugText() {
- var inputDiv = $("<div class='start_end_input'></div>")
- $("<span>" + resources.text_startPoint + ":" + "</span>").appendTo(inputDiv);
- var input = $("<input type='search' width='60px' id='startInput' value='省汽修' text='26,3111.42533851,-5527.73795456'/>");
- var p = new SuperMap.Geometry.Point(3111.42533851, -5527.73795456);
- startLayer.addMarker(new SuperMap.Marker(new SuperMap.LonLat(p.x, p.y), iconstart));
- input.keyup(findStartStops);
- input.keydown(updateStartInputByResult);
- input.appendTo(inputDiv);
- inputDiv.appendTo($("#func"));
- var dataList = $("<div id='startSugPopup' class='sugpopup'></div>");
- $("<ul id='startSugList' class='dropList'></ul>").appendTo(dataList);
- dataList.appendTo(inputDiv);
- function findStartStops(event) {
- clear();
- var code = event.keyCode;
- if (isStartKey) return;
- if (code === 37 || code === 38 || code === 39 || code === 40 || code === 13) return;
- markerLayer.clearMarkers();
- startLayer.clearMarkers();
- vectorLayer.removeAllFeatures();
- $("#startInput").attr("text", "");
- var txt = $("#endInput").attr("text");
- if (txt) {
- var end = txt.split(",");
- endLayer.addMarker(new SuperMap.Marker(new SuperMap.LonLat(end[1], end[2]), iconend));
- }
- var list = $("#startSugList");
- list.empty();
- var popup = $("#startSugPopup");
- var startName = event.target.value;
- if (!startName) {
- popup.css("display", "none");
- return;
- }
- var params = new SuperMap.REST.StopQueryParameters({
- keyWord: startName,
- returnPosition: true
- });
- var iserver = new SuperMap.REST.StopQueryService(traffic_transfer, {
- eventListeners: {
- processCompleted: stopQuerySucceed,
- processFailed: stopQueryFailed
- }
- });
- iserver.processAsync(params);
- //返回根据模糊的地名搜索得到的跟地名有关的所有公交站点的结果
- function stopQuerySucceed(stopQueryEvent) {
- popup.addClass("show").css("display", "block");
- if (!stopQueryEvent.result.transferStopInfos.length) {
- $("<li>" + resources.text_notFindSPoint + "</li>").appendTo(list);
- noStart = true;
- } else {
- noStart = false;
- for (var i = 0, len = stopQueryEvent.result.transferStopInfos.length; i < len; i++) {
- var station = stopQueryEvent.result.transferStopInfos[i];
- var value = station.stopID + "," + station.position.x + "," + station.position.y;
- $("<li id='" + value + "'>" + station.name + "</li>").appendTo(list);
- list.find("li").click(function () {
- var input = $("#startInput");
- input.val($(this).text());
- input.attr("text", $(this).attr("id"));
- $("#startSugList").empty();
- popup.removeClass("show");
- var arr = $(this).attr("id").split(",");
- startLayer.addMarker(new SuperMap.Marker(new SuperMap.LonLat(arr[1], arr[2]), iconstart));
- map.setCenter(new SuperMap.LonLat(arr[1], arr[2]), 0);
- }).hover(
- function () {
- $("#startSugList li.dropListMouseOver").removeClass("dropListMouseOver");
- $(this).addClass("dropListMouseOver");
- },
- function () {
- $(this).removeClass("dropListMouseOver");
- }
- );
- }
- }
- }
- function stopQueryFailed(result) {
- widgets.alert.showAlert(result, false);
- }
- }
- function updateStartInputByResult(event) {
- clear();
- var code = event.keyCode, current, input;
- if (code === 38 || code === 40) {
- isStartKey = true;
- } else if (code === 13) {
- } else {
- isStartKey = false;
- return;
- }
- current = $("#startSugList li.dropListMouseOver");
- input = $("#startInput");
- if (code === 13) {
- if (current.length !== 0) {
- input.val(current.text());
- input.attr("text", current.attr("id"));
- $("#startSugList").empty();
- $("#startSugPopup").removeClass("show");
- var arr = current.attr("id").split(",");
- startLayer.clearMarkers();
- startLayer.addMarker(new SuperMap.Marker(new SuperMap.LonLat(arr[1], arr[2]), iconstart));
- map.setCenter(new SuperMap.LonLat(arr[1], arr[2]), 0);
- }
- return;
- }
- if (code === 38) {
- if (current.length !== 0) {
- current.removeClass("dropListMouseOver");
- current = current.prev();
- if (current.length === 0) {
- current = $("#startSugPopup li:last-child");
- }
- } else {
- current = $("#startSugPopup li:last-child");
- }
- current.addClass("dropListMouseOver");
- input.val(current.text());
- input.attr("text", current.attr("id"));
- } else if (code === 40) {
- if (current.length !== 0) {
- current.removeClass("dropListMouseOver");
- current = current.next();
- if (current.length === 0) {
- current = $("#startSugPopup li:first-child");
- }
- } else {
- current = $("#startSugPopup li:first-child");
- }
- current.addClass("dropListMouseOver");
- input.val(current.text());
- input.attr("text", current.attr("id"));
- }
- }
- }
- //终点搜索文本提示信息框
- function addEndSugText() {
- var inputDiv = $("<div class='start_end_input'></div>")
- $("<span>" + resources.text_endPoint + ":" + "</span>").appendTo(inputDiv);
- var input = $("<input type='search' width='60px' id='endInput' value='中安大厦' text='180,6055.3431955,-4270.0725196'/>");
- var p = new SuperMap.Geometry.Point(6055.3431955, -4270.0725196);
- startLayer.addMarker(new SuperMap.Marker(new SuperMap.LonLat(p.x, p.y), iconend));
- input.keyup(findEndStops);
- input.keydown(updateEndInputByResult);
- input.appendTo(inputDiv);
- inputDiv.appendTo($("#func"));
- var dataList = $("<div id='endSugPopup' class='sugpopup'></div>");
- $("<ul id='endSugList' class='dropList'></ul>").appendTo(dataList);
- dataList.appendTo(inputDiv);
- function findEndStops(event) {
- clear();
- var code = event.keyCode;
- if (isEndKey) return;
- if (code === 37 || code === 38 || code === 39 || code === 40 || code === 13) return;
- markerLayer.clearMarkers();
- vectorLayer.removeAllFeatures();
- endLayer.clearMarkers();
- $("#endInput").attr("text", "");
- var txt = $("#startInput").attr("text");
- if (txt) {
- var start = txt.split(",");
- startLayer.addMarker(new SuperMap.Marker(new SuperMap.LonLat(start[1], start[2]), iconstart));
- }
- var list = $("#endSugList");
- list.empty();
- var popup = $("#endSugPopup");
- var endName = event.target.value;
- if (!endName) {
- popup.css("display", "none");
- return;
- }
- var params = new SuperMap.REST.StopQueryParameters({
- keyWord: endName,
- returnPosition: true
- });
- var iserver = new SuperMap.REST.StopQueryService(traffic_transfer, {
- eventListeners: {
- processCompleted: stopQuerySucceed,
- processFailed: stopQueryFailed
- }
- });
- iserver.processAsync(params);
- function stopQuerySucceed(stopQueryEvent) {
- popup.addClass("show").css("display", "block");
- if (!stopQueryEvent.result.transferStopInfos.length) {
- $("<li>" + resources.text_notFindEPoint + "</li>").appendTo(list);
- noEnd = true;
- } else {
- noEnd = false;
- for (var i = 0, len = stopQueryEvent.result.transferStopInfos.length; i < len; i++) {
- var station = stopQueryEvent.result.transferStopInfos[i];
- var value = station.stopID + "," + station.position.x + "," + station.position.y;
- $("<li id='" + value + "'>" + station.name + "</li>").appendTo(list);
- list.find("li").click(function () {
- var input = $("#endInput");
- input.val($(this).text());
- input.attr("text", $(this).attr("id"));
- $("#endSugList").empty();
- popup.removeClass("show");
- var arr = $(this).attr("id").split(",");
- endLayer.addMarker(new SuperMap.Marker(new SuperMap.LonLat(arr[1], arr[2]), iconend));
- map.setCenter(new SuperMap.LonLat(arr[1], arr[2]), 0);
- }).hover(
- function () {
- $("#endSugList li.dropListMouseOver").removeClass("dropListMouseOver");
- $(this).addClass("dropListMouseOver");
- },
- function () {
- $(this).removeClass("dropListMouseOver");
- }
- );
- }
- }
- }
- function stopQueryFailed(result) {
- widgets.alert.showAlert(result, false);
- }
- }
- function updateEndInputByResult(event) {
- clear();
- var code = event.keyCode, current, input;
- if (code === 38 || code === 40) {
- isStartKey = true;
- } else if (code === 13) {
- } else {
- isStartKey = false;
- return;
- }
- current = $("#endSugList li.dropListMouseOver");
- input = $("#endInput");
- if (code === 13) {
- if (current.length !== 0) {
- input.val(current.text());
- input.attr("text", current.attr("id"));
- $("#endSugList").empty();
- $("#endSugPopup").removeClass("show");
- var arr = current.attr("id").split(",");
- endLayer.clearMarkers();
- endLayer.addMarker(new SuperMap.Marker(new SuperMap.LonLat(arr[1], arr[2]), iconend));
- map.setCenter(new SuperMap.LonLat(arr[1], arr[2]), 0);
- }
- return;
- }
- if (code === 38) {
- if (current.length !== 0) {
- current.removeClass("dropListMouseOver");
- current = current.prev();
- if (current.length === 0) {
- current = $("#endSugList li:last-child");
- }
- } else {
- current = $("#endSugList li:last-child");
- }
- current.addClass("dropListMouseOver");
- input.val(current.text());
- input.attr("text", current.attr("id"));
- } else if (code === 40) {
- if (current.length !== 0) {
- current.removeClass("dropListMouseOver");
- current = current.next();
- if (current.length === 0) {
- current = $("#endSugList li:first-child");
- }
- } else {
- current = $("#endSugList li:first-child");
- }
- current.addClass("dropListMouseOver");
- input.val(current.text());
- input.attr("text", current.attr("id"));
- }
- }
- }
- var host = window.isLocal ? window.server : "https://iserver.supermap.io",
- changChun_Map = host + "/iserver/services/map-changchun/rest/maps/长春市区图",
- traffic_transfer = host + "/iserver/services/traffictransferanalyst-sample/restjsr/traffictransferanalyst/Traffic-Changchun";
- init();
- function init() {
- map = new SuperMap.Map("map", {
- controls: [
- new SuperMap.Control.ScaleLine(),
- new SuperMap.Control.Zoom(),
- new SuperMap.Control.MousePosition(),
- new SuperMap.Control.Navigation({
- dragPanOptions: {
- enableKinetic: true
- }
- })]
- });
- vectorLayer = new SuperMap.Layer.Vector("Vector Layer");
- tempRedLayer = new SuperMap.Layer.Vector("Red Layer");
- markerLayer = new SuperMap.Layer.Markers("Marker Layer");
- startLayer = new SuperMap.Layer.Markers("start Layer");
- endLayer = new SuperMap.Layer.Markers("end Layer");
- layer = new SuperMap.Layer.TiledDynamicRESTLayer("World", changChun_Map, {
- transparent: true,
- cacheEnabled: true
- }, {maxResolution: "auto"});
- layer.events.on({"layerInitialized": addLayer});
- function addLayer() {
- map.addLayers([layer, vectorLayer, markerLayer, startLayer, endLayer, tempRedLayer]);
- map.setCenter(new SuperMap.LonLat(4503.6240321526, -3861.911472192499), 0);
- addStartSugText();
- addEndSugText();
- addDropDownMenu(resources.text_transferScheme);
- addDropDownMenuItem(resources.text_minTime, lessTime);
- addDropDownMenuItem(resources.text_minDistance, minDistance);
- addDropDownMenuItem(resources.text_lessWalk, lessWalk);
- addDropDownMenuItem(resources.text_lessTransfer, lessTransfer);
- }
- function getStartEndStopID() {
- if (!$("#startInput").attr("value")) {
- widgets.alert.showAlert(resources.msg_query + resources.msg_selectSPoint, true);
- return;
- }
- if (!$("#endInput").attr("value")) {
- widgets.alert.showAlert(resources.msg_query + resources.msg_selectEPoint, true);
- return;
- }
- var start = $("#startInput").attr("text");
- var startList = $("#startSugList li");
- if (startList.length === 1 && startList.html() !== resources.text_notFindSPoint) {
- $("#startInput").attr("text", startList.attr("id"));
- $("#startInput").attr("value", startList.html());
- start = startList.attr("id").split(",")[0];
- } else {
- if (start) {
- start = parseInt(start.split(",")[0]);
- } else {
- var startStop = $("#startSugList").find("li")[0];
- var startStopID = startStop.getAttribute("id");
- var startStopName = startStop.innerHTML;
- if (!startStopID) {
- widgets.alert.showAlert(resources.msg_query + resources.msg_noSInfo, false);
- return;
- }
- $("#startInput").attr("text", startStopID);
- $("#startInput").attr("value", startStopName);
- start = parseInt(startStopID.split(",")[0]);
- }
- }
- var end = $("#endInput").attr("text");
- var endList = $("#endSugList li");
- if (endList.length === 1 && endList.html() !== resources.text_notFindEPoint) {
- $("#endInput").attr("text", endList.attr("id"));
- $("#endInput").attr("value", endList.html());
- end = endList.attr("id").split(",")[0];
- } else {
- if (end) {
- end = parseInt(end.split(",")[0]);
- } else {
- var endStop = $("#endSugList").find("li")[0];
- var endStopID = endStop.getAttribute("id");
- var endStopName = endStop.innerHTML;
- if (!endStopID) {
- widgets.alert.showAlert(resources.msg_query + resources.msg_noEInfo, false);
- return;
- }
- $("#endInput").attr("text", endStopID);
- $("#endInput").attr("value", endStopName);
- end = parseInt(endStopID.split(",")[0]);
- }
- }
- $("#startSugList").empty();
- $("#startSugPopup").removeClass("show");
- $("#endSugList").empty();
- $("#endSugPopup").removeClass("show");
- return [start, end];
- }
- //最小时间公交换乘
- function lessTime() {
- clear();
- window.closeWindow();
- var stopIDs = getStartEndStopID();
- if (stopIDs) {
- executeTrafficTransfer(stopIDs, SuperMap.REST.TransferTactic.LESS_TIME);
- }
- }
- //最短距离的公交换乘
- function minDistance() {
- clear();
- window.closeWindow();
- var stopIDs = getStartEndStopID();
- if (stopIDs) {
- executeTrafficTransfer(stopIDs, SuperMap.REST.TransferTactic.MIN_DISTANCE);
- }
- }
- //最少步行公交换乘
- function lessWalk() {
- clear();
- window.closeWindow();
- var stopIDs = getStartEndStopID();
- if (stopIDs) {
- executeTrafficTransfer(stopIDs, SuperMap.REST.TransferTactic.LESS_WALK);
- }
- }
- //少换乘公交换乘
- function lessTransfer() {
- clear();
- window.closeWindow();
- var stopIDs = getStartEndStopID();
- if (stopIDs) {
- executeTrafficTransfer(stopIDs, SuperMap.REST.TransferTactic.LESS_TRANSFER);
- }
- }
- //定义公交换乘,points表示起始点坐标,transferTactic表示换乘策略类型
- //包括时间最短、距离最短、最少换乘、最少步行四种选择
- function executeTrafficTransfer(points, transferTactic) {
- if (noStart) {
- widgets.alert.showAlert(resources.msg_query + resources.text_notFindSPoint, false);
- return;
- }
- if (noEnd) {
- widgets.alert.showAlert(resources.msg_query + resources.text_notFindEPoint, false);
- return;
- }
- window.paths = {};
- window.paths["points"] = points;
- vectorLayer.removeAllFeatures();
- execTransSolutionsQuery(points, transferTactic, "NONE");
- }
- }
- //transGuide代表换乘方式,transSolutions代表换乘方案,indexX代表方案索引号
- function fillTransferInfo(transGuide, transSolutions, indexX) {
- markerLayer.clearMarkers();
- vectorLayer.removeAllFeatures();
- tempRedLayer.removeAllFeatures();
- if (popwin) map.removePopup(popwin);
- if (transGuide && transGuide.items.length) {
- var items = transGuide.items;
- for (var itemIndex = 0, itemLen = items.length; itemIndex < itemLen; itemIndex++) {
- var feature = new SuperMap.Feature.Vector();
- feature.geometry = items[itemIndex].route;
- feature.style = styleLine;
- vectorLayer.addFeatures(feature);
- }
- markerLayer.addMarker(new SuperMap.Marker(new SuperMap.LonLat(items[0].startPosition.x, items[0].startPosition.y), iconstart));
- markerLayer.addMarker(new SuperMap.Marker(new SuperMap.LonLat(items[items.length - 1].endPosition.x, items[items.length - 1].endPosition.y), iconend));
- }
- var table = $("<table id='trafficRes' class='table table-bordered'></table>");
- var startStop = $("<tr></tr>");
- $("<td class='start_transfer' ></td>").appendTo(startStop);
- $("<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);
- startStop.appendTo(table);
- var indexY = 0;
- for (var iiii = 0, iiiiLen = transGuide.items.length; iiii < iiiiLen; iiii++) {
- var item = transGuide.items[iiii];
- var tr2 = $("<tr></tr>");
- if (item.isWalking) {
- $("<td class='step_transfer' ></td>").appendTo(tr2);
- $("<td>" + resources.text_walkTO + "<a class='busLink'><span style='display:none'>" + item.endPosition.x + "," + item.endPosition.y + "</span>" + item.endStopName + "</a></td>").appendTo(tr2);
- $("<td>" + parseInt(item.distance) + resources.msg_m + "</td>").appendTo(tr2);
- } else {
- var otherLines = transSolutions[indexX].linesItems[indexY],
- links = "";
- if (otherLines && otherLines.lineItems.length > 1) {
- links = "</br>" + resources.text_alsoRide;
- for (var oti = 0, otLen = otherLines.lineItems.length; oti < otLen; oti++) {
- var line = otherLines.lineItems[oti];
- if (item.lineName !== line.lineName) {
- var other = indexX + "," + indexY + "," + oti + ",0";
- links += "<a class='busLink'><span style='display:none'>" + other + "</span>" + line.lineName + "</a>";
- }
- }
- }
- $("<td class='bus_transfer'></td>").appendTo(tr2);
- var points = item.route.components, pointStr = "";
- for (var i = 0; i < points.length; i++) {
- pointStr += points[i].x + " " + points[i].y;
- if (i != points.length - 1) {
- pointStr += ",";
- }
- }
- $("<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);
- $("<td>" + item.passStopCount + resources.text_stops + "</td>").appendTo(tr2);
- indexY++;
- }
- tr2.appendTo(table);
- }
- var endStop = $("<tr></tr>");
- endStop.appendTo(table);
- $("<td class='end_transfer' ></td>").appendTo(endStop);
- $("<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);
- return table;
- }
- function execTransSolutionsQuery(points, tactic, preference, chked) {
- //配置公交换乘参数
- var params = new SuperMap.REST.TransferSolutionParameters({
- solutionCount: 6,//最大换乘导引数量
- transferTactic: tactic,//公交换乘策略类型
- transferPreference: preference,
- walkingRatio: 10,//步行与公交的消耗权重比
- points: points //起始点坐标
- });
- // 配置公交换乘服务,监听两个事件,processCompleted和processFailed,服务端成功返回查询结果时触发
- //processCompleted 事件,服务端返回查询结果失败时触发 processFailed 事件。
- var iserver = new SuperMap.REST.TransferSolutionService(traffic_transfer, {
- eventListeners: {
- processCompleted: transferSolutionsSucceed,
- processFailed: transferSolutionsFailed
- }
- });
- //execute
- iserver.processAsync(params);
- //执行公交换乘成功返回结果
- function transferSolutionsSucceed(event) {
- $("#result").empty();
- markerLayer.clearMarkers();
- startLayer.clearMarkers();
- endLayer.clearMarkers();
- //在地图上叠加符号信息
- var transGuide = event.result.transferGuide,
- transSolutions = event.result.solutionItems,
- Solutions = [];
- for (var j = 0; j < transSolutions.length; j++) {
- var linesItems = transSolutions[j].linesItems, transSolution = [];
- for (var jj = 0; jj < linesItems.length; jj++) {
- var lineItems = linesItems[jj].lineItems, items = [];
- for (var jjj = 0; jjj < lineItems.length; jjj++) {
- var lineItem = lineItems[jjj];
- items.push("{'lineID':" + lineItem.lineID + ",'startStopIndex':" + lineItem.startStopIndex + ",'endStopIndex':" + lineItem.endStopIndex + "}");
- }
- transSolution.push(items);
- }
- Solutions.push(transSolution);
- }
- window.paths["transSolutions"] = transSolutions;
- window.paths["solutions"] = Solutions;
- if (!transGuide || !transSolutions) return;
- var transRes = $("<div class='transferResult'></div>");
- var solution, lines, line,
- dispStatus = "block",
- strMessage = "";
- for (var i = 0, iLen = transSolutions.length; i < iLen; i++) {
- solution = transSolutions[i];
- var title = "";
- for (var ii = 0, iiLen = solution.linesItems.length; ii < iiLen; ii++) {
- lines = solution.linesItems[ii];
- for (var iii = 0, iiiLen = lines.lineItems.length; iii < iiiLen; iii++) {
- line = lines.lineItems[iii];
- if (iii !== iiiLen - 1) {
- title += line.lineName + "/";
- } else {
- title += line.lineName;
- }
- }
- if (ii !== iiLen - 1) {
- title += " → ";
- }
- }
- //存放默认路径,默认取数组的第一个元素
- var path = "[", pLine;
- var pathLines = solution.linesItems;
- for (var pi = 0, pLen = pathLines.length; pi < pLen; pi++) {
- pLine = pathLines[pi].lineItems[0];
- path += "{'lineID':" + pLine.lineID + ",'startStopIndex':" + pLine.startStopIndex + ",'endStopIndex':" + pLine.endStopIndex + "}";
- if (pi !== pLen - 1) path += ",";
- }
- path += "]";
- var index = "solutions_" + i;
- window.paths[index] = path;
- $("<div class='transferSolution' id='transferSolution-" + i + "'><span class='transferIndex'>" + resources.text_scheme + (i + 1) + ":</span>" + title + "</div>").appendTo(transRes);
- if (i !== 0) {
- dispStatus = "none";
- }
- var list = $("<div class='transferInfo' id='transferInfo-" + i + "' style='display:" + dispStatus + "'></div>").appendTo(transRes);
- list.appendTo(transRes);
- if (i !== 0) {
- } else {
- fillTransferInfo(transGuide, transSolutions, 0, 0).appendTo(list);
- }
- }
- strMessage += transRes.html();
- showWindow(strMessage, chked);
- bindSolutionsClickEvent();
- bindPreferenceClickEvent();
- setPopup();
- function bindSolutionsClickEvent() {
- for (var i = 0; i < 6; i++) {
- $("#transferSolution-" + i).click(toggleGuideItems);
- }
- function toggleGuideItems(e) {
- for (var i = 0; i < 6; i++) {
- $("#transferInfo-" + i).hide(500);
- }
- var id = parseInt(e.currentTarget.id.split("-")[1]);
- $("#transferInfo-" + id).show(500);
- var transLines = window.paths["solutions_" + id];
- execTransPathQuery(id, transLines);
- }
- }
- function bindPreferenceClickEvent() {
- $("#preferenceCheck").click(setTransferPreference);
- function setTransferPreference(e) {
- var preference = SuperMap.REST.TransferPreference.NONE;
- var chked = "unchecked";
- if (e.currentTarget.checked) {
- preference = SuperMap.REST.TransferPreference.NO_SUBWAY;
- chked = "checked";
- }
- execTransSolutionsQuery(points, tactic, preference, chked);
- }
- }
- }
- //执行公交换乘失败返回结果
- function transferSolutionsFailed(event) {
- widgets.alert.showAlert("错误提示:" + event.error.errorMsg, false);
- }
- }
- function execTransPathQuery(id, transLines) {
- var params = new SuperMap.REST.TransferPathParameters({
- points: window.paths["points"],
- transferLines: transLines
- });
- var iserver = new SuperMap.REST.TransferPathService(traffic_transfer, {
- eventListeners: {
- processCompleted: transferPathSucceed,
- processFailed: transferPathFailed
- }
- });
- iserver.processAsync(params);
- function transferPathSucceed(event) {
- $("#transferInfo-" + id).empty();
- var transGuide = event.result.transferGuide;
- transSolutions = window.paths["transSolutions"];
- map.setCenter(new SuperMap.LonLat(4503.6240321526, -3861.911472192499), 0);
- fillTransferInfo(transGuide, transSolutions, id).appendTo($("#transferInfo-" + id));
- setPopup();
- }
- function transferPathFailed(event) {
- }
- }
- function setPopup() {
- $(".busLink").click(function () {
- if (popwin) map.removePopup(popwin);
- tempRedLayer.removeAllFeatures();
- var points = this.children[0].innerText.split(","), lonLat;
- if (points.length === 2) {
- lonLat = new SuperMap.LonLat(points[0], points[1]);
- var contentHTML = "<div style='font-size:.8em; opacity: 0.8; overflow-y:hidden;'><br>";
- contentHTML += this.innerHTML + "<br></div>";
- //初始化一个弹出窗口,当某个地图要素被选中时会弹出此窗口,用来显示选中地图要素的属性信息
- if (popwin) map.removePopup(popwin);
- popwin = new SuperMap.Popup.FramedCloud("chicken",
- lonLat,
- null,
- contentHTML,
- null,
- true,
- null,
- true);
- map.addPopup(popwin);
- map.setCenter(lonLat, 2);
- } else if (points.length === 4 && points[3] === "0") {
- var linesItems = window.paths["solutions"][points[0]], lineStr = "[";
- for (var i = 0; i < linesItems.length; i++) {
- var lineItem = linesItems[i][0], j = parseInt(points[1]);
- if (i !== j) {
- lineStr += lineItem;//"{'lineID':" + lineItem.lineID + ",'startStopIndex':" + lineItem.startStopIndex + ",'endStopIndex':" + lineItem.endStopIndex + "}";
- } else if (i === j) {
- lineItem = linesItems[points[1]][points[2]];
- lineStr += lineItem;//"{'lineID':" + lineItem.lineID + ",'startStopIndex':" + lineItem.startStopIndex + ",'endStopIndex':" + lineItem.endStopIndex + "}"
- }
- if (i !== linesItems.length - 1) {
- lineStr += ",";
- }
- }
- lineStr += "]";
- $("#transferInfo-" + points[0]).hide(500);
- execTransPathQuery(points[0], lineStr);
- $("#transferInfo-" + points[0]).show(500);
- } else {
- var linePoints = [];
- for (var i = 0; i < points.length; i++) {
- var arr = points[i].split(" ");
- var point = new SuperMap.Geometry.Point(arr[0], arr[1]);
- linePoints.push(point);
- }
- var lineString = new SuperMap.Geometry.LineString(linePoints);
- var feature = new SuperMap.Feature.Vector();
- feature.geometry = lineString;
- feature.style = styleLineRed;
- tempRedLayer.addFeatures(feature);
- lonLat = lineString.getBounds().getCenterLonLat();
- map.setCenter(lonLat, 2);
- map.zoomToExtent(lineString.getBounds());
- }
- });
- }
- function clear() {
- $('div').remove('#mapAlert');
- tempRedLayer.removeAllFeatures();
- vectorLayer.removeAllFeatures();
- popwin && map && map.removePopup(popwin);
- }
- function showWindow(winMessage, chked) {
- if (document.getElementById("popupWin")) {
- $("#popupWin").css("display", "block");
- } else {
- $("<div id='popupWin'></div>").addClass("popupWindow").appendTo($("#result"));
- }
- if (chked !== "checked") {
- chked = "unchecked";
- }
- var str = "";
- 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>'; //标题栏
- 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>';
- str += '<div class="winContent" style="overflow-y: auto;">';
- str += winMessage;
- str += '</div>';
- $("#popupWin").html(str);
- }
- window.closeWindow = function () {
- $("#result").empty();
- $("#popupWin").css("display", "none");
- $("#win_bg").css("display", "none");
- }
- window.startMove = function (o, e) {
- var wb;
- if (SuperMap.Browser.name === "msie" && e.button === 1) wb = true;
- else if (e.button === 0) wb = true;
- if (wb) {
- var x_pos = parseInt(e.clientX - o.parentNode.offsetLeft);
- var y_pos = parseInt(e.clientY - o.parentNode.offsetTop);
- if (y_pos <= o.offsetHeight) {
- document.documentElement.onmousemove = function (mEvent) {
- var eEvent = (SuperMap.Browser.name === "msie") ? event : mEvent;
- o.parentNode.style.left = eEvent.clientX - x_pos + "px";
- o.parentNode.style.top = eEvent.clientY - y_pos + "px";
- }
- }
- }
- }
- window.stopMove = function (o, e) {
- document.documentElement.onmousemove = null;
- }
- //添加下拉菜单
- function addDropDownMenu(name) {
- $("<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"));
- }
- function addDropDownMenuItem(name, callback) {
- var li = $("<li><a href='javascript:void(0)'>" + name + "</a></li>");
- li.click(callback);
- li.appendTo($("#menuList"));
- }
- </script>
- </body>
- </html>
|