route.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. (function () {
  2. var page = {
  3. init: function ($page) {
  4. //页面初始化
  5. learun.layer.loading(true, "加载数据中");
  6. //播放控制相关事件清除
  7. function removeEvents(){
  8. $(".icon-bofang").off("tap");
  9. $(".icon-last").off("tap");
  10. $(".icon-next").off("tap");
  11. $(".speed-set").off("tap");
  12. }
  13. //地图初始化
  14. var routeMap = new AMap.Map('route-map', {
  15. center: [117.000923, 36.675807],
  16. zoom: 15
  17. });
  18. routeMap.on('complete', function(){
  19. learun.layer.loading(false);
  20. });
  21. //test
  22. var initPage = function(PathSimplifier, data) {
  23. if(!data){
  24. window.pathSimplifierIns.setData([]);
  25. window.pathSimplifierIns = null;
  26. return;
  27. }
  28. removeEvents();
  29. console.log
  30. if(window.pathSimplifierIns){
  31. window.pathSimplifierIns.setData([]);
  32. window.pathSimplifierIns = null;
  33. }
  34. //创建组件实例
  35. var pathSimplifierIns = new PathSimplifier({
  36. zIndex: 100,
  37. map: routeMap, //所属的地图实例
  38. getPath: function(pathData, pathIndex) {
  39. //返回轨迹数据中的节点坐标信息,[AMap.LngLat, AMap.LngLat...] 或者 [[lng|number,lat|number],...]
  40. // return pathData.path;
  41. var points = pathData.points,
  42. lnglatList = [];
  43. for (var i = 0, len = points.length; i < len; i++) {
  44. lnglatList.push(points[i].lngLat);
  45. }
  46. return lnglatList;
  47. },
  48. renderOptions: {
  49. //轨迹线的样式
  50. pathLineStyle: {
  51. strokeStyle: 'red',
  52. lineWidth: 6,
  53. dirArrowStyle: true
  54. }
  55. }
  56. });
  57. pathSimplifierIns.setData(data);
  58. console.log(pathSimplifierIns.getPathNavigators());
  59. //创建一个巡航器
  60. var navg0 = pathSimplifierIns.createPathNavigator(0, //关联第1条轨迹
  61. {
  62. loop: false, //循环播放
  63. speed: 1000
  64. });
  65. //播放速度控制
  66. $page.find('.speed-set').on('tap', function () {
  67. var speedSign = $page.find('#speed-icon');
  68. if(speedSign.hasClass('icon-beisu1')){
  69. speedSign.removeClass('icon-beisu1');
  70. speedSign.addClass('icon-beisu2');
  71. $page.find('.speed-level').html('中速');
  72. navg0.setSpeed(2*10000);
  73. }else if(speedSign.hasClass('icon-beisu2')){
  74. speedSign.removeClass('icon-beisu2');
  75. speedSign.addClass('icon-beisu4');
  76. $page.find('.speed-level').html('快速');
  77. navg0.setSpeed(4*10000);
  78. }else if(speedSign.hasClass('icon-beisu4')){
  79. speedSign.removeClass('icon-beisu4');
  80. speedSign.addClass('icon-beisu1');
  81. $page.find('.speed-level').html('慢速');
  82. navg0.setSpeed(10000);
  83. }
  84. });
  85. // 播放暂停切换
  86. $page.find('.icon-bofang').on('tap', function () {
  87. var playSign = $page.find('#play-pause');
  88. if(playSign.hasClass('icon-bofang')){
  89. playSign.removeClass('icon-bofang');
  90. playSign.addClass('icon-zanting');
  91. if(navg0.getNaviStatus() == 'stop'){
  92. navg0.start();
  93. }else{
  94. navg0.resume();
  95. }
  96. }else{
  97. playSign.removeClass('icon-zanting');
  98. playSign.addClass('icon-bofang');
  99. navg0.pause();
  100. }
  101. });
  102. //节点控制
  103. $page.find('.icon-last').on('tap', function () {
  104. if(navg0.getNaviStatus() == 'stop'){
  105. return;
  106. }
  107. if(navg0.getNaviStatus() == 'moving'){
  108. navg0.pause();
  109. // $('#play-pause').removeClass('icon-zanting');
  110. // $('#play-pause').addClass('icon-bofang');
  111. }
  112. //当前节点索引
  113. var presentNode = navg0.getCursor().idx;
  114. if(presentNode == 0){
  115. navg0.moveToPoint(0, 0);
  116. return;
  117. }
  118. navg0.moveToPoint(presentNode-1, 0);
  119. pathSimplifierIns.render();
  120. });
  121. $page.find('.icon-next').on('tap', function () {
  122. if(navg0.getNaviStatus() == 'stop'){
  123. return;
  124. }
  125. if(navg0.getNaviStatus() == 'moving'){
  126. navg0.pause();
  127. // $('#play-pause').removeClass('icon-zanting');
  128. // $('#play-pause').addClass('icon-bofang');
  129. }
  130. var endNode = navg0.getPathEndIdx();
  131. var presentNode = navg0.getCursor().idx;
  132. if(presentNode == endNode){
  133. return;
  134. }
  135. navg0.moveToPoint(presentNode+1, 0);
  136. pathSimplifierIns.render();
  137. });
  138. //检测末端
  139. navg0.on('pause', function(){
  140. $('#play-pause').removeClass('icon-zanting');
  141. $('#play-pause').addClass('icon-bofang');
  142. });
  143. // $page.find('.text-area').on('tap', function(){
  144. // navg0.destroy();
  145. // });
  146. window.pathSimplifierIns = pathSimplifierIns;
  147. }
  148. AMapUI.load(['ui/misc/PathSimplifier'], function(PathSimplifier) {
  149. if (!PathSimplifier.supportCanvas) {
  150. alert('当前环境不支持 Canvas!');
  151. return;
  152. }
  153. $page.find('.date-set').rldate({
  154. type: 'date'
  155. },function(date){
  156. // $page.find('.f-dtpicker-ok').on('tap', function(){
  157. // });
  158. var pattern = /\d{4}(\-|\/|.)\d{1,2}\1\d{1,2}/;
  159. if(!pattern.test(date)){
  160. learun.layer.toast('请选择正确轨迹的日期');
  161. return;
  162. }
  163. var post_data = {
  164. "date":date,
  165. "deviceNumber":'868500028325363'
  166. }
  167. learun.httppost(config.webapi+'?s=api/get_gps_route',post_data,function(res){
  168. if(!res.success){
  169. learun.layer.toast(res.message);
  170. }
  171. var data = null;
  172. if(res.data){
  173. data = [{name:'test1',points:[]}];
  174. JSON.parse(res.data).forEach(v => {
  175. data[0].points.push({speed:v.speed, lngLat:[v.lng, v.lat]});
  176. });
  177. console.log(data);
  178. }
  179. initPage(PathSimplifier, data);
  180. });
  181. });
  182. // $page.find('.lr-btn-primary').on('tap', function(){
  183. // var date = $('#date2')[0].innerText;
  184. // console.log(date);
  185. // $('.widthset').hide();
  186. // $('.outcase').show();
  187. // });
  188. //日期格式化
  189. Date.prototype.Format = function(fmt)
  190. { //author: meizz
  191. var o = {
  192. "M+" : this.getMonth()+1, //月份
  193. "d+" : this.getDate(), //日
  194. "h+" : this.getHours(), //小时
  195. "m+" : this.getMinutes(), //分
  196. "s+" : this.getSeconds(), //秒
  197. "q+" : Math.floor((this.getMonth()+3)/3), //季度
  198. "S" : this.getMilliseconds() //毫秒
  199. };
  200. if(/(y+)/.test(fmt))
  201. fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
  202. for(var k in o)
  203. if(new RegExp("("+ k +")").test(fmt))
  204. fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
  205. return fmt;
  206. }
  207. //启动页面
  208. // initPage(PathSimplifier);
  209. // 6789012345
  210. var nowDate = new Date().Format("yyyy-MM-dd");
  211. console.log(nowDate);
  212. var post_data = {
  213. "date": nowDate,
  214. "deviceNumber":'6789012345'
  215. }
  216. learun.httppost(config.webapi+'?s=api/get_gps_route',post_data,function(res){
  217. if(!res.success){
  218. learun.layer.toast(res.message);
  219. return;
  220. }
  221. var data = [{name:'test1',points:[]}];
  222. JSON.parse(res.data).forEach(v => {
  223. data[0].points.push({speed:v.speed, lngLat:[v.lng, v.lat]});
  224. });
  225. console.log(data);
  226. learun.initPage(PathSimplifier, data);
  227. });
  228. });
  229. }
  230. };
  231. return page;
  232. })();