trackPlayback.vue 6.1 KB

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