route.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. (function () {
  2. var page = {
  3. init: function ($page) {
  4. //页面初始化
  5. $page.find('#date2').lrdate({
  6. type: 'date'
  7. });
  8. $page.find('.lr-btn-primary').on('tap', function(){
  9. var date = $('#date2')[0].innerText;
  10. console.log(date);
  11. $('.widthset').hide();
  12. $('.outcase').show();
  13. });
  14. //地图初始化
  15. learun.routeMap = new AMap.Map('route-map', {
  16. center: [117.000923, 36.675807],
  17. zoom: 15
  18. });
  19. //test
  20. learun.initPage = function(PathSimplifier) {
  21. //创建组件实例
  22. learun.pathSimplifierIns = new PathSimplifier({
  23. zIndex: 100,
  24. map: learun.routeMap, //所属的地图实例
  25. getPath: function(pathData, pathIndex) {
  26. //返回轨迹数据中的节点坐标信息,[AMap.LngLat, AMap.LngLat...] 或者 [[lng|number,lat|number],...]
  27. return pathData.path;
  28. },
  29. renderOptions: {
  30. //轨迹线的样式
  31. pathLineStyle: {
  32. strokeStyle: 'red',
  33. lineWidth: 6,
  34. dirArrowStyle: true
  35. }
  36. }
  37. });
  38. //这里构建两条简单的轨迹,仅作示例
  39. learun.pathSimplifierIns.setData([{
  40. name: '轨迹0',
  41. path: [
  42. [100.340417, 27.376994],
  43. [100.239417, 27.3764],
  44. [100.238417, 27.386994],
  45. [100.137417, 27.379994],
  46. [100.436417, 27.396994],
  47. [100.535417, 27.376694],
  48. [100.134417, 27.374994],
  49. [100.232417, 27.372994],
  50. [100.331417, 27.376994],
  51. ]
  52. }]);
  53. //创建一个巡航器
  54. var navg0 = learun.pathSimplifierIns.createPathNavigator(0, //关联第1条轨迹
  55. {
  56. loop: false, //循环播放
  57. speed: 10000
  58. });
  59. //播放速度控制
  60. $page.find('.speed-set').on('tap', function () {
  61. var speedSign = $page.find('#speed-icon');
  62. if(speedSign.hasClass('icon-beisu1')){
  63. speedSign.removeClass('icon-beisu1');
  64. speedSign.addClass('icon-beisu2');
  65. $page.find('.speed-level').html('中速');
  66. navg0.setSpeed(2*10000);
  67. }else if(speedSign.hasClass('icon-beisu2')){
  68. speedSign.removeClass('icon-beisu2');
  69. speedSign.addClass('icon-beisu4');
  70. $page.find('.speed-level').html('快速');
  71. navg0.setSpeed(4*10000);
  72. }else if(speedSign.hasClass('icon-beisu4')){
  73. speedSign.removeClass('icon-beisu4');
  74. speedSign.addClass('icon-beisu1');
  75. $page.find('.speed-level').html('慢速');
  76. navg0.setSpeed(10000);
  77. }
  78. });
  79. // 播放暂停切换
  80. $page.find('.icon-bofang').on('tap', function () {
  81. var playSign = $page.find('#play-pause');
  82. if(playSign.hasClass('icon-bofang')){
  83. playSign.removeClass('icon-bofang');
  84. playSign.addClass('icon-zanting');
  85. if(navg0.getNaviStatus() == 'stop'){
  86. navg0.start();
  87. }else{
  88. navg0.resume();
  89. }
  90. }else{
  91. playSign.removeClass('icon-zanting');
  92. playSign.addClass('icon-bofang');
  93. navg0.pause();
  94. }
  95. });
  96. //节点控制
  97. $page.find('.icon-last').on('tap', function () {
  98. if(navg0.getNaviStatus() == 'stop'){
  99. return;
  100. }
  101. if(navg0.getNaviStatus() == 'moving'){
  102. navg0.pause();
  103. $('#play-pause').removeClass('icon-zanting');
  104. $('#play-pause').addClass('icon-bofang');
  105. }
  106. //当前节点索引
  107. var presentNode = navg0.getCursor().idx;
  108. if(presentNode == 0){
  109. navg0.moveToPoint(0, 0);
  110. return;
  111. }
  112. navg0.moveToPoint(presentNode-1, 0);
  113. learun.pathSimplifierIns.render();
  114. });
  115. $page.find('.icon-next').on('tap', function () {
  116. if(navg0.getNaviStatus() == 'stop'){
  117. return;
  118. }
  119. if(navg0.getNaviStatus() == 'moving'){
  120. navg0.pause();
  121. $('#play-pause').removeClass('icon-zanting');
  122. $('#play-pause').addClass('icon-bofang');
  123. }
  124. var endNode = navg0.getPathEndIdx();
  125. var presentNode = navg0.getCursor().idx;
  126. if(presentNode == endNode){
  127. return;
  128. }
  129. navg0.moveToPoint(presentNode+1, 0);
  130. learun.pathSimplifierIns.render();
  131. });
  132. $page.find('date-set').on('tap', function(){
  133. // $('.outcase').hide();
  134. $('.widthset').show();
  135. });
  136. }
  137. AMapUI.load(['ui/misc/PathSimplifier'], function(PathSimplifier) {
  138. if (!PathSimplifier.supportCanvas) {
  139. alert('当前环境不支持 Canvas!');
  140. return;
  141. }
  142. //启动页面
  143. learun.initPage(PathSimplifier);
  144. });
  145. }
  146. };
  147. return page;
  148. })();