route.js 12 KB

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