route.js 11 KB

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