route.js 12 KB

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