trackPlayback.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. lineArr:Object,
  34. },
  35. data(){
  36. return{
  37. map: null,
  38. marker: null
  39. }
  40. },
  41. beforeDestroy() {
  42. this.map && this.map.destroy();
  43. },
  44. methods:{
  45. initMap() {
  46. this.map = new AMap.Map("container", {
  47. resizeEnable: true,
  48. center: this.lineArr.length >0 ?this.lineArr[this.lineArr.length - 1]:[120.382891,36.066460],
  49. zoom: 17
  50. });
  51. let icon = new AMap.Icon({
  52. size: new AMap.Size(52, 26), // 图标尺寸
  53. image: 'https://webapi.amap.com/images/car.png',
  54. imageSize: new AMap.Size(52, 26), // 根据所设置的大小拉伸或压缩图片
  55. });
  56. this.marker = new AMap.Marker({
  57. map: this.map,
  58. position: this.lineArr.length >0 ?this.lineArr[this.lineArr.length - 1]:[120.382891,36.066460],
  59. // icon: "https://webapi.amap.com/images/car.png",
  60. icon: icon,
  61. markerMeta: new AMap.Size(28, 28),
  62. offset: new AMap.Pixel(-26, -15),
  63. autoRotation: true,
  64. angle: -15
  65. });
  66. // 绘制轨迹
  67. let polyline = new AMap.Polyline({
  68. map: this.map,
  69. path: this.lineArr,
  70. showDir: true,
  71. strokeColor: "#28F", //线颜色
  72. // strokeOpacity: 1, //线透明度
  73. strokeWeight: 6 //线宽
  74. // strokeStyle: "solid" //线样式
  75. });
  76. let passedPolyline = new AMap.Polyline({
  77. map: this.map,
  78. path: this.lineArr,
  79. strokeColor: "#AF5", //线颜色
  80. // strokeOpacity: 1, //线透明度
  81. strokeWeight: 6 //线宽
  82. // strokeStyle: "solid" //线样式
  83. });
  84. this.marker.on("moving", function (e) {
  85. passedPolyline.setPath(e.passedPath);
  86. });
  87. this.map.setFitView();
  88. },
  89. startAnimation() {
  90. this.marker.moveAlong(this.lineArr, 100000);
  91. },
  92. pauseAnimation() {
  93. this.marker.pauseMove();
  94. },
  95. resumeAnimation() {
  96. this.marker.resumeMove();
  97. },
  98. stopAnimation() {
  99. this.marker.stopMove();
  100. },
  101. }
  102. }
  103. </script>
  104. <style scoped src="../styles/demo-center.css"></style>
  105. <style scoped>
  106. #container {
  107. height: 80vh;
  108. width: 100%;
  109. }
  110. .input-card .btn {
  111. margin-right: 1.2rem;
  112. width: 9rem;
  113. }
  114. .input-card .btn:last-child {
  115. margin-right: 0;
  116. }
  117. </style>
  118. <style lang="scss" scoped>
  119. .home-container {
  120. padding: 0px 5px 5px 0px;
  121. box-sizing: border-box;
  122. height: 100%;
  123. ::v-deep .el-card__body {
  124. padding: 10px 15px;
  125. font-size: 14px;
  126. }
  127. &__card {
  128. width: 100%;
  129. height: 100%;
  130. }
  131. .title {
  132. display: flex;
  133. justify-content: space-between;
  134. }
  135. }
  136. .content {
  137. }
  138. ::v-deep .el-dialog {
  139. margin-top: 5vh !important;
  140. margin-bottom: 0 !important;
  141. }
  142. ::v-deep .el-dialog__body {
  143. padding: 0 20px 10px 20px !important;
  144. }
  145. </style>