route.js 11 KB

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