index.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <base href="//webapi.amap.com/ui/1.0/ui/misc/PathSimplifier/examples/" />
  5. <meta charset="utf-8">
  6. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  7. <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
  8. <link rel="stylesheet" href="https://a.amap.com/jsapi_demos/static/demo-center/css/demo-center.css" />
  9. <link rel="stylesheet" href="https://trace.weilaibike.com/js/lCalendar.css" />
  10. <!-- <link rel="stylesheet" href="css/lCalendar.css"> -->
  11. <script src="https://cdn.bootcss.com/vue/2.6.11/vue.min.js"></script>
  12. <script src="https://cdn.bootcss.com/axios/0.19.2/axios.min.js"></script>
  13. <script src="https://cdn.bootcss.com/qs/6.9.3/qs.min.js"></script>
  14. <title>车辆位置</title>
  15. <style>
  16. html,
  17. body,
  18. #container {
  19. width: 100%;
  20. height: 100%;
  21. }
  22. #container {
  23. position: relative;
  24. }
  25. .date {
  26. width: 100%;
  27. position: absolute;
  28. top: 5%;
  29. left: 0;
  30. z-index: 9999;
  31. }
  32. .dateCon {
  33. width: 80%;
  34. height: 112px;
  35. margin: 0 auto;
  36. background: #fff;
  37. border-radius: 10px;
  38. }
  39. .dateCon div {
  40. padding: 8px 15px;
  41. }
  42. .dateCon input {
  43. /* background:#f00; */
  44. width: 150px;
  45. outline: none;
  46. border: none;
  47. padding: 0;
  48. height: 15px;
  49. cursor: pointer
  50. }
  51. .button {
  52. display: flex;
  53. justify-content: space-around;
  54. align-items: center;
  55. }
  56. .button span {
  57. display: inline-block;
  58. background: #18d5b9;
  59. color: #fff;
  60. padding: 5px 30px;
  61. border-radius: 5px;
  62. }
  63. </style>
  64. </head>
  65. <body>
  66. <div id="container">
  67. <div id="app">
  68. <div class="date">
  69. <div class="dateCon">
  70. <div>
  71. <span>
  72. <span>开始时间:</span>
  73. <input class="start" id="demo1" type="text" placeholder="选择开始时间" ref="demo1" readonly>
  74. </span>
  75. </div>
  76. <div>
  77. <span>结束时间:</span>
  78. <input class="end" type="text" id="demo2" placeholder="选择结束时间" ref="demo2" readonly>
  79. </div>
  80. <div class="button">
  81. <span @click="getPosition">显示轨迹</span>
  82. <span>清除轨迹</span>
  83. </div>
  84. </div>
  85. </div>
  86. </div>
  87. </div>
  88. <!-- 加载地图JSAPI脚本 -->
  89. <script src="https://webapi.amap.com/maps?v=1.4.15&key=bd75d5583e6e04663da170715ff52b3d"></script>
  90. <script src="https://webapi.amap.com/ui/1.0/main.js?v=1.0.11"></script>
  91. <script src="https://trace.weilaibike.com/js/datePicker.js"></script>
  92. <script src="https://trace.weilaibike.com/js/jquery-1.4.2.min.js"></script>
  93. <script src="https://trace.weilaibike.com/js/lCalendar.js"></script>
  94. <!-- <script src="http://resource.weilaibike.com/yunwei/datePicker.js"></script> -->
  95. <script>
  96. $(function () {
  97. var calendardatetime = new lCalendar();
  98. calendardatetime.init({
  99. 'trigger': '#demo1',
  100. 'type': 'datetime'
  101. });
  102. var calendardatetime = new lCalendar();
  103. calendardatetime.init({
  104. 'trigger': '#demo2',
  105. 'type': 'datetime'
  106. });
  107. });
  108. </script>
  109. <script>
  110. var map = new AMap.Map('container', {
  111. resizeEnable: true, //是否监控地图容器尺寸变化
  112. zoom: 4, //初始化地图层级
  113. center: [113.78620466447434, 34.78300092508428] //初始化地图中心点
  114. });
  115. var vm = new Vue({
  116. el: "#app", //找到并扫面和监控#app下的所有内容
  117. data: {
  118. pathDataTimes: '',
  119. token: '',
  120. bike_no: '',
  121. startTime: '',
  122. endTime: '',
  123. pathDate: []
  124. },
  125. created() {
  126. let that = this;
  127. // var url = "https://trace.weilaibike.com/trackTest.html?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC9hZG1pbi53ZWlsYWliaWtlLmRldi5oYW55aXl1bi5jb21cL2FwcC1hcGlcL2F1dGhcL2xvZ2luIiwiaWF0IjoxNTg2MzM2MTUxLCJleHAiOjE1ODY1MDg5NTEsIm5iZiI6MTU4NjMzNjE1MSwianRpIjoiOEx2WTdBWFhRQlBhUEE1MyIsInN1YiI6MSwicHJ2IjoiYzgyOTIyMzgzNWQxMTEzOGYwOGFjZTU2ZmZhNjYyOGJjMjY4M2NiNSJ9.6R8WlEsBhsYq_NPqmT4D6p4s5JgTH2mRN51_7kRA8XE&&bike_no=10010010044&&startTime=2020-04-01 16:19&&endTime=2020-04-09 16:19"
  128. var url = window.location.href; /*获取url里"?"后面的值*/
  129. var temp1 = url.split('?');
  130. var pram = temp1[1];
  131. var keyValue = pram.split('&&');
  132. var obj = {};
  133. for (var i = 0; i < keyValue.length; i++) {
  134. var item = keyValue[i].split('=');
  135. var key = item[0];
  136. var value = item[1];
  137. obj[key] = value;
  138. }
  139. that.token = obj.token;
  140. that.bike_no = obj.bike_no;
  141. that.startTime = obj.startTime;
  142. that.endTime = obj.endTime
  143. console.log(typeof (obj.startTime));
  144. console.log(typeof (obj.bike_no));
  145. console.log(typeof (obj.endTime));
  146. console.log(typeof (obj.token));
  147. // var url = window.location.href.split("?")[1]; /*获取url里"?"后面的值*/
  148. // if (url) { /*判断是否是一个参数还是多个参数*/
  149. // url = url.split("=")
  150. // that.token = url1
  151. // return url[1]; /*返回想要的参数值*/
  152. // } else {
  153. // return '';
  154. // }
  155. // let account = "admin";
  156. // let password = "123abc"
  157. // axios.post("https://admin.weilaibike.dev.hanyiyun.com/app-api/auth/login",Qs.stringify({account,password})).then(res=>{
  158. // console.log(res);
  159. // that.token = res.data.token
  160. // })
  161. // this.getTrack();
  162. this.getPosition();
  163. },
  164. methods: {
  165. getPosition() {
  166. console.log(this.$refs.demo1.value)
  167. alert(1)
  168. let that = this;
  169. let token = that.token;
  170. let data = {
  171. token: that.token,
  172. bike_no: that.bike_no,
  173. 'time_between[0]': that.startTime,
  174. ' time_between[1]': that.endTime,
  175. }
  176. axios.post("https://admin.weilaibike.com/app-api/bike/bikeLocation", Qs
  177. .stringify({
  178. token: that.token,
  179. bike_no: that.bike_no,
  180. 'time_between[0]': that.startTime,
  181. 'time_between[1]': that.endTime,
  182. })).then(res => {
  183. that.pathData = res.data.locations
  184. AMapUI.load(['ui/misc/PathSimplifier'], function (PathSimplifier) {
  185. if (!PathSimplifier.supportCanvas) {
  186. alert('当前环境不支持 Canvas!');
  187. return;
  188. }
  189. //启动页面
  190. initPage(PathSimplifier);
  191. });
  192. function initPage(PathSimplifier) {
  193. let that = this;
  194. //创建组件实例
  195. var pathSimplifierIns = new PathSimplifier({
  196. zIndex: 100,
  197. map: map, //所属的地图实例
  198. getPath: function (pathData, pathIndex) {
  199. console.log(pathData, 'pathData')
  200. //返回轨迹数据中的节点坐标信息,[AMap.LngLat, AMap.LngLat...] 或者 [[lng|number,lat|number],...]
  201. return pathData.path;
  202. },
  203. getHoverTitle: function (pathData, pathIndex, pointIndex) {
  204. //返回鼠标悬停时显示的信息
  205. if (pointIndex >= 0) {
  206. console.log(pointIndex, 'pointIndex')
  207. //鼠标悬停在某个轨迹节点上
  208. return pathData.name + ',点:' + pointIndex + '/' +
  209. pathData.path.length + ',时间:';
  210. }
  211. //鼠标悬停在节点之间的连线上
  212. return pathData.name + ',点数量' + pathData.path.length;
  213. },
  214. renderOptions: {
  215. //轨迹线的样式
  216. pathLineStyle: {
  217. strokeStyle: 'red',
  218. lineWidth: 6,
  219. dirArrowStyle: true
  220. },
  221. renderAllPointsIfNumberBelow: 100,
  222. }
  223. });
  224. //这里构建两条简单的轨迹,仅作示例
  225. pathSimplifierIns.setData([{
  226. name: '轨迹',
  227. path: res.data.locations
  228. },
  229. ]);
  230. //创建一个巡航器
  231. var navg0 = pathSimplifierIns.createPathNavigator(0, //关联第1条轨迹
  232. {
  233. loop: true, //循环播放
  234. speed: 500
  235. });
  236. navg0.start();
  237. }
  238. })
  239. },
  240. },
  241. })
  242. </script>
  243. </body>
  244. </html>