trackPlayback.vue 6.4 KB

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