toolRouteSearch.js 93 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145
  1. define([
  2. 'html!templates/tools/toolRouteSearch',
  3. 'modDir/service/routeSearch',
  4. 'modDir/service/routeSearchNew',
  5. 'modDir/service/addressSearch',
  6. 'modDir/tools/toolRoutePlaceSearch',
  7. 'css!styles/tools/toolRouteSearch',
  8. 'vendorDir/map23dlib/leaflet.eleation',
  9. 'vendorDir/map23dlib/d3.v3.min',
  10. 'css!styles/tools/toolElevation'
  11. ],
  12. function (tpcLayout, routeSearchF, routeSearchNew, addressSearchF) {
  13. /**
  14. * 模块数据 用于数据存储和外部调用
  15. * @type {Object}
  16. * 数据存放
  17. */
  18. var modValue = {
  19. options: {
  20. searchType: 0
  21. // searchType: 4
  22. },
  23. directionsDataResult: null, //查询结果数据
  24. navigationResult: {}, //导航结果(新)
  25. resultNum: 0, // 导航结果第几条(新)
  26. brushGroup: null, //路线容器
  27. startPoint: { //起点坐标
  28. latlng: null,
  29. name: ''
  30. },
  31. stopPoint: { //终点坐标
  32. latlng: null,
  33. name: ''
  34. },
  35. acrossIndeX: ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'G', 'K', 'L', 'M'],
  36. amongMarkers: {}, //中间点坐标集合
  37. acrossPoints: {}, //途经点坐标集合
  38. avoidPoints: {}, //规避点坐标集合
  39. roadMarker: {}, //路标 包含起点、中间点、终点
  40. resultHtml: null,
  41. pointSearchType: 0, //查询起始点 0为无,1为起点,2为终点
  42. markerGroup: null, //地名标记图层组
  43. TDClickType: null,
  44. routSerchGroup: 'show',
  45. curStation: null,
  46. curCname: null,
  47. // avoidAreas:{
  48. // sBounds:[],
  49. // eBounds:[]
  50. // }
  51. avoidAreas: [] //------------规避区域----------------- }; /* * 模块状态,用于存储模块的状态 例如:收起,关闭
  52. };
  53. var status = {
  54. initialized: false //是否初始化
  55. };
  56. /**
  57. * 初始化
  58. * 事件监听
  59. * @type {Function}
  60. * @returns {*}
  61. */
  62. function init() {
  63. if (!status.initialized) {
  64. // if (map23DConfig.routType == 'DTT') {}
  65. routeSearchF = routeSearchNew;
  66. setLayout();
  67. bindEvent();
  68. status.initialized = true;
  69. modValue.markerGroup = map23DControl.group({
  70. action: 'add'
  71. });
  72. modValue.brushGroup = map23DControl.group({
  73. action: 'add'
  74. });
  75. subscribe();
  76. };
  77. /*ONEMAP.C.publisher.publish({
  78. modName: 'toolRouteSearch'
  79. }, 'topbarClick');*/
  80. remove({
  81. modName: 'toolRouteSearch'
  82. });
  83. };
  84. function layoutResize() {
  85. if (map23DData.display.map2D) {
  86. $("#directionsSearch .waypointWrapper").removeClass('TD');
  87. $('#directionsStart').val(modValue.startPoint.name.length > 0 ? modValue.startPoint.name : '输入起点');
  88. $('#directionsStop').val(modValue.stopPoint.name.length > 0 ? modValue.stopPoint.name : '输入终点');
  89. $(".waypoint .startIcon").unbind('click');
  90. $(".waypoint .stopIcon").unbind('click');
  91. } else if (map23DData.display.map3D) {
  92. $("#directionsSearch .waypointWrapper").addClass('TD');
  93. $('#directionsStart').val(modValue.startPoint.name.length > 0 ? modValue.startPoint.name : '点击左边图标激活地图选点');
  94. $('#directionsStop').val(modValue.stopPoint.name.length > 0 ? modValue.stopPoint.name : '点击左边图标激活地图选点');
  95. bindTDEvent();
  96. }
  97. };
  98. function bindTDEvent() {
  99. $(".waypoint .startIcon").unbind('click').bind('click', function () {
  100. if (modValue.TDClickType != 'start') {
  101. modValue.TDClickType = 'start';
  102. $(".waypoint .startIcon").addClass('active');
  103. $("#acrossPointsList .across-li .acrossIcon").removeClass('active');
  104. $(".waypoint .stopIcon").removeClass('active');
  105. ONEMAP.C.publisher.unSubscribe(TDClickSetPoint, 'map3DclickNew');
  106. ONEMAP.C.publisher.subscribe(TDClickSetPoint, 'map3DclickNew');
  107. } else {
  108. modValue.TDClickType = null;
  109. $(".waypoint .startIcon").removeClass('active');
  110. ONEMAP.C.publisher.unSubscribe(TDClickSetPoint, 'map3DclickNew');
  111. }
  112. })
  113. $("#acrossPointsList .across-li .acrossIcon").unbind('click').bind('click', function () {
  114. var cid = $(this).parent().parent().attr('cid');
  115. if (modValue.TDClickType != 'addacross' || modValue.curTDAcrossId != cid) {
  116. modValue.TDClickType = 'addacross';
  117. modValue.curTDAcrossId = cid;
  118. $("#acrossPointsList .across-li .acrossIcon").removeClass('active');
  119. $(this).addClass('active');
  120. $(".waypoint .stopIcon").removeClass('active');
  121. $(".waypoint .startIcon").removeClass('active');
  122. ONEMAP.C.publisher.unSubscribe(TDClickSetPoint, 'map3DclickNew');
  123. ONEMAP.C.publisher.subscribe(TDClickSetPoint, 'map3DclickNew');
  124. } else {
  125. modValue.TDClickType = null;
  126. modValue.curTDAcrossId = null;
  127. $("#acrossPointsList .across-li .acrossIcon").removeClass('active');
  128. ONEMAP.C.publisher.unSubscribe(TDClickSetPoint, 'map3DclickNew');
  129. }
  130. })
  131. $(".waypoint .stopIcon").unbind('click').bind('click', function () {
  132. if (modValue.TDClickType != 'stop') {
  133. modValue.TDClickType = 'stop';
  134. $(".waypoint .stopIcon").addClass('active');
  135. $("#acrossPointsList .across-li .acrossIcon").removeClass('active');
  136. $(".waypoint .startIcon").removeClass('active');
  137. ONEMAP.C.publisher.unSubscribe(TDClickSetPoint, 'map3DclickNew');
  138. ONEMAP.C.publisher.subscribe(TDClickSetPoint, 'map3DclickNew');
  139. } else {
  140. modValue.TDClickType = null;
  141. $(".waypoint .stopIcon").removeClass('active');
  142. ONEMAP.C.publisher.unSubscribe(TDClickSetPoint, 'map3DclickNew');
  143. }
  144. })
  145. };
  146. function TDClickDelPoint(options) {
  147. if (options.feature.name.split('_')[0] == 'marker23D') {
  148. delAcrossPoint(options.feature.name);
  149. }
  150. };
  151. function TDClickSetPoint(options) {
  152. if (options.latlng.x != 0 || options.latlng.y != 0) {
  153. var latlng = new L.LatLng(options.latlng.y, options.latlng.x);
  154. if (modValue.TDClickType == 'start') {
  155. setStartPoint(latlng);
  156. $(".waypoint .startIcon").removeClass('active');
  157. } else if (modValue.TDClickType == 'stop') {
  158. setStopPoint(latlng);
  159. $(".waypoint .stopIcon").removeClass('active');
  160. } else if (modValue.TDClickType == 'addacross') {
  161. setAcrossPoint(latlng, null, modValue.curTDAcrossId);
  162. modValue.curTDAcrossId = null;
  163. $("#acrossPointsList .across-li .acrossIcon").removeClass('active');
  164. }
  165. modValue.TDClickType = null;
  166. ONEMAP.C.publisher.unSubscribe(TDClickSetPoint, 'map3DclickNew');
  167. }
  168. }
  169. function setLayout() {
  170. $("#routSearchContent .cover-content").empty().append(tpcLayout);
  171. if (map23DData.display.map2D) {
  172. $("#directionsSearch .waypointWrapper").removeClass('TD');
  173. $('#directionsStart').val(modValue.startPoint.name.length > 0 ? modValue.startPoint.name : '输入起点');
  174. $('#directionsStop').val(modValue.stopPoint.name.length > 0 ? modValue.stopPoint.name : '输入终点');
  175. } else if (map23DData.display.map3D) {
  176. $("#directionsSearch .waypointWrapper").addClass('TD');
  177. $('#directionsStart').val(modValue.startPoint.name.length > 0 ? modValue.startPoint.name : '点击左边图标激活地图选点');
  178. $('#directionsStop').val(modValue.stopPoint.name.length > 0 ? modValue.stopPoint.name : '点击左边图标激活地图选点');
  179. bindTDEvent();
  180. }
  181. //滚动条初始
  182. $('#roadViewListWrap').mCustomScrollbar({
  183. scrollInertia: 1000
  184. });
  185. $("#pointSearchResult").mCustomScrollbar({
  186. scrollInertia: 1000
  187. });
  188. $("#directionsSearch .waypointWrapper .across-points-content").mCustomScrollbar({
  189. scrollInertia: 1000
  190. });
  191. $('<div id="routeElevationWrap" class="cover-panel"><iframe frameborder="0" class="cover-iframe"></iframe><div class="cover-content"><button class="btn close">X</button><div id="routeElevationShow"></div></div></div>').appendTo('body');
  192. //拖拽
  193. $("#routSearchContent .header").dragmove($('#routSearchContent'));
  194. };
  195. /**
  196. * 监听事件
  197. */
  198. function subscribe() {
  199. ONEMAP.C.publisher.subscribe(cleanDirections, 'cleanMap');
  200. ONEMAP.C.publisher.subscribe(layoutResize, 'change23D');
  201. //PubSub.subscribe('map3D.featureClick', show3DWeather);
  202. };
  203. function unSubscribe() {
  204. ONEMAP.C.publisher.unSubscribe(TDClickSetPoint, 'map3DclickNew');
  205. };
  206. function controlMyLayer(options) {
  207. switch (options.action) {
  208. case 'remove':
  209. cleanDirections();
  210. remove({
  211. modName: 'clear'
  212. });
  213. break;
  214. case 'opacity':
  215. setGropOpacity(options);
  216. break;
  217. case 'up':
  218. case 'down':
  219. setGroupZIndex(options);
  220. break;
  221. }
  222. }
  223. function setGropOpacity(options) {
  224. options = options.options;
  225. if (options.opacity == 1) {
  226. map23DControl.group({
  227. action: 'show',
  228. guid: modValue.brushGroup
  229. });
  230. map23DControl.group({
  231. action: 'show',
  232. guid: modValue.markerGroup
  233. });
  234. map23DControl.group({
  235. action: 'show',
  236. guid: ONEMAP.M.routPlaceSearch.modValue.markerGroup
  237. });
  238. modValue.routSerchGroup = 'show';
  239. } else {
  240. map23DControl.group({
  241. action: 'hide',
  242. guid: modValue.brushGroup
  243. });
  244. map23DControl.group({
  245. action: 'hide',
  246. guid: modValue.markerGroup
  247. });
  248. map23DControl.group({
  249. action: 'hide',
  250. guid: ONEMAP.M.routPlaceSearch.modValue.markerGroup
  251. });
  252. modValue.routSerchGroup = 'hide';
  253. }
  254. }
  255. function remove(options) {
  256. if (options.modName != 'toolRouteSearch') {
  257. $("#header .tools-routgh").removeClass('cur');
  258. $("#routSearchContent").hide();
  259. $(".slot-title").hide();
  260. if (modValue.elevationControl) {
  261. map2DViewer.map.removeControl(modValue.elevationControl);
  262. modValue.elevationControl = null;
  263. }
  264. $('#routeElevationWrap').hide();
  265. modValue.TDClickType = null;
  266. $(".waypoint .startIcon").removeClass('active');
  267. $(".waypoint .stopIcon").removeClass('active');
  268. unSubscribe();
  269. } else {
  270. if ($("#header .tools-routgh").hasClass('cur')) {
  271. $("#header .tools-routgh").removeClass('cur');
  272. $("#routSearchContent").hide();
  273. if (modValue.elevationControl) {
  274. map2DViewer.map.removeControl(modValue.elevationControl);
  275. modValue.elevationControl = null;
  276. }
  277. $('#routeElevationWrap').hide();
  278. modValue.TDClickType = null;
  279. $(".waypoint .startIcon").removeClass('active');
  280. $(".waypoint .stopIcon").removeClass('active');
  281. unSubscribe();
  282. } else {
  283. $("#header .tools-routgh").addClass('cur');
  284. $("#routSearchContent").show();
  285. }
  286. }
  287. };
  288. /**
  289. * 三维跳转
  290. */
  291. function fly3DInView(lat, lng, zoom) {
  292. map3DViewer.flyTo({
  293. center: {
  294. lat: lat,
  295. lng: lng
  296. },
  297. zoom: zoom,
  298. heading: 0, //摄像机平面角度 正北为0
  299. tilt: 0, //摄像机倾斜角
  300. });
  301. };
  302. /**
  303. * 清空图层
  304. */
  305. function clearMarker() {
  306. if (map23DData.display.map3D) {
  307. $.each(map3DViewer.markers, function (value, key) {
  308. // map3DViewer.label({
  309. // action: 'remove',
  310. // guid: value,
  311. // featureType: 'marker'
  312. // })
  313. })
  314. }
  315. map23DControl.group({
  316. action: 'cleanAll',
  317. guid: modValue.markerGroup
  318. })
  319. };
  320. /**
  321. * 清除路径
  322. */
  323. function cleanDirections() {
  324. if (modValue.appendToMyLayer) {
  325. var options = {
  326. action: "remove",
  327. DOMid: modValue.appendToMyLayer
  328. }
  329. modValue.appendToMyLayer = ONEMAP.M.myLayers.myLayerControl(options);
  330. ONEMAP.C.publisher.unSubscribe(controlMyLayer, modValue.appendToMyLayer);
  331. modValue.appendToMyLayer = null;
  332. }
  333. if (modValue.routSerchGroup == 'hide') {
  334. setGropOpacity({
  335. options: {
  336. opacity: 1
  337. }
  338. })
  339. modValue.routSerchGroup = 'show';
  340. }
  341. //清空线
  342. map23DControl.group({
  343. action: 'cleanAll',
  344. guid: modValue.brushGroup
  345. });
  346. //中间点
  347. map23DControl.group({
  348. action: 'cleanAll',
  349. guid: modValue.markerGroup
  350. });
  351. map23DControl.group({
  352. action: 'cleanAll',
  353. guid: ONEMAP.M.routPlaceSearch.modValue.markerGroup
  354. });
  355. //重置方案
  356. $('.routeTypeList li:eq(1)').css({
  357. "display": "none"
  358. })
  359. $('#routeSearchType').text('第一方案')
  360. //查询结果清除
  361. $("#roadViewList").empty();
  362. $("#slot-busWaysList").empty();
  363. //重置路径搜索界面
  364. $('#directionsStart').val('输入起点');
  365. $('#directionsStop').val('输入终点');
  366. $("#acrossPointsList").empty();
  367. modValue.startPoint = {
  368. latlng: null,
  369. name: ''
  370. };
  371. modValue.stopPoint = {
  372. latlng: null,
  373. name: ''
  374. };
  375. modValue.amongMarkers = {};
  376. modValue.acrossPoints = {};
  377. modValue.avoidPoints = {};
  378. modValue.directionsDataResult = null; //查询结果数据
  379. modValue.navigationResult = {}; //导航结果(新)
  380. modValue.resultNum = 0; // 导航结果第几条(新)
  381. window.routingControl = null;
  382. $('#abtnPrintLine, #d_fav, #directionsSearch .abtnElevation,#downloadLine').hide();
  383. $(".header .thtitle").show();
  384. $('#pointSearchResult').hide();
  385. $('#pointSearchResultWrap').empty();
  386. $("#roadViewListWrap").mCustomScrollbar("update");
  387. $("#pointSearchResult").mCustomScrollbar("update");
  388. $("#directionsSearch .across .waypoint button").removeClass('active');
  389. $(".waypoint .acrossIcon").removeClass('active');
  390. $(".waypoint .stopIcon").removeClass('active');
  391. $(".waypoint .startIcon").removeClass('active');
  392. modValue.TDClickType = null;
  393. modValue.curTDAcrossId = null;
  394. ONEMAP.C.publisher.unSubscribe(TDClickSetPoint, 'map3DclickNew');
  395. ONEMAP.C.publisher.unSubscribe(TDClickDelPoint, 'map3D.featureClick');
  396. };
  397. /**
  398. * 清除地名查询列表
  399. * @return {[type]} [description]
  400. */
  401. function cleanPointSearch() {
  402. clearMarker();
  403. $('#pointSearchResult').hide()
  404. $('#pointSearchResultWrap').empty();
  405. };
  406. /**
  407. * 获取最终查询结果
  408. * @type {Function}
  409. */
  410. function getSearchResult() {
  411. if (modValue.startPoint.latlng && modValue.stopPoint.latlng && modValue.startPoint.name == $("#directionsStart").val() && modValue.stopPoint.name == $("#directionsStop").val()) {
  412. cleanPointSearch();
  413. if (map23DData.display.map2D) {
  414. map2DViewer.groups[modValue.brushGroup].clearLayers();
  415. map2DViewer.markers[modValue.roadMarker.start].addTo(map2DViewer.groups[modValue.brushGroup]);
  416. map2DViewer.markers[modValue.roadMarker.stop].addTo(map2DViewer.groups[modValue.brushGroup]);
  417. for (var item in modValue.amongMarkers) {
  418. modValue.amongMarkers[item].addTo(map2DViewer.groups[modValue.brushGroup]);
  419. }
  420. } else if (map23DData.display.map3D) {
  421. /*map3DViewer.groups[modValue.brushGroup].clearLayers();
  422. map3DViewer.markers[modValue.roadMarker.start].addTo(map3DViewer.groups[modValue.brushGroup]);
  423. map3DViewer.markers[modValue.roadMarker.stop].addTo(map3DViewer.groups[modValue.brushGroup]);
  424. for(var item in modValue.amongMarkers){
  425. amongMarkers[item].addTo(map3DViewer.groups[modValue.brushGroup]);
  426. }*/
  427. }
  428. setNotResultHtml('正在计算路径信息...'); //行车查询
  429. var routeSearch = new routeSearchF();
  430. var via = [];
  431. var avoid = [];
  432. via.push([modValue.startPoint.latlng.lng, modValue.startPoint.latlng.lat]);
  433. for (var viaItem in modValue.acrossPoints) {
  434. if (modValue.acrossPoints.hasOwnProperty(viaItem)) {
  435. via.push([modValue.acrossPoints[viaItem].latlng.lng, modValue.acrossPoints[viaItem].latlng.lat]);
  436. }
  437. }
  438. via.push([modValue.stopPoint.latlng.lng, modValue.stopPoint.latlng.lat]);
  439. for (var avoidItem in modValue.avoidPoints) {
  440. if (modValue.avoidPoints.hasOwnProperty(avoidItem)) {
  441. avoid.push([modValue.avoidPoints[avoidItem].latlng.lng, modValue.avoidPoints[avoidItem].latlng.lat]);
  442. }
  443. }
  444. var searchOptions = {
  445. viaAry: via,
  446. searchType: modValue.options.searchType,
  447. bounds: modValue.avoidAreas
  448. };
  449. routeSearch.getNaviPath(searchOptions, function (data) {
  450. //界面重置
  451. if (data.length == 1) {
  452. //设置界面 一条结果路径
  453. $('.routeTypeList li:eq(1)').css({
  454. "display": "none"
  455. })
  456. } else if (data.length == 2) {
  457. //设置界面 一条结果路径
  458. $('.routeTypeList li:eq(1)').css({
  459. "display": "block"
  460. })
  461. } else {
  462. setNotResultHtml('此线路无路径数据,无法规划路径!');
  463. return false;
  464. }
  465. $('#routeSearchType').html($('.routeTypeList li:eq(0)').text())
  466. modValue.resultNum = 0
  467. modValue.navigationResult = [];
  468. for (var i = 0; i < data.length; i++) {
  469. var minlon = 0,
  470. maxlon = 0,
  471. minlat = 0,
  472. maxlat = 0;
  473. var allPolyline = '';
  474. modValue.navigationResult.push({});
  475. //路径 全部点位(路径过长时,点位过多,渲染速度慢)
  476. for (var k = 0; k < data[i].coordinates.length; k++) {
  477. var lng = data[i].coordinates[k].lng
  478. var lat = data[i].coordinates[k].lat
  479. if (k == 0) {
  480. minlon = data[i].coordinates[k].lng
  481. maxlon = data[i].coordinates[k].lng
  482. minlat = data[i].coordinates[k].lat
  483. maxlat = data[i].coordinates[k].lat
  484. } else {
  485. if (lng < minlon) {
  486. minlon = lng
  487. }
  488. if (lng > maxlon) {
  489. maxlon = lng
  490. }
  491. if (lat < minlat) {
  492. minlat = lat
  493. }
  494. if (lat > maxlat) {
  495. maxlat = lat
  496. }
  497. }
  498. allPolyline += lng + ',' + lat + ",";
  499. }
  500. modValue.navigationResult[i].coors = allPolyline;
  501. modValue.navigationResult[i].coordinates = data[i].coordinates;
  502. modValue.navigationResult[i].totalDistance = data[i].summary.totalDistance //米
  503. modValue.navigationResult[i].totalTime = data[i].summary.totalTime //秒
  504. modValue.navigationResult[i].segmengList = data[i].instructions //文字导航
  505. modValue.navigationResult[i].bounds = {
  506. minlon: minlon - (maxlon - minlon) / 5,
  507. maxlon: maxlon + (maxlon - minlon) / 5,
  508. minlat: minlat - (maxlat - minlat) / 5,
  509. maxlat: maxlat + (maxlat - minlat) / 5,
  510. }; //缩放范围
  511. modValue.navigationResult[i].center = {
  512. lon: (maxlon + minlon) / 2,
  513. lat: (maxlat + minlat) / 2
  514. }
  515. }
  516. setNavigation();
  517. });
  518. // if (map23DData.display.map2D) {
  519. // map2DViewer.map.fitBounds(map2DViewer.groups[modValue.brushGroup].getBounds());
  520. // }
  521. } else if (modValue.startPoint.latlng === null) {
  522. setNotResultHtml('未查询到起点信息,请检查对应查询条件。');
  523. } else if (modValue.stopPoint.latlng === null) {
  524. setNotResultHtml('未查询到终点信息,请检查对应查询条件。');
  525. }
  526. };
  527. /**
  528. * 绘制导航结果 (最新)
  529. * @type {Function}
  530. * @param options {Object}
  531. * @private
  532. */
  533. function setNavigation() {
  534. //移除 本模块点位popup
  535. $('.routePopup').remove();
  536. if (JSON.stringify(modValue.navigationResult) == "{}") {
  537. return;
  538. }
  539. if (map23DData.display.map2D) {
  540. map2DViewer.map.fitBounds([
  541. [modValue.navigationResult[modValue.resultNum].bounds.minlat, modValue.navigationResult[modValue.resultNum].bounds.minlon],
  542. [modValue.navigationResult[modValue.resultNum].bounds.maxlat, modValue.navigationResult[modValue.resultNum].bounds.maxlon]
  543. ]);
  544. } else {
  545. map3DViewer.map.camera.flyTo({
  546. destination: Cesium.Rectangle.fromDegrees(modValue.navigationResult[modValue.resultNum].bounds.minlon,
  547. modValue.navigationResult[modValue.resultNum].bounds.minlat,
  548. modValue.navigationResult[modValue.resultNum].bounds.maxlon,
  549. modValue.navigationResult[modValue.resultNum].bounds.maxlat)
  550. })
  551. }
  552. modValue.directionsDataResult = {}
  553. modValue.directionsDataResult.coors = modValue.navigationResult[modValue.resultNum].coors;
  554. drawCarPolyline({
  555. opacity: 0.8,
  556. lineNum: 0,
  557. color: '#0099ff',
  558. weight: 6
  559. });
  560. parseResultData(modValue.navigationResult[modValue.resultNum].segmengList);
  561. }
  562. /**
  563. * 在地图上画出驾车路线
  564. * @type {Function}
  565. * @param options {Object}
  566. * @private
  567. */
  568. function drawCarPolyline(options) {
  569. if (!modValue.appendToMyLayer) {
  570. var layerLength = ONEMAP.M.myLayers.checkLength();
  571. if (layerLength < map23DConfig.layerMaxLength) {
  572. var mylayeroptions = {
  573. action: "add",
  574. DOM: {
  575. name: '路径规划',
  576. type: "group",
  577. guid: modValue.markerGroup
  578. }
  579. }
  580. modValue.appendToMyLayer = ONEMAP.M.myLayers.myLayerControl(mylayeroptions);
  581. ONEMAP.C.publisher.subscribe(controlMyLayer, modValue.appendToMyLayer);
  582. } else {
  583. ONEMAP.C.publisher.publish({
  584. type: 'warning',
  585. message: '图层数量已达上限,无法上图'
  586. }, 'noteBar::add');
  587. return false;
  588. }
  589. }
  590. $.each(map23DData.polylines, function (i, t) {
  591. map23DControl.polyline({
  592. action: 'remove',
  593. guid: i
  594. })
  595. })
  596. var points = modValue.directionsDataResult.coors;
  597. //转换为可用坐标
  598. var pArray = points.split(',');
  599. var pointLatLng = [];
  600. var dDouble = true;
  601. var temp = [];
  602. for (var i = 0, l = pArray.length; i < l; i++) {
  603. if (dDouble) {
  604. temp = [];
  605. temp.push(pArray[i]);
  606. dDouble = false;
  607. } else {
  608. temp.unshift(pArray[i]);
  609. dDouble = true;
  610. //var gcjloc = transformFromWGSToGCJ(parseFloat(temp[0]),parseFloat(temp[1]));
  611. //temp = [gcjloc.lat.toString(),gcjloc.lng.toString()];
  612. temp = [temp[1], temp[0]];
  613. pointLatLng.push(temp);
  614. }
  615. };
  616. var guid = map23DControl.polyline({
  617. action: 'add',
  618. groupId: modValue.brushGroup,
  619. geojson: {
  620. "properties": {
  621. color: '#666',
  622. weight: options.weight + 3,
  623. opacity: 1,
  624. altitudeMode: 0,
  625. },
  626. "geometry": {
  627. "coordinates": pointLatLng
  628. }
  629. }
  630. })
  631. map3DViewer.polyline({
  632. action: 'hide',
  633. guid: guid
  634. })
  635. // // if (map23DData.display.map3D == true) {
  636. // // }
  637. map23DControl.polyline({
  638. action: 'add',
  639. groupId: modValue.brushGroup,
  640. geojson: {
  641. "properties": {
  642. color: options.color,
  643. weight: options.weight,
  644. opacity: options.opacity,
  645. altitudeMode: 0,
  646. },
  647. "geometry": {
  648. "coordinates": pointLatLng
  649. }
  650. }
  651. })
  652. //modValue.polyLineAll.push(polylineID)
  653. };
  654. /**
  655. * 解析数据 填充节点
  656. * @type {Function}
  657. * @private
  658. */
  659. function parseResultData(data) {
  660. $(".slot-title").show();
  661. $("#roadViewList").empty(); //驾车类型
  662. for (var i = 0, l = data.length; i < l; i++) {
  663. var item = data[i];
  664. var actionType = 'C';
  665. if (!item.modifier || item.modifier == 'Straight') { //直行
  666. actionType = 'C';
  667. }
  668. if (item.modifier == 'Left') { //左转
  669. actionType = 'TL';
  670. }
  671. if (item.modifier == 'Right') { //右转
  672. actionType = 'TR';
  673. }
  674. if (item.modifier == 'Uturn') {
  675. actionType = 'TU';
  676. }
  677. var lng = modValue.navigationResult[modValue.resultNum].coordinates[item.index].lng
  678. var lat = modValue.navigationResult[modValue.resultNum].coordinates[item.index].lat
  679. var nlng = map23DControl.formatDegree(lng);
  680. var nlat = map23DControl.formatDegree(lat);
  681. var li = $('' +
  682. '<li class="withoutChildren" title="' + nlng + ' , ' + nlat + '" data-position-lat="' + lat + '" data-position-lon="' + lng + '">' +
  683. '<span class="maneuverLink">' +
  684. '<span class="maneuverWrapper">' +
  685. '<span class="maneuverHolder">' +
  686. '<span class="maneuverType">' +
  687. '<span class="maneuverNumber ' + actionType + '">' + (i + 1) + '.</span>' +
  688. '</span>' +
  689. '<span class="maneuverProgress">' + item.distance + '&nbsp;米</span>' +
  690. '<span class="maneuverDescription">' +
  691. '<span class="maneuverInstruction">' +
  692. //'<span class="next-street">'+item.roadName+'</span>. ' +
  693. '<span class="distance-description">' + item.text + '</span>.' +
  694. '</span>' +
  695. '</span>' +
  696. '</span>' +
  697. '</span>' +
  698. '</span>' +
  699. '</li><hr/>');
  700. $("#roadViewList").append(li);
  701. var popup_options = {
  702. name: '<span style="font-size:12px;line-height:36px; color:#fff">' + nlng + ' , ' + nlat + '</span>',
  703. content: item.text
  704. };
  705. var popupHtml = creatPopupHtml(popup_options);
  706. var markerId = map23DControl.marker({
  707. action: 'add',
  708. groupId: modValue.markerGroup,
  709. geojson: {
  710. "properties": {
  711. iconUrl: map23DConfig.map23DAssetsUrl + '/images/layout/ico_p_3-' + actionType + '.png',
  712. iconSize: [16, 16],
  713. iconAnchor: [8, 8],
  714. popupAnchor: [0, -8],
  715. //popupContent: popupHtml
  716. },
  717. "geometry": {
  718. "type": "Point",
  719. "coordinates": [lng, lat]
  720. }
  721. }
  722. });
  723. //modValue.markerAll.push(markerId);
  724. map23DControl.marker({
  725. action: 'hide',
  726. guid: markerId,
  727. })
  728. li.bind("click", {
  729. m: markerId,
  730. info: item.text
  731. }, function (e) {
  732. //if(map23DData.display.map2D){
  733. map23DControl.marker({
  734. action: 'show',
  735. guid: e.data.m,
  736. })
  737. $("#roadViewList .cur").removeClass('cur');
  738. $(this).addClass('cur');
  739. var lat = map23DData.markers[e.data.m].geojson.geometry.coordinates[1];
  740. var lng = map23DData.markers[e.data.m].geojson.geometry.coordinates[0];
  741. mapToPoint([lat, lng, 15])
  742. });
  743. }
  744. $("#roadViewList").prepend('<li style="text-align:center; font-size:14px;">总行驶里程: ' + (modValue.navigationResult[modValue.resultNum].totalDistance / 1000).toFixed(3) + '公里</li><hr/>');
  745. $('#abtnPrintLine').show();
  746. $("#downloadLine").show();
  747. //收藏事件
  748. $('#d_fav').show();
  749. $('#directionsSearch .abtnElevation').show();
  750. };
  751. /**
  752. * 无结果列表
  753. * @type {Function}
  754. * @param notText {String} 无结果提示信息
  755. * @returns {*}
  756. * @private
  757. */
  758. function setNotResultHtml(notText) {
  759. $('#roadViewList').empty().append('<p class="not-result">' + notText + '</p>');
  760. };
  761. /**
  762. * 获取起点,终点信息 通过输入框的地名和 起始点的地名匹配判断是否相同 来确定是否进行地名查询
  763. * pointSearchResult
  764. * @return {[type]} [description]
  765. */
  766. function getStartAndStop() {
  767. $('#pointSearchResultWrap').empty();
  768. modValue.resultHtml = '';
  769. modValue.pointSearchType = 0;
  770. if (modValue.startPoint.name != $("#directionsStart").val() && $('#directionsStart').val() != '' && $('#directionsStart').val() != '输入起点') {
  771. //起点展开
  772. modValue.pointSearchType = 1;
  773. buildSearch('start');
  774. };
  775. $.each($("#acrossPointsList li"), function (i, t) {
  776. if ($(t).find('input').val() != "" && $(t).find('input').val() != "输入途经点") {
  777. var cid = $(t).attr('cid');
  778. modValue.pointSearchContentCid = null;
  779. if (!modValue.acrossPoints[cid]) {
  780. modValue.acrossPoints[cid] = {
  781. latlng: null,
  782. name: null
  783. };
  784. if (modValue.pointSearchType == 0) {
  785. modValue.pointSearchType = 3;
  786. }
  787. buildSearch('across', cid);
  788. if (!modValue.pointSearchContentCid) {
  789. modValue.pointSearchContentCid = cid;
  790. }
  791. } else {
  792. if (modValue.acrossPoints[cid].name != $(t).find('input').val()) {
  793. modValue.acrossPoints[cid] = {
  794. latlng: null,
  795. name: $(t).find('input').val()
  796. };
  797. if (modValue.pointSearchType == 0) {
  798. modValue.pointSearchType = 3;
  799. }
  800. buildSearch('across', cid);
  801. if (!modValue.pointSearchContentCid) {
  802. modValue.pointSearchContentCid = cid;
  803. }
  804. }
  805. }
  806. }
  807. })
  808. if (modValue.stopPoint.name != $("#directionsStop").val() && $('#directionsStop').val() != '' && $('#directionsStop').val() != '输入终点') {
  809. //如果不需查询起点的时候设置终点展开
  810. if (modValue.pointSearchType == 0) {
  811. modValue.pointSearchType = 2;
  812. }
  813. buildSearch('stop');
  814. }
  815. setPlaceResultHtml();
  816. };
  817. /**
  818. * 构建查询结果 起始点顺序开始
  819. * @param {[type]} type [description]
  820. * @return {[type]} [description]
  821. */
  822. function buildSearch(type, cid) {
  823. if (cid) {
  824. var indexOf = $("#acrossPointsList").find('li[cid=' + cid + ']').index() + 1;
  825. }
  826. switch (type) {
  827. case 'start':
  828. modValue.resultHtml += '<div id="directionsStartSearch">' +
  829. '<div class="header"><h3>查询起点</h3></div>' +
  830. '<div class="d-waypoints" id="dStartResult"></div>' +
  831. '</div>';
  832. break;
  833. case 'across':
  834. modValue.resultHtml += '<div cid="' + cid + '" class="across-list" id="directionsAcrossSearch' + cid + '">' +
  835. '<div class="header"><h3>查询第' + indexOf + '途经点</h3></div>' +
  836. '<div class="d-waypoints" id="dAcross' + modValue.acrossIndeX[cid] + 'Result"></div>' +
  837. '</div>';
  838. break;
  839. case 'stop':
  840. modValue.resultHtml += '<div id="directionsStopSearch">' +
  841. '<div class="header"><h3>查询终点</h3></div>' +
  842. '<div class="d-waypoints" id="dStopResult"></div>' +
  843. '</div>';
  844. break;
  845. }
  846. };
  847. /**
  848. * 填充侧栏html列表
  849. * @type {Function}
  850. * @returns {*}
  851. * @private
  852. */
  853. function setPlaceResultHtml() {
  854. $('#pointSearchResultWrap').empty().append(modValue.resultHtml);
  855. $('#pointSearchResult').show();
  856. //判断查询状态,设置展开
  857. if (modValue.pointSearchType == 1) {
  858. $('#directionsStartSearch').addClass('open');
  859. } else if (modValue.pointSearchType == 2) {
  860. $('#directionsStopSearch').addClass('open');
  861. } else if (modValue.pointSearchType == 3) {
  862. $("#pointSearchResultWrap .across-list").eq(0).addClass('open');
  863. } else {
  864. return false;
  865. }
  866. //绑定事件
  867. $.each($("#pointSearchResultWrap .across-list"), function (i, t) {
  868. $(t).find('.header').bind('click', function () {
  869. $('#pointSearchResult .open').removeClass('open');
  870. $(this).parent().addClass('open');
  871. $(this).next().empty();
  872. modValue.pointSearchType = 3;
  873. var idName = $(this).next().attr('id');
  874. var cid = $(this).parent().attr('cid');
  875. modValue.pointSearchContentId = idName;
  876. modValue.pointSearchContentCid = cid;
  877. ONEMAP.M.routPlaceSearch.pointSearch({
  878. 'keyWord': $("#acrossPointsList").find('li[cid=' + cid + ']').find('input').val()
  879. });
  880. });
  881. })
  882. $('#directionsStartSearch .header').bind('click', function () {
  883. //if (modValue.pointSearchType == 2) {
  884. $('#pointSearchResult .open').removeClass('open');
  885. $('#directionsStartSearch').addClass('open');
  886. $('#didNametopResult').empty();
  887. //}
  888. modValue.pointSearchType = 1;
  889. ONEMAP.M.routPlaceSearch.pointSearch({
  890. 'keyWord': $("#directionsStart").val()
  891. });
  892. });
  893. $('#directionsStopSearch .header').bind('click', function () {
  894. //if (modValue.pointSearchType == 1) {
  895. $('#pointSearchResult .open').removeClass('open');
  896. $('#directionsStopSearch').addClass('open');
  897. $('#dStartResult').empty();
  898. //}
  899. modValue.pointSearchType = 2;
  900. ONEMAP.M.routPlaceSearch.pointSearch({
  901. 'keyWord': $("#directionsStop").val()
  902. });
  903. });
  904. if (modValue.pointSearchType == 1) {
  905. ONEMAP.M.routPlaceSearch.pointSearch({
  906. 'keyWord': $("#directionsStart").val()
  907. });
  908. }
  909. if (modValue.pointSearchType == 2) {
  910. ONEMAP.M.routPlaceSearch.pointSearch({
  911. 'keyWord': $("#directionsStop").val()
  912. });
  913. }
  914. if (modValue.pointSearchType == 3) {
  915. if (!modValue.pointSearchContentCid) {
  916. var curid = $("#pointSearchResultWrap .across-list").eq(0).attr('cid');
  917. var name = $("#acrossPointsList").find('li[cid=' + curid + ']').find('input').val();
  918. modValue.pointSearchContentCid = curid;
  919. modValue.pointSearchContentId = $("#pointSearchResultWrap .across-list").eq(0).attr('id');
  920. } else {
  921. var name = $("#acrossPointsList").find('li[cid=' + modValue.pointSearchContentCid + ']').find('input').val();
  922. var indexOf = $("#acrossPointsList").find('li[cid=' + modValue.pointSearchContentCid + ']').index();
  923. modValue.pointSearchContentId = $("#pointSearchResultWrap .across-list").eq(indexOf).attr('id');
  924. }
  925. ONEMAP.M.routPlaceSearch.pointSearch({
  926. 'keyWord': name
  927. });
  928. }
  929. };
  930. /**
  931. * 更新地图上描绘点
  932. */
  933. function updateMarkers(options) {
  934. if (options.latLng.length != 2) {
  935. var latlng = [];
  936. latlng[0] = options.latLng.lng;
  937. latlng[1] = options.latLng.lat;
  938. } else {
  939. var latlng = [];
  940. latlng[0] = options.latLng[0];
  941. latlng[1] = options.latLng[1];
  942. }
  943. map23DControl.marker({
  944. action: "update",
  945. guid: options.guid,
  946. geojson: {
  947. "properties": {
  948. title: options.name,
  949. popupContent: options.popupContent
  950. },
  951. "geometry": {
  952. "coordinates": latlng
  953. }
  954. }
  955. })
  956. }
  957. /**
  958. * 在地图上描绘点
  959. * @type {Function}
  960. * @param options {Object} {type , latLng}
  961. * @private
  962. */
  963. function setMarkers(options) {
  964. if (options.latLng.length != 2) {
  965. var latlng = [];
  966. latlng[0] = options.latLng.lng;
  967. latlng[1] = options.latLng.lat;
  968. } else {
  969. var latlng = [];
  970. latlng[0] = options.latLng[0];
  971. latlng[1] = options.latLng[1];
  972. }
  973. switch (options.type) {
  974. case 'start':
  975. if (modValue.roadMarker.start) {
  976. map23DControl.marker({
  977. action: 'remove',
  978. guid: modValue.roadMarker.start
  979. })
  980. }
  981. modValue.roadMarker.start = map23DControl.marker({
  982. action: 'add',
  983. groupId: modValue.brushGroup,
  984. geojson: {
  985. "type": "Feature",
  986. "properties": {
  987. iconUrl: map23DConfig.map23DAssetsUrl + '/images/tools/start_point.png',
  988. iconSize: [22, 29],
  989. iconAnchor: [11, 29],
  990. popupAnchor: [0, -29],
  991. altitudeMode: 1,
  992. draggable: true
  993. },
  994. "geometry": {
  995. "type": "Point",
  996. "coordinates": [latlng[0], latlng[1]]
  997. }
  998. }
  999. })
  1000. if (map23DData.display.map2D) {
  1001. map2DViewer.markers[modValue.roadMarker.start].on('dragend', function () {
  1002. setStartPoint(this._latlng);
  1003. });
  1004. }
  1005. break;
  1006. case 'across':
  1007. var guid = options.cid.split('_')[1];
  1008. var acrossMarker = map23DControl.marker({
  1009. action: 'add',
  1010. guid: guid,
  1011. groupId: modValue.brushGroup,
  1012. geojson: {
  1013. "type": "Feature",
  1014. "properties": {
  1015. iconUrl: map23DConfig.map23DAssetsUrl + '/images/tools/across_point.png',
  1016. iconSize: [22, 29],
  1017. iconAnchor: [11, 29],
  1018. popupAnchor: [0, -29],
  1019. altitudeMode: 1,
  1020. draggable: true
  1021. },
  1022. "geometry": {
  1023. "type": "Point",
  1024. "coordinates": [latlng[0], latlng[1]]
  1025. }
  1026. }
  1027. })
  1028. return acrossMarker;
  1029. break;
  1030. case 'avoid':
  1031. var avoidMarker = map23DControl.marker({
  1032. action: 'add',
  1033. groupId: modValue.brushGroup,
  1034. geojson: {
  1035. "type": "Feature",
  1036. "properties": {
  1037. iconUrl: map23DConfig.map23DAssetsUrl + '/images/layout/ico_p_5.png',
  1038. iconSize: [25, 25],
  1039. iconAnchor: [12, 24],
  1040. popupAnchor: [0, -25],
  1041. altitudeMode: 1,
  1042. draggable: true,
  1043. },
  1044. "geometry": {
  1045. "type": "Point",
  1046. "coordinates": [latlng[0], latlng[1]]
  1047. }
  1048. }
  1049. })
  1050. return avoidMarker;
  1051. break;
  1052. case 'stop':
  1053. if (modValue.roadMarker.stop) {
  1054. map23DControl.marker({
  1055. action: 'remove',
  1056. guid: modValue.roadMarker.stop
  1057. })
  1058. }
  1059. modValue.roadMarker.stop = map23DControl.marker({
  1060. action: 'add',
  1061. groupId: modValue.brushGroup,
  1062. geojson: {
  1063. "type": "Feature",
  1064. "properties": {
  1065. iconUrl: map23DConfig.map23DAssetsUrl + '/images/tools/stop_point.png',
  1066. iconSize: [22, 29],
  1067. iconAnchor: [11, 29],
  1068. popupAnchor: [0, -29],
  1069. altitudeMode: 1,
  1070. },
  1071. "geometry": {
  1072. "type": "Point",
  1073. "coordinates": [latlng[0], latlng[1]]
  1074. }
  1075. }
  1076. })
  1077. if (map23DData.display.map2D) {
  1078. map2DViewer.markers[modValue.roadMarker.stop].on('dragend', function () {
  1079. setStopPoint(this._latlng);
  1080. });
  1081. }
  1082. break;
  1083. }
  1084. };
  1085. /**
  1086. * 设置起点坐标
  1087. * @type {Function}
  1088. * @param latLng {Object}
  1089. */
  1090. function setStartPoint(latLng, name) {
  1091. if (!status.initialized) {
  1092. init();
  1093. }
  1094. $("#routSearchContent").show();
  1095. $("#header .tools-routgh").addClass('cur');
  1096. if (latLng instanceof Array) {
  1097. modValue.startPoint.latlng = new L.LatLng(latLng[1], latLng[0]);
  1098. latLng = new L.LatLng(latLng[1], latLng[0]);
  1099. } else {
  1100. modValue.startPoint.latlng = latLng;
  1101. }
  1102. var nLatlng = L.Util.formatHMS(latLng);
  1103. setMarkers({
  1104. type: 'start',
  1105. latLng: latLng
  1106. });
  1107. if (name) {
  1108. $("#directionsStart").val(name);
  1109. modValue.startPoint.name = name;
  1110. if (map23DData.display.map2D) {
  1111. var popup_options = {
  1112. name: name,
  1113. content: '<span style="font-size:12px;line-height:36px; color:#fff">' + nLatlng.lng + ' , ' + nLatlng.lat + '</span>'
  1114. };
  1115. var popupHtml = creatPopupHtml(popup_options);
  1116. map2DViewer.markers[modValue.roadMarker.start].bindPopup(popupHtml, {
  1117. closeButton: false,
  1118. autoPan: false,
  1119. maxWidth: 160,
  1120. minWidth: 160
  1121. }).openPopup();
  1122. }
  1123. var curMarkerData = map2DViewer.markers[modValue.roadMarker.start].getLatLng();
  1124. updateMarkers({
  1125. name: name,
  1126. latLng: [curMarkerData.lng, curMarkerData.lat],
  1127. guid: modValue.roadMarker.start,
  1128. popupContent: popupHtml
  1129. });
  1130. getSearchResult();
  1131. } else {
  1132. ONEMAP.M.routPlaceSearch.getInfoByZoomLatLng(latLng, function (data) {
  1133. if (!data.address) {
  1134. data.address = '未知地点';
  1135. }
  1136. $("#directionsStart").val(data.address);
  1137. modValue.startPoint.name = data.address;
  1138. var curMarkerData = map2DViewer.markers[modValue.roadMarker.start].getLatLng();
  1139. updateMarkers({
  1140. name: name,
  1141. latLng: [curMarkerData.lng, curMarkerData.lat],
  1142. guid: modValue.roadMarker.start
  1143. });
  1144. if (map23DData.display.map2D) {
  1145. var popup_options = {
  1146. name: data.address,
  1147. content: '<span style="font-size:12px;line-height:36px; color:#fff">' + nLatlng.lng + ' , ' + nLatlng.lat + '</span>'
  1148. };
  1149. var popupHtml = creatPopupHtml(popup_options);
  1150. map2DViewer.markers[modValue.roadMarker.start].bindPopup(popupHtml, {
  1151. closeButton: false,
  1152. autoPan: false,
  1153. maxWidth: 160,
  1154. minWidth: 160
  1155. }).openPopup();
  1156. }
  1157. //setMarkers();
  1158. getSearchResult();
  1159. });
  1160. }
  1161. };
  1162. /**
  1163. * 创建冒泡窗
  1164. */
  1165. function creatPopupHtml(options) {
  1166. var popupHtml = '<div class="popup_html">' +
  1167. ' <div class="popup-lt"></div>' +
  1168. ' <div class="popup-lb"></div>' +
  1169. ' <div class="popup-rt"></div>' +
  1170. ' <div class="popup-rb"></div>' +
  1171. ' <div class="popup-ct" style="text-indent:15px;line-height:48px">' + options.name +
  1172. ' </div>' +
  1173. ' <div class="popup-cb" style="padding-bottom:20px;color:#666666 !important">' + options.content + '</div>' +
  1174. '</div>'
  1175. return popupHtml;
  1176. }
  1177. /**
  1178. * 添加途经点坐标
  1179. * @type {Function}
  1180. * @param latLng {Object}
  1181. */
  1182. function setAcrossPoint(latLng, name, cid) {
  1183. if (!status.initialized) {
  1184. init();
  1185. }
  1186. $("#routSearchContent").show();
  1187. $("#header .tools-routgh").addClass('cur');
  1188. if (ONEMAP.T.getObjNameAry(modValue.acrossPoints).length > 4) {
  1189. alert('最多可添加 5 个途经点');
  1190. return false;
  1191. }
  1192. if (latLng instanceof Array) {
  1193. latLng = new L.LatLng(latLng[1], latLng[0]);
  1194. }
  1195. var acrossPoint = {
  1196. name: '未知地点',
  1197. latlng: latLng
  1198. }
  1199. //if(modValue.curTDAcrossId){
  1200. // cid = modValue.curTDAcrossId;
  1201. //}
  1202. if (!cid) {
  1203. $(".waypoint .choose-across").click();
  1204. var length = $("#acrossPointsList li").length;
  1205. cid = $("#acrossPointsList li").eq(length - 1).attr('cid');
  1206. }
  1207. if (cid) {
  1208. var pointId = cid;
  1209. }
  1210. if (modValue.amongMarkers[pointId]) {
  1211. updateMarkers({
  1212. type: 'across',
  1213. latLng: latLng,
  1214. cid: cid,
  1215. guid: pointId
  1216. });
  1217. var acrossMarkerId = pointId;
  1218. } else {
  1219. var acrossMarkerId = setMarkers({
  1220. type: 'across',
  1221. latLng: latLng,
  1222. cid: cid
  1223. });
  1224. }
  1225. modValue.amongMarkers[pointId] = map2DViewer.markers[acrossMarkerId];
  1226. modValue.acrossPoints[pointId] = acrossPoint;
  1227. modValue.amongMarkers[pointId].on('dragend', function () {
  1228. modValue.acrossPoints[pointId].latlng = this._latlng;
  1229. //去更新popup
  1230. ONEMAP.M.routPlaceSearch.getInfoByZoomLatLng(modValue.acrossPoints[pointId].latlng, function (data) {
  1231. if (!data.address) {
  1232. data.address = '未知地点';
  1233. }
  1234. modValue.acrossPoints[pointId].name = data.address;
  1235. var nLatlng = L.Util.formatHMS(modValue.acrossPoints[pointId].latlng);
  1236. var curMarkerData = modValue.amongMarkers[pointId].getLatLng();
  1237. updateMarkers({
  1238. name: data.address,
  1239. latLng: [curMarkerData.lng, curMarkerData.lat],
  1240. guid: pointId
  1241. }); //
  1242. var popup_options = {
  1243. name: data.address,
  1244. content: '<a style="float:left" href="javascript:ONEMAP.M.toolRouteSearch.delAcrossPoint(\'' + pointId + '\');">移除</a><br/><span style="font-size:12px;line-height:36px; color:#fff">' + nLatlng.lng + ' , ' + nLatlng.lat + '</span>'
  1245. };
  1246. var popupHtml = creatPopupHtml(popup_options);
  1247. modValue.amongMarkers[pointId].bindPopup(popupHtml, {
  1248. closeButton: false,
  1249. autoPan: false,
  1250. maxWidth: 160,
  1251. minWidth: 160
  1252. }).openPopup();
  1253. });
  1254. getSearchResult();
  1255. });
  1256. if (name) {
  1257. modValue.acrossPoints[pointId].name = name;
  1258. $("#acrossPointsList").find('li[cid=' + cid + ']').find('input').val(name);
  1259. var curMarkerData = modValue.amongMarkers[pointId].getLatLng();
  1260. updateMarkers({
  1261. name: name,
  1262. latLng: [curMarkerData.lng, curMarkerData.lat],
  1263. guid: pointId
  1264. });
  1265. var nLatlng = L.Util.formatHMS(latLng);
  1266. var popup_options = {
  1267. name: name,
  1268. content: '<a style="float:left" href="javascript:ONEMAP.M.toolRouteSearch.delAcrossPoint(\'' + pointId + '\');">移除</a><br/><span style="font-size:12px;line-height:36px; color:#fff">' + nLatlng.lng + ' , ' + nLatlng.lat + '</span>'
  1269. };
  1270. var popupHtml = creatPopupHtml(popup_options);
  1271. modValue.amongMarkers[pointId].bindPopup(popupHtml, {
  1272. closeButton: false,
  1273. autoPan: false,
  1274. maxWidth: 160,
  1275. minWidth: 160
  1276. }).openPopup();
  1277. getSearchResult();
  1278. } else {
  1279. ONEMAP.M.routPlaceSearch.getInfoByZoomLatLng(latLng, function (data) {
  1280. if (!data.address) {
  1281. data.address = '未知地点';
  1282. }
  1283. $("#acrossPointsList").find('li[cid=' + cid + ']').find('input').val(data.address);
  1284. modValue.acrossPoints[pointId].name = data.address;
  1285. var nLatlng = L.Util.formatHMS(latLng);
  1286. var curMarkerData = modValue.amongMarkers[pointId].getLatLng();
  1287. updateMarkers({
  1288. name: data.address,
  1289. latLng: [curMarkerData.lng, curMarkerData.lat],
  1290. guid: pointId
  1291. });
  1292. var popup_options = {
  1293. name: data.address,
  1294. content: '<a style="float:left" href="javascript:ONEMAP.M.toolRouteSearch.delAcrossPoint(\'' + pointId + '\');">移除</a><br/><span style="font-size:12px;line-height:36px; color:#fff">' + nLatlng.lng + ' , ' + nLatlng.lat + '</span>'
  1295. };
  1296. var popupHtml = creatPopupHtml(popup_options);
  1297. modValue.amongMarkers[pointId].bindPopup(popupHtml, {
  1298. closeButton: false,
  1299. autoPan: false,
  1300. maxWidth: 160,
  1301. minWidth: 160
  1302. }).openPopup();
  1303. getSearchResult();
  1304. });
  1305. }
  1306. };
  1307. /**
  1308. * 移除途经点
  1309. * @param {[type]} pointId [description]
  1310. * @return {[type]} [description]
  1311. */
  1312. function delAcrossPoint(pointId) {
  1313. map23DControl.marker({
  1314. action: 'remove',
  1315. guid: pointId
  1316. });
  1317. $("#acrossPointsList").find('li[cid=' + pointId + ']').remove();
  1318. delete modValue.amongMarkers[pointId];
  1319. delete modValue.acrossPoints[pointId];
  1320. //var acrossPointsArry = Object.getOwnPropertyNames(modValue.acrossPoints);
  1321. //var latname = acrossPointsArry[acrossPointsArry.length - 1];
  1322. //$.each(modValue.acrossPoints, function(i, t) {
  1323. // if (i > pointId) {
  1324. // modValue.acrossPoints[i - 1] = modValue.acrossPoints[i]
  1325. // }
  1326. //});
  1327. //delete modValue.acrossPoints[latname];
  1328. getSearchResult();
  1329. };
  1330. //移除规避区域
  1331. function delAvoidArea(id) {
  1332. map2DViewer.polygon({
  1333. action: 'remove',
  1334. guid: id
  1335. });
  1336. }
  1337. /**
  1338. * 添加规避点坐标
  1339. * @type {Function}
  1340. * @param latLng {Object}
  1341. */
  1342. function setAvoidPoint(latLng, name) {
  1343. if (!status.initialized) {
  1344. init();
  1345. }
  1346. $("#routSearchContent").show();
  1347. $("#header .tools-routgh").addClass('cur');
  1348. if (ONEMAP.T.getObjNameAry(modValue.avoidPoints).length == 5) {
  1349. alert('最多可添加 5 个规避点');
  1350. return false;
  1351. }
  1352. if (latLng instanceof Array) {
  1353. latLng = new L.LatLng(latLng[1], latLng[0]);
  1354. }
  1355. var avoidPoint = {
  1356. name: '未知地点',
  1357. latlng: latLng
  1358. };
  1359. var avoidMarkerId = setMarkers({
  1360. type: 'avoid',
  1361. latLng: latLng
  1362. });
  1363. var pointId = avoidMarkerId;
  1364. if (map23DData.display.map2D) {
  1365. modValue.amongMarkers[pointId] = map2DViewer.markers[pointId];
  1366. modValue.avoidPoints[pointId] = avoidPoint;
  1367. modValue.amongMarkers[pointId].on('dragend', function () {
  1368. modValue.avoidPoints[pointId].latlng = this._latlng;
  1369. //去更新popup
  1370. ONEMAP.M.routPlaceSearch.getInfoByZoomLatLng(modValue.avoidPoints[pointId].latlng, function (data) {
  1371. if (!data.address) {
  1372. data.address = '未知地点';
  1373. }
  1374. modValue.avoidPoints[pointId].name = data.address;
  1375. var nLatlng = L.Util.formatHMS(modValue.avoidPoints[pointId].latlng);
  1376. modValue.amongMarkers[pointId].bindPopup(data.address + '<a style="float:left" href="javascript:ONEMAP.M.toolRouteSearch.delAvoidPoint(\'' + pointId + '\');">移除</a><br/><span style="font-size:12px;line-height:36px; color:#fff">' + nLatlng.lng + ' , ' + nLatlng.lat + '</span>', {
  1377. closeButton: false,
  1378. autoPan: false,
  1379. maxWidth: 160,
  1380. minWidth: 160
  1381. }).openPopup();
  1382. });
  1383. getSearchResult();
  1384. });
  1385. if (name) {
  1386. modValue.avoidPoints[pointId].name = name;
  1387. var nLatlng = L.Util.formatHMS(latLng);
  1388. modValue.amongMarkers[pointId].bindPopup(name + '<a style="float:left" href="javascript:ONEMAP.M.toolRouteSearch.delAvoidPoint(\'' + pointId + '\');">移除</a><br/><span style="font-size:12px;line-height:36px; color:#fff">' + nLatlng.lng + ' , ' + nLatlng.lat + '</span>', {
  1389. closeButton: false,
  1390. autoPan: false,
  1391. maxWidth: 160,
  1392. minWidth: 160
  1393. }).openPopup();
  1394. getSearchResult();
  1395. } else {
  1396. ONEMAP.M.routPlaceSearch.getInfoByZoomLatLng(latLng, function (data) {
  1397. if (!data.address) {
  1398. data.address = '未知地点';
  1399. }
  1400. modValue.avoidPoints[pointId].name = data.address;
  1401. var nLatlng = L.Util.formatHMS(latLng);
  1402. modValue.amongMarkers[pointId].bindPopup(data.address + '<a style="float:left" href="javascript:ONEMAP.M.toolRouteSearch.delAvoidPoint(\'' + pointId + '\');">移除</a><br/><span style="font-size:12px;line-height:36px; color:#fff">(' + nLatlng.lng + ' , ' + nLatlng.lat + ')</span>', {
  1403. closeButton: false,
  1404. autoPan: false,
  1405. maxWidth: 160,
  1406. minWidth: 160
  1407. }).openPopup();
  1408. getSearchResult();
  1409. });
  1410. }
  1411. }
  1412. };
  1413. /**
  1414. * 移除规避点
  1415. * @param {[type]} pointId [description]
  1416. * @return {[type]} [description]
  1417. */
  1418. function delAvoidPoint(pointId) {
  1419. map23DControl.marker({
  1420. action: 'remove',
  1421. guid: pointId
  1422. });
  1423. delete modValue.amongMarkers[pointId];
  1424. delete modValue.avoidPoints[pointId];
  1425. getSearchResult();
  1426. };
  1427. /**
  1428. * 设置终点坐标
  1429. * @type {Function}
  1430. * @param latLng {Object}
  1431. */
  1432. function setStopPoint(latLng, name) {
  1433. if (!status.initialized) {
  1434. init();
  1435. }
  1436. $("#routSearchContent").show();
  1437. $("#header .tools-routgh").addClass('cur');
  1438. if (latLng instanceof Array) {
  1439. modValue.stopPoint.latlng = new L.LatLng(latLng[1], latLng[0]);
  1440. latLng = new L.LatLng(latLng[1], latLng[0]);
  1441. } else {
  1442. modValue.stopPoint.latlng = latLng;
  1443. }
  1444. var nLatlng = L.Util.formatHMS(latLng);
  1445. setMarkers({
  1446. type: 'stop',
  1447. latLng: latLng
  1448. });
  1449. if (name) {
  1450. $("#directionsStop").val(name);
  1451. modValue.stopPoint.name = name;
  1452. var curMarkerData = map2DViewer.markers[modValue.roadMarker.stop].getLatLng();
  1453. updateMarkers({
  1454. name: name,
  1455. latLng: [curMarkerData.lng, curMarkerData.lat],
  1456. guid: modValue.roadMarker.stop
  1457. });
  1458. if (map23DData.display.map2D) {
  1459. var popup_options = {
  1460. name: name,
  1461. content: '<span style="font-size:12px;line-height:36px; color:#fff">(' + nLatlng.lng + ' , ' + nLatlng.lat + ')</span>'
  1462. };
  1463. var popupHtml = creatPopupHtml(popup_options);
  1464. map2DViewer.markers[modValue.roadMarker.stop].bindPopup(popupHtml, {
  1465. closeButton: false,
  1466. autoPan: false,
  1467. maxWidth: 160,
  1468. minWidth: 160
  1469. }).openPopup();
  1470. }
  1471. getSearchResult();
  1472. } else {
  1473. ONEMAP.M.routPlaceSearch.getInfoByZoomLatLng(latLng, function (data) {
  1474. if (!data.address) {
  1475. data.address = '未知地点';
  1476. }
  1477. $("#directionsStop").val(data.address);
  1478. modValue.stopPoint.name = data.address;
  1479. var curMarkerData = map2DViewer.markers[modValue.roadMarker.stop].getLatLng();
  1480. updateMarkers({
  1481. name: data.address,
  1482. latLng: [curMarkerData.lng, curMarkerData.lat],
  1483. guid: modValue.roadMarker.stop
  1484. });
  1485. if (map23DData.display.map2D) {
  1486. var popup_options = {
  1487. name: data.address,
  1488. content: '<span style="font-size:12px;line-height:36px; color:#fff">(' + nLatlng.lng + ' , ' + nLatlng.lat + ')</span>'
  1489. };
  1490. var popupHtml = creatPopupHtml(popup_options);
  1491. map2DViewer.markers[modValue.roadMarker.stop].bindPopup(popupHtml, {
  1492. closeButton: false,
  1493. autoPan: false,
  1494. maxWidth: 160,
  1495. minWidth: 160
  1496. }).openPopup();
  1497. }
  1498. getSearchResult();
  1499. });
  1500. }
  1501. };
  1502. function keyserch(e) {
  1503. if (e == 13) {
  1504. var acrossChange = true;
  1505. $.each($("#acrossPointsList li"), function (i, t) {
  1506. if ($(t).find('input').val() != "" && $(t).find('input').val() != "输入途经点") {
  1507. var cid = $(t).attr('cid');
  1508. if (!modValue.acrossPoints[cid]) {
  1509. acrossChange = false;
  1510. } else {
  1511. if (modValue.acrossPoints[cid].name != $(t).find('input').val()) {
  1512. acrossChange = false;
  1513. }
  1514. }
  1515. }
  1516. });
  1517. if (acrossChange && modValue.startPoint.latlng && modValue.stopPoint.latlng && modValue.startPoint.name == $('#directionsStart').val() && modValue.stopPoint.name == $('#directionsStop').val()) {
  1518. getSearchResult();
  1519. } else if ($.trim($('#directionsStart').val()) != '' && $('#directionsStart').val() != '输入起点' && $.trim($('#directionsStop').val()) != '' && $('#directionsStop').val() != '输入终点') {
  1520. if ((/[^\a-\z\A-\Z0-9\u4E00-\u9FA5\s\"]/g).test($("#directionsStart").val())) {
  1521. setNotResultHtml('起点只能包含英文、数字、中文');
  1522. return false;
  1523. }
  1524. if ($.trim($("#directionsStart").val()).length < 2) {
  1525. setNotResultHtml('起点不允许输入单字符');
  1526. return false;
  1527. }
  1528. if ((/[^\a-\z\A-\Z0-9\u4E00-\u9FA5\s\"]/g).test($("#directionsStop").val())) {
  1529. setNotResultHtml('终点只能包含英文、数字、中文');
  1530. return false;
  1531. }
  1532. if ($.trim($("#directionsStop").val()).length < 2) {
  1533. setNotResultHtml('终点不允许输入单字符');
  1534. return false;
  1535. }
  1536. getStartAndStop();
  1537. } else if ($.trim($('#directionsStart').val()) == '' || $('#directionsStart').val() == '输入起点') {
  1538. setNotResultHtml('起点不能为空,请检查对应查询条件。');
  1539. return false;
  1540. } else if ($.trim($('#directionsStop').val()) == '' || $('#directionsStop').val() == '输入终点') {
  1541. setNotResultHtml('终点不能为空,请检查对应查询条件。');
  1542. return false;
  1543. }
  1544. }
  1545. };
  1546. /**
  1547. * 下载地图上路线数据
  1548. * 格式为geojson
  1549. */
  1550. function downloadLineGeojson(){
  1551. var geojson = {
  1552. "type": "FeatureCollection",
  1553. "features": [{
  1554. "type": "Feature",
  1555. "properties": {
  1556. name:modValue.startPoint.name
  1557. },
  1558. "geometry": {
  1559. "type": "Point",
  1560. "coordinates": [
  1561. modValue.startPoint.latlng.lng,
  1562. modValue.startPoint.latlng.lat,
  1563. ]
  1564. }
  1565. },{
  1566. "type": "Feature",
  1567. "properties": {
  1568. name:modValue.stopPoint.name
  1569. },
  1570. "geometry": {
  1571. "type": "Point",
  1572. "coordinates": [
  1573. modValue.stopPoint.latlng.lng,
  1574. modValue.stopPoint.latlng.lat,
  1575. ]
  1576. }
  1577. }]
  1578. };
  1579. $.each(modValue.acrossPoints,function(i,t){
  1580. geojson.features.push({
  1581. "type": "Feature",
  1582. "properties": {
  1583. name:t.name
  1584. },
  1585. "geometry": {
  1586. "type": "Point",
  1587. "coordinates": [
  1588. t.latlng.lng,
  1589. t.latlng.lat,
  1590. ]
  1591. }
  1592. })
  1593. })
  1594. var points = modValue.directionsDataResult.coors;
  1595. //转换为可用坐标
  1596. var pArray = points.split(',');
  1597. var pointLatLng = [];
  1598. var dDouble = true;
  1599. var temp = [];
  1600. for (var i = 0, l = pArray.length; i < l; i++) {
  1601. var num = pArray[i];
  1602. if(typeof(pArray[i]) == "string" && pArray[i] != ""){
  1603. num = JSON.parse(num);
  1604. }
  1605. if (dDouble) {
  1606. temp = [];
  1607. temp.push(num);
  1608. dDouble = false;
  1609. } else {
  1610. temp.push(num);
  1611. dDouble = true;
  1612. pointLatLng.push(temp);
  1613. }
  1614. }
  1615. geojson.features.push({
  1616. "type": "Feature",
  1617. "properties": {
  1618. },
  1619. "geometry": {
  1620. "type": "LineString",
  1621. "coordinates": pointLatLng
  1622. }
  1623. })
  1624. var eleLink = document.createElement('a');
  1625. var filename = 'exportRout.geojson';
  1626. eleLink.download = filename;
  1627. var content = JSON.stringify(geojson);
  1628. var blob = new Blob([content]);
  1629. var href = URL.createObjectURL(blob);
  1630. eleLink.href = href;
  1631. $(eleLink)[0].click();
  1632. }
  1633. function bindEvent() {
  1634. //添加途经点
  1635. $(".waypoint .choose-across").unbind('click').bind('click', function () {
  1636. if ($("#acrossPointsList .across-li").length > 4) {
  1637. alert('最多可添加 5 个途经点');
  1638. return false;
  1639. }
  1640. var divID = map23DControl.buildGuid('marker23D');
  1641. var acrossItemHtml = '<li class="across-li" cid="' + divID + '">' +
  1642. '<div class="waypoint">' +
  1643. '<div class="searchBox">' +
  1644. '<input type="text" class="input directions-across" title="输入途经点">' +
  1645. '<a class="delete-cur-across"></a>' +
  1646. '</div>' +
  1647. '<div class="acrossIcon"></div>' +
  1648. '</div>' +
  1649. '</li>';
  1650. $(acrossItemHtml).appendTo($("#acrossPointsList"));
  1651. $.each($("#acrossPointsList li"), function (i, t) {
  1652. if ($(t).find('input').val() == "") {
  1653. $(t).find('input').val("输入途经点");
  1654. }
  1655. })
  1656. $("#directionsSearch .waypointWrapper .across-points-content").mCustomScrollbar('update');
  1657. bindEvent();
  1658. if (map23DData.display.map3D) {
  1659. bindTDEvent();
  1660. }
  1661. });
  1662. //添加规避区域
  1663. $(".waypoint .choose-avoid").unbind("click").bind("click", function () {
  1664. if ($("#avoidAreaList .avoid-li").length > 4) {
  1665. alert('最多可添加 5 个规避区域');
  1666. return false;
  1667. }
  1668. map2DViewer.drawrectangleFire = function (data) {
  1669. var guid = map2DViewer.polygon({
  1670. action: 'add',
  1671. polygontype: 'circlepolygon', //polygon circlepolygon
  1672. geojson: {
  1673. "type": "Feature",
  1674. "properties": {
  1675. title: '测试矩形',
  1676. color: '#0033ff',
  1677. weight: 3,
  1678. fillColor: '#ff9999',
  1679. opacity: 1,
  1680. fillOpacity: 0.5,
  1681. popupContent: '',
  1682. },
  1683. "geometry": {
  1684. "type": "Polygon",
  1685. "coordinates": [data._latlng]
  1686. }
  1687. }
  1688. })
  1689. var dbd = new Array();
  1690. dbd[0] = [data.bounds[0][1], data.bounds[0][0]];
  1691. dbd[1] = [data.bounds[1][1], data.bounds[1][0]];
  1692. modValue.options.searchType = 4;
  1693. modValue.avoidAreas.push(dbd);
  1694. var avoidItemHtml = '<li class="avoid-li" cid="' + guid + '">' +
  1695. '<div class="waypoint">' +
  1696. '<div class="searchBox">' +
  1697. '<input type="text" class="input directions-avoid" title="绘制规避区域" value=' + dbd + '>' +
  1698. '<a class="delete-cur-avoid">删除</a>' +
  1699. '</div>' +
  1700. '<div class="avoidIcon"></div>' +
  1701. '</div>' +
  1702. '</li>';
  1703. $(avoidItemHtml).appendTo($("#avoidAreaList"));
  1704. $.each($("#avoidAreaList li"), function (i, t) {
  1705. if ($(t).find('input').val() == "") {
  1706. $(t).find('input').val("绘制规避区域");
  1707. }
  1708. })
  1709. $("#directionsSearch .waypointWrapper .avoid-points-content").mCustomScrollbar('update');
  1710. bindEvent();
  1711. if (map23DData.display.map3D) {
  1712. bindTDEvent();
  1713. }
  1714. };
  1715. var avoidA = map2DViewer.setDrawRectangle({
  1716. action: 'add_start',
  1717. offset: [-1000, 50],
  1718. properties: {
  1719. title: '测试矩形',
  1720. color: '#ff0000',
  1721. weight: 3,
  1722. fillColor: '#ff9999',
  1723. opacity: 1,
  1724. fillOpacity: 0.5,
  1725. popupContent: '',
  1726. },
  1727. });
  1728. // var divID = map23DControl.buildGuid('marker23D');
  1729. });
  1730. // 删除当前规避区域
  1731. $("#avoidAreaList .delete-cur-avoid").unbind('click').bind('click', function () {
  1732. var curid = $(this).parent().parent().parent().attr('cid');
  1733. //数据删除
  1734. delAvoidArea(curid);
  1735. var index = $(this).parents().filter(".avoid-li").index();
  1736. $(this).parents().filter(".avoid-li").remove();
  1737. // var hh = modValue.avoidAreas;
  1738. modValue.avoidAreas.splice(index, 1);
  1739. // var gg = modValue.avoidAreas;
  1740. //重新获取路线
  1741. getSearchResult();
  1742. })
  1743. // 删除当前途经点
  1744. $("#acrossPointsList .delete-cur-across").unbind('click').bind('click', function () {
  1745. var curid = $(this).parent().parent().parent().attr('cid');
  1746. //数据删除
  1747. delAcrossPoint(curid)
  1748. //重新获取路线
  1749. getSearchResult();
  1750. })
  1751. //路径规划模式选择
  1752. $(".routeTypeList li").unbind('click').bind('click', function () {
  1753. $(".routeTypeList li").removeClass("active");
  1754. $(this).addClass("active");
  1755. $("#routeSearchType").text($(this).text());
  1756. modValue.resultNum = $(this).attr("type");
  1757. $(".routeTypeList").hide();
  1758. //清空点标记图层组
  1759. map23DControl.group({
  1760. action: 'cleanAll',
  1761. guid: modValue.markerGroup
  1762. })
  1763. setNavigation();
  1764. })
  1765. $(".routeTypeList li").hover(function () {
  1766. $(".routeTypeList li").removeClass("active");
  1767. $(this).addClass("active");
  1768. })
  1769. $("#routeSearchType").click(function () {
  1770. $(".routeTypeList").show();
  1771. })
  1772. $("#routeSearchType").bind('mouseleave', function () {
  1773. $(".routeTypeList").hide();
  1774. })
  1775. $(".routeTypeList").hover(function () {
  1776. $(".routeTypeList").show();
  1777. }, function () {
  1778. $(".routeTypeList").hide();
  1779. })
  1780. //清除路径
  1781. $('#d_clear a').unbind('focus').bind('click', function () {
  1782. cleanDirections();
  1783. $(".slot-title").hide();
  1784. });
  1785. //收藏
  1786. $('#d_fav a').unbind('click').bind('click', function () {
  1787. //判断是否登录,没有登录进行提示
  1788. if (!ONEMAP.D.isLoad) {
  1789. ONEMAP.C.publisher.publish({
  1790. type: 'warning',
  1791. message: '请登录后使用!'
  1792. }, 'noteBar::add');
  1793. return false;
  1794. }
  1795. var acrossPointsAry = [];
  1796. for (var across in modValue.acrossPoints) {
  1797. //if(modValue.acrossPoints.hasOwnProperty(across)){
  1798. acrossPointsAry.push([modValue.acrossPoints[across].latlng.lng, modValue.acrossPoints[across].latlng.lat]);
  1799. //}
  1800. }
  1801. var avoidPointsAry = [];
  1802. for (var avoid in modValue.avoidPoints) {
  1803. //if(modValue.avoidPoints.hasOwnProperty(avoid)){
  1804. avoidPointsAry.push([modValue.avoidPoints[avoid].latlng.lng, modValue.avoidPoints[avoid].latlng.lat]);
  1805. //}
  1806. }
  1807. var objData = {
  1808. name: $('#directionsStart').val() + ' 至 ' + $('#directionsStop').val(),
  1809. startpoint_lat: modValue.startPoint.latlng.lat,
  1810. startpoint_lon: modValue.startPoint.latlng.lng,
  1811. stoppoint_lat: modValue.stopPoint.latlng.lat,
  1812. stoppoint_lon: modValue.stopPoint.latlng.lng,
  1813. acrossPoints: JSON.stringify(acrossPointsAry),
  1814. avoidPoints: JSON.stringify(avoidPointsAry)
  1815. //acrossPoints : acrossPointsAry,
  1816. //avoidPoints :avoidPointsAry
  1817. };
  1818. require(['modDir/user/userRoute'], function (userRoute) {
  1819. userRoute.addRoute(objData);
  1820. })
  1821. });
  1822. $('#directionsStart').bind('focus', function () {
  1823. $(this).val('');
  1824. });
  1825. $('#directionsStop').bind('focus', function () {
  1826. $(this).val('');
  1827. });
  1828. $("#acrossPointsList .directions-across").bind('focus', function () {
  1829. $(this).val('');
  1830. });
  1831. $("#acrossPointsList .directions-across").bind('focusout', function () {
  1832. if ($(this).val() == '') {
  1833. $(this).val('输入途经点');
  1834. }
  1835. });
  1836. $("#avoidAreaList .directions-avoid").bind('focus', function () {
  1837. $(this).val('');
  1838. });
  1839. $("#avoidAreaList .directions-avoid").bind('focusout', function () {
  1840. if ($(this).val() == '') {
  1841. $(this).val('绘制规避区域');
  1842. }
  1843. });
  1844. $('#directionsStart').bind('focusout', function () {
  1845. if ($(this).val() == '') {
  1846. if (map23DData.display.map2D) {
  1847. $(this).val('输入起点');
  1848. } else {
  1849. $(this).val('点击左边图标激活地图选点');
  1850. }
  1851. };
  1852. });
  1853. $('#directionsStop').bind('focusout', function () {
  1854. if ($(this).val() == '') {
  1855. if (map23DData.display.map2D) {
  1856. $(this).val('输入起点');
  1857. } else {
  1858. $(this).val('点击左边图标激活地图选点');
  1859. }
  1860. };
  1861. });
  1862. //查询路线 如果有起始点,直接查询,没有,先去查询起始点的位置
  1863. $("#directionsSearchButton").unbind('click').bind("click", function () {
  1864. keyserch(13);
  1865. });
  1866. $("#directionsStart").unbind('keydown').bind('keydown', function (e) {
  1867. keyserch(e.keyCode);
  1868. })
  1869. $("#directionsStop").unbind('keydown').bind("keydown", function (e) {
  1870. keyserch(e.keyCode);
  1871. });
  1872. // $("#directionsStart").unbind('change').bind('change', function (e) {
  1873. // cleanDirections();
  1874. // })
  1875. // $("#directionsStop").unbind('change').bind("change", function (e) {
  1876. // cleanDirections();
  1877. // });
  1878. //路线导出
  1879. $("#downloadLine").unbind('click').bind('click',function(){
  1880. downloadLineGeojson()
  1881. })
  1882. //打印事件
  1883. $('#abtnPrintLine').unbind('click').bind('click', function () {
  1884. var acrossPointsAry = [];
  1885. for (var across in modValue.acrossPoints) {
  1886. if (modValue.acrossPoints.hasOwnProperty(across)) {
  1887. acrossPointsAry.push([modValue.acrossPoints[across].latlng.lat, modValue.acrossPoints[across].latlng.lng]);
  1888. }
  1889. }
  1890. var avoidPointsAry = [];
  1891. for (var avoid in modValue.avoidPoints) {
  1892. if (modValue.avoidPoints.hasOwnProperty(avoid)) {
  1893. avoidPointsAry.push([modValue.avoidPoints[avoid].latlng.lat, modValue.avoidPoints[avoid].latlng.lng]);
  1894. }
  1895. }
  1896. var can = '?m=directions' +
  1897. '&dir=' + modValue.startPoint.latlng.lat + '|' + modValue.startPoint.latlng.lng + '|' + modValue.stopPoint.latlng.lat + '|' + modValue.stopPoint.latlng.lng + '|' + map2DViewer.map.getMaxZoom() +
  1898. '&across=' + JSON.stringify(acrossPointsAry) +
  1899. '&searchType=' + JSON.stringify(modValue.options.searchType) +
  1900. '&avoid=' + JSON.stringify(avoidPointsAry) +
  1901. '&map=' + ONEMAP.M.mapHolder.modValue.mainLayers + '|' + map2DViewer.map.getZoom() + '|' + map2DViewer.map.getCenter().lat + '|' + map2DViewer.map.getCenter().lng +
  1902. '&place=' + modValue.startPoint.name + '|' + modValue.stopPoint.name +
  1903. '&plan=' + $('.routeTypeList .active').attr('type')
  1904. window.open('/print.html' + can);
  1905. });
  1906. $('#routeElevationWrap .close').unbind('click').bind('click', function () {
  1907. $('#routeElevationShow').empty();
  1908. $('#routeElevationWrap').hide();
  1909. $('#directionsSearch .abtnElevation').removeClass("active");
  1910. });
  1911. ////剖面量算事件 ,'d3/d3.v3.min'
  1912. $('#directionsSearch .abtnElevation').unbind('click').bind('click', function () {
  1913. $(this).addClass("active");
  1914. var coordinates = '' + modValue.startPoint.latlng.lng + ',' + modValue.startPoint.latlng.lat + ',';
  1915. var points = modValue.directionsDataResult.coors;
  1916. //转换为可用坐标
  1917. var pArray = points.split(',');
  1918. var pointLatLng = [];
  1919. var dDouble = true;
  1920. var temp = [];
  1921. for (var i = 0, l = pArray.length; i < l; i++) {
  1922. if (dDouble) {
  1923. temp = [];
  1924. temp.push(pArray[i]);
  1925. dDouble = false;
  1926. } else {
  1927. temp.unshift(pArray[i]);
  1928. dDouble = true;
  1929. temp = L.latLng(temp);
  1930. pointLatLng.push(temp);
  1931. }
  1932. }
  1933. for (var ii = 0, ll = pointLatLng.length; ii < ll; ii++) {
  1934. if (ii % 2 == 0) {
  1935. coordinates += pointLatLng[ii]['lng'] + ',' + pointLatLng[ii]['lat'] + ',';
  1936. }
  1937. }
  1938. coordinates += modValue.stopPoint.latlng.lng + ',' + modValue.stopPoint.latlng.lat;
  1939. var url = onemapUrlConfig.elevationDataUrl + '/v1.0/geoprocessing/profile_elevation';
  1940. var ajaxData = {
  1941. points: '[' + coordinates + ']',
  1942. count: 8,
  1943. zoom: map23DData.view.zoom,
  1944. delta_zoom: 0
  1945. };
  1946. $.ajax({
  1947. type: "post",
  1948. dataType: 'json',
  1949. url: url,
  1950. data: ajaxData,
  1951. beforeSend: ONEMAP.V.loading.load(),
  1952. success: function (data) {
  1953. if (data.code == 0) {
  1954. data = data.data;
  1955. if (data.length > 0) {
  1956. var coordinatesAll = [];
  1957. var coordinatesTemp = [];
  1958. var gap = 1;
  1959. for (var i = 0, l = data.length; i < l; i++) {
  1960. coordinatesTemp = [data[i + 2], data[i + 3], data[i + 1]];
  1961. coordinatesAll.push(coordinatesTemp);
  1962. i = i + 3;
  1963. }
  1964. var geojson = {
  1965. "name": "NewFeatureType",
  1966. "type": "FeatureCollection",
  1967. "features": [{
  1968. "type": "Feature",
  1969. "geometry": {
  1970. "type": "LineString",
  1971. "coordinates": coordinatesAll
  1972. },
  1973. "properties": null
  1974. }]
  1975. };
  1976. if (modValue.elevationControl) {
  1977. map2DViewer.map.removeControl(modValue.elevationControl);
  1978. modValue.elevationControl = null;
  1979. }
  1980. modValue.elevationControl = L.control.elevation();
  1981. modValue.elevationControl.addTo(map2DViewer.map);
  1982. var gjl = L.geoJson(geojson, {
  1983. onEachFeature: modValue.elevationControl.addData.bind(modValue.elevationControl)
  1984. });
  1985. $('#routeElevationShow').empty();
  1986. $(".leaflet-control-elevation").appendTo($('#routeElevationShow'));
  1987. $(".leaflet-control-elevation").css({
  1988. 'position': 'absolute',
  1989. 'left': 0,
  1990. 'bottom': 0
  1991. });
  1992. $('#routeElevationWrap').show();
  1993. // if(ONEMAP.M.mapHolder._elevationControl){
  1994. // ONEMAP.M.mapHolder._elevationControl.removeFrom(_this._map);
  1995. // ONEMAP.M.mapHolder._elevationControl = null;
  1996. // var gjl = L.geoJson(geojson,{
  1997. // onEachFeature: ONEMAP.M.mapHolder._elevationControl.addData.bind(ONEMAP.M.mapHolder._elevationControl)
  1998. // });
  1999. // }else {
  2000. // require(['ocean/Control.Elevation','d3/d3.v3.min'], function () {
  2001. // ONEMAP.M.mapHolder._elevationControl = L.control.elevation();
  2002. // ONEMAP.M.mapHolder._elevationControl.addTo(_this._map);
  2003. // var gjl = L.geoJson(geojson,{
  2004. // onEachFeature: ONEMAP.M.mapHolder._elevationControl.addData.bind(ONEMAP.M.mapHolder._elevationControl)
  2005. // });
  2006. // });
  2007. // }
  2008. } else {
  2009. ONEMAP.C.publisher.publish({
  2010. type: 'error',
  2011. message: '无量算数据显示'
  2012. }, 'noteBar::add');
  2013. }
  2014. } else {
  2015. ONEMAP.C.publisher.publish({
  2016. type: 'error',
  2017. message: data.message
  2018. }, 'noteBar::add');
  2019. }
  2020. },
  2021. completer: ONEMAP.V.loading.loaded()
  2022. });
  2023. });
  2024. };
  2025. /**
  2026. * 设置地图到指定的区域
  2027. * 支持url解析
  2028. * @type {Function}
  2029. * @param options {Object} {center:中心点,zoom:缩放比例}
  2030. */
  2031. function mapToPoint(options) {
  2032. var mapViewer = {
  2033. center: {
  2034. lat: options[0],
  2035. lng: options[1],
  2036. },
  2037. alt: map3DViewer.getZoomFrom2DZoom(options[2], -90)
  2038. };
  2039. map23DControl.flyTo(mapViewer);
  2040. };
  2041. return ONEMAP.M.toolRouteSearch = {
  2042. init: init,
  2043. clearMarker: clearMarker,
  2044. modValue: modValue,
  2045. setStartPoint: setStartPoint,
  2046. setAcrossPoint: setAcrossPoint,
  2047. delAcrossPoint: delAcrossPoint,
  2048. setAvoidPoint: setAvoidPoint,
  2049. delAvoidPoint: delAvoidPoint,
  2050. setStopPoint: setStopPoint
  2051. }
  2052. })