trackPlayback.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. <template>
  2. <el-dialog
  3. title="车辆轨迹"
  4. append-to-body
  5. custom-class="dialog_two"
  6. :visible.sync="dialogVisible"
  7. lock-scroll
  8. width="80%">
  9. <div id="container" v-if="dialogVisible"></div>
  10. <div class="input-card" style="right: 10.3%;bottom: 10.3%" v-if="this.lineArr.length>0">
  11. <h4>轨迹回放控制</h4>
  12. <div class="input-item">
  13. <input type="button" class="btn" value="开始动画" id="start" @click="startAnimation()"/>
  14. <input type="button" class="btn" value="暂停动画" id="pause" @click="pauseAnimation()"/>
  15. </div>
  16. <div class="input-item">
  17. <input type="button" class="btn" value="继续动画" id="resume" @click="resumeAnimation()"/>
  18. <input type="button" class="btn" value="停止动画" id="stop" @click="stopAnimation()"/>
  19. </div>
  20. </div>
  21. <div class="input-card" style="right: 10.3%;bottom: 10.3%" v-else>
  22. <span style="color: red">暂无该车辆轨迹信息</span>
  23. </div>
  24. </el-dialog>
  25. </template>
  26. <script>
  27. export default {
  28. name: "trackPlayback",
  29. props: {
  30. dialogVisible: {
  31. type: Boolean
  32. },
  33. parkingPoint: {
  34. type: Boolean
  35. },
  36. lineArr:Object,
  37. },
  38. data(){
  39. return{
  40. map: null,
  41. marker: null,
  42. infoWindow: null
  43. }
  44. },
  45. beforeDestroy() {
  46. this.map && this.map.destroy();
  47. },
  48. methods:{
  49. initMap() {
  50. this.map = new AMap.Map("container", {
  51. resizeEnable: true,
  52. center: this.lineArr.length >0 ?this.lineArr[this.lineArr.length - 1]:[120.382891,36.066460],
  53. zoom: 17
  54. });
  55. let icon = new AMap.Icon({
  56. size: new AMap.Size(52, 26), // 图标尺寸
  57. image: 'https://trade.tubaosoft.com/file/bladex/000000/1123598821738675201/che.png',
  58. imageSize: new AMap.Size(52, 26), // 根据所设置的大小拉伸或压缩图片
  59. });
  60. this.marker = new AMap.Marker({
  61. map: this.map,
  62. position: this.lineArr.length >0 ?this.lineArr[this.lineArr.length - 1]:[120.382891,36.066460],
  63. // icon: "https://webapi.amap.com/images/car.png",
  64. icon: icon,
  65. markerMeta: new AMap.Size(28, 28),
  66. offset: new AMap.Pixel(-26, -15),
  67. autoRotation: true,
  68. angle: -15
  69. });
  70. // 绘制轨迹
  71. let polyline = new AMap.Polyline({
  72. map: this.map,
  73. path: this.lineArr,
  74. showDir: true,
  75. strokeColor: "#28F", //线颜色
  76. // strokeOpacity: 1, //线透明度
  77. strokeWeight: 6 //线宽
  78. // strokeStyle: "solid" //线样式
  79. });
  80. let passedPolyline = new AMap.Polyline({
  81. map: this.map,
  82. path: this.lineArr,
  83. strokeColor: "#AF5", //线颜色
  84. // strokeOpacity: 1, //线透明度
  85. strokeWeight: 6 //线宽
  86. // strokeStyle: "solid" //线样式
  87. });
  88. if (this.parkingPoint.length>0){
  89. this.infoWindow = new AMap.InfoWindow({
  90. offset: new AMap.Pixel(0, -30)
  91. });
  92. for (let i = 0; i < this.parkingPoint.length; i++) {
  93. this.marker = new AMap.Marker({
  94. position: this.parkingPoint[i].location,
  95. map: this.map
  96. });
  97. // (this.parkingPoint[i].ete - this.parkingPoint[i].bte)
  98. console.log(this.fun(this.parkingPoint[i].bte, this.parkingPoint[i].ete));
  99. this.marker.content = '<div style="width: 300px;">'
  100. + '<p style="font-size: 22px;font-weight: bold;background-color: #2d8cf0;color: #fff;">' + this.fun(this.parkingPoint[i].bte, this.parkingPoint[i].ete) + '</p>'
  101. + '<p style="padding: 5px 0"><span style="color: #a0a0a0">停车时间:</span>' + (new Date(Number(this.parkingPoint[i].bte) + 8 * 60 * 60 * 1000).toJSON().split('T').join(' ').substr(0, 19)).slice(5,19)+'至'+ (new Date(Number(this.parkingPoint[i].ete) + 8 * 60 * 60 * 1000).toJSON().split('T').join(' ').substr(0, 19)).slice(5,19)+ '</p>'
  102. + '<p><span style="color: #a0a0a0">当前位置:</span>' +this.parkingPoint[i].address + '</p>'
  103. + '</div>'
  104. this.marker.on('click', this.markerClick);
  105. this.marker.emit('click', {target: this.marker});
  106. }
  107. }
  108. this.map.setFitView();
  109. },
  110. fun(startTime,endTime) {
  111. let usedTime = endTime - startTime; // 相差的毫秒数
  112. let days = Math.floor(usedTime / (24 * 3600 * 1000)); // 计算出天数
  113. let leavel = usedTime % (24 * 3600 * 1000); // 计算天数后剩余的时间
  114. let hours = Math.floor(leavel / (3600 * 1000)); // 计算剩余的小时数
  115. let leavel2 = leavel % (3600 * 1000); // 计算剩余小时后剩余的毫秒数
  116. let minutes = Math.floor(leavel2 / (60 * 1000)); // 计算剩余的分钟数
  117. if (startTime && endTime){
  118. return days + '天' + hours + '时' + minutes + '分'
  119. }else {
  120. return '获取失败'
  121. }
  122. },
  123. markerClick(e) {
  124. this.infoWindow.setContent(e.target.content);
  125. this.infoWindow.open(this.map, e.target.getPosition());
  126. },
  127. startAnimation() {
  128. this.marker.moveAlong(this.lineArr, 10000);
  129. },
  130. pauseAnimation() {
  131. this.marker.pauseMove();
  132. },
  133. resumeAnimation() {
  134. this.marker.resumeMove();
  135. },
  136. stopAnimation() {
  137. this.marker.stopMove();
  138. },
  139. }
  140. }
  141. </script>
  142. <style scoped src="../styles/demo-center.css"></style>
  143. <style scoped>
  144. #container {
  145. height: 80vh;
  146. width: 100%;
  147. }
  148. .input-card .btn {
  149. margin-right: 1.2rem;
  150. width: 9rem;
  151. }
  152. .input-card .btn:last-child {
  153. margin-right: 0;
  154. }
  155. </style>
  156. <style lang="scss" scoped>
  157. .home-container {
  158. padding: 0px 5px 5px 0px;
  159. box-sizing: border-box;
  160. height: 100%;
  161. ::v-deep .el-card__body {
  162. padding: 10px 15px;
  163. font-size: 14px;
  164. }
  165. &__card {
  166. width: 100%;
  167. height: 100%;
  168. }
  169. .title {
  170. display: flex;
  171. justify-content: space-between;
  172. }
  173. }
  174. .content {
  175. }
  176. ::v-deep .el-dialog {
  177. margin-top: 5vh !important;
  178. margin-bottom: 0 !important;
  179. }
  180. ::v-deep .el-dialog__body {
  181. padding: 0 20px 10px 20px !important;
  182. }
  183. ::v-deep .amap-info-close{
  184. right: 10px!important;
  185. top: 12px !important;
  186. }
  187. ::v-deep .amap-info-content{
  188. padding: 5px 5px 5px 5px !important;
  189. }
  190. </style>