trackPlayback.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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. // 绘制轨迹
  61. let polyline = new AMap.Polyline({
  62. map: this.map,
  63. path: this.lineArr,
  64. showDir: true,
  65. strokeColor: "#28F", //线颜色
  66. // strokeOpacity: 1, //线透明度
  67. strokeWeight: 6 //线宽
  68. // strokeStyle: "solid" //线样式
  69. });
  70. let passedPolyline = new AMap.Polyline({
  71. map: this.map,
  72. path: this.lineArr,
  73. strokeColor: "#AF5", //线颜色
  74. // strokeOpacity: 1, //线透明度
  75. strokeWeight: 6 //线宽
  76. // strokeStyle: "solid" //线样式
  77. });
  78. if (this.parkingPoint.length>0){
  79. this.infoWindow = new AMap.InfoWindow({
  80. offset: new AMap.Pixel(0, -30)
  81. });
  82. for (let i = 0; i < this.parkingPoint.length; i++) {
  83. this.marker = new AMap.Marker({
  84. position: this.parkingPoint[i].location,
  85. map: this.map
  86. });
  87. let fun = this.fun(this.parkingPoint[i].bte, this.parkingPoint[i].ete)==='获取失败'?'':this.fun(this.parkingPoint[i].bte, this.parkingPoint[i].ete)
  88. this.marker.content = '<div style="width: 300px;">'
  89. + '<p style="font-size: 22px;font-weight: bold;background-color: #2d8cf0;color: #fff;">' + fun + '</p>'
  90. + '<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>'
  91. + '<p><span style="color: #a0a0a0">当前位置:</span>' +this.parkingPoint[i].address + '</p>'
  92. + '</div>'
  93. this.marker.on('click', this.markerClick);
  94. this.marker.emit('click', {target: this.marker});
  95. }
  96. }
  97. this.marker = new AMap.Marker({
  98. map: this.map,
  99. position: this.lineArr.length >0 ?this.lineArr[this.lineArr.length - 1]:[120.382891,36.066460],
  100. // icon: "https://webapi.amap.com/images/car.png",
  101. icon: icon,
  102. markerMeta: new AMap.Size(28, 28),
  103. offset: new AMap.Pixel(-26, -15),
  104. autoRotation: true,
  105. angle: -15
  106. });
  107. this.map.setFitView();
  108. },
  109. fun(startTime,endTime) {
  110. let usedTime = endTime - startTime; // 相差的毫秒数
  111. let days = Math.floor(usedTime / (24 * 3600 * 1000)); // 计算出天数
  112. let leavel = usedTime % (24 * 3600 * 1000); // 计算天数后剩余的时间
  113. let hours = Math.floor(leavel / (3600 * 1000)); // 计算剩余的小时数
  114. let leavel2 = leavel % (3600 * 1000); // 计算剩余小时后剩余的毫秒数
  115. let minutes = Math.floor(leavel2 / (60 * 1000)); // 计算剩余的分钟数
  116. if (startTime && endTime){
  117. return days + '天' + hours + '时' + minutes + '分'
  118. }else {
  119. return '获取失败'
  120. }
  121. },
  122. markerClick(e) {
  123. this.infoWindow.setContent(e.target.content);
  124. this.infoWindow.open(this.map, e.target.getPosition());
  125. },
  126. startAnimation() {
  127. this.marker.moveAlong(this.lineArr, 10000);
  128. },
  129. pauseAnimation() {
  130. this.marker.pauseMove();
  131. },
  132. resumeAnimation() {
  133. this.marker.resumeMove();
  134. },
  135. stopAnimation() {
  136. this.marker.stopMove();
  137. },
  138. }
  139. }
  140. </script>
  141. <style scoped src="../styles/demo-center.css"></style>
  142. <style scoped>
  143. #container {
  144. height: 80vh;
  145. width: 100%;
  146. }
  147. .input-card .btn {
  148. margin-right: 1.2rem;
  149. width: 9rem;
  150. }
  151. .input-card .btn:last-child {
  152. margin-right: 0;
  153. }
  154. </style>
  155. <style lang="scss" scoped>
  156. .home-container {
  157. padding: 0px 5px 5px 0px;
  158. box-sizing: border-box;
  159. height: 100%;
  160. ::v-deep .el-card__body {
  161. padding: 10px 15px;
  162. font-size: 14px;
  163. }
  164. &__card {
  165. width: 100%;
  166. height: 100%;
  167. }
  168. .title {
  169. display: flex;
  170. justify-content: space-between;
  171. }
  172. }
  173. .content {
  174. }
  175. ::v-deep .el-dialog {
  176. margin-top: 5vh !important;
  177. margin-bottom: 0 !important;
  178. }
  179. ::v-deep .el-dialog__body {
  180. padding: 0 20px 10px 20px !important;
  181. }
  182. ::v-deep .amap-info-close{
  183. right: 10px!important;
  184. top: 12px !important;
  185. }
  186. ::v-deep .amap-info-content{
  187. padding: 5px 5px 5px 5px !important;
  188. }
  189. </style>