route.js 12 KB

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