mapTrack.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /**
  2. // author:jiana
  3. // time:2025-04-23
  4. // desc:运单管理
  5. */
  6. <template>
  7. <div class="mapTrack">
  8. <!-- <div class="btnBox">
  9. <div>轨迹回放控制</div>
  10. <div style="margin:10px 0;">
  11. <Button size="small" type="primary" @click="startAnimation" ghost style="margin-right:20px;">开始动画</Button>
  12. <Button size="small" type="primary" @click="pauseAnimation" ghost>暂停动画</Button>
  13. </div>
  14. <div>
  15. <Button size="small" type="primary" @click="resumeAnimation" ghost style="margin-right:20px;">继续动画</Button>
  16. <Button size="small" type="primary" @click="stopAnimation" ghost>停止动画</Button>
  17. </div>
  18. </div> -->
  19. <div id="container"></div>
  20. </div>
  21. </template>
  22. <script>
  23. import { defineComponent, ref ,reactive, onMounted} from 'vue'
  24. import {useRoute} from 'vue-router'
  25. import AMapLoader from "@amap/amap-jsapi-loader";
  26. import axios from 'axios';
  27. import { tms } from '@/request/api'
  28. export default defineComponent({
  29. components:{
  30. },
  31. props:{
  32. waybillNum: { type: String, default: "" }
  33. },
  34. setup(props) {
  35. const route = useRoute()
  36. const data = ref(null);
  37. const trajectory = ref([]);
  38. const loadData = async () =>{
  39. trajectory.value = []
  40. await tms.truckTrackQueryByWaybillNum({waybillNum:props.waybillNum}).then(res =>{
  41. if (res.code == 101) {
  42. data.value = res.data
  43. if(data.value.obj && data.value.obj.runRoute){
  44. data.value.obj.runRoute.forEach(item => {
  45. if (!isNaN(item.lon) && !isNaN(item.lat)) {
  46. trajectory.value.push([Number(item.lon),Number(item.lat)])
  47. }
  48. });
  49. }
  50. }
  51. })
  52. }
  53. const getMap = () =>{
  54. AMapLoader.load({
  55. key: '81a1282308f1aae58082425a1ebb91b0',
  56. version: '2.0',
  57. plugins: ['AMap.MoveAnimation']
  58. }).then(AMap => {
  59. AMap.plugin('AMap.MoveAnimation', () => {
  60. var map = new AMap.Map('container', {
  61. center: trajectory.value[0],
  62. });
  63. // 起点
  64. var marker = new AMap.Marker({
  65. map: map,
  66. position: trajectory.value[0],
  67. icon: require('@/assets/images/qidian.png'), // 自定义图标
  68. offset: new AMap.Pixel(-13, -26),
  69. });
  70. // 终点
  71. var markerEnd = new AMap.Marker({
  72. map: map,
  73. position: trajectory.value.slice(-1).pop(),
  74. icon: require('@/assets/images/zhongdian.png'), // 自定义图标
  75. offset: new AMap.Pixel(-13, -26),
  76. });
  77. // 绘制轨迹
  78. var polyline = new AMap.Polyline({
  79. map: map,
  80. path: trajectory.value,
  81. showDir:true,
  82. strokeColor: "#28F", //线颜色
  83. strokeWeight: 6, //线宽
  84. });
  85. map.setFitView();
  86. map.setZoom(7);
  87. });
  88. }).catch(e => {
  89. console.error(e);
  90. });
  91. }
  92. onMounted(async ()=>{
  93. await loadData()
  94. await getMap()
  95. })
  96. return {
  97. }
  98. },
  99. })
  100. </script>
  101. <style lang="scss" scoped>
  102. .mapTrack{
  103. // padding: 20px;
  104. #container{
  105. width: 100%;
  106. height: 460px;
  107. }
  108. .btnBox{
  109. position: absolute;
  110. top: 70px;
  111. left: 20px;
  112. z-index: 1;
  113. background: #fff;
  114. width: 200px;
  115. height: 110px;
  116. padding: 10px;
  117. border-radius: 5px;
  118. }
  119. }
  120. </style>
  121. <style lang="scss">
  122. .amap-icon{
  123. width: 40px !important;
  124. height: 40px !important;
  125. }
  126. .amap-icon img{
  127. width: 40px !important;
  128. height: 40px !important;
  129. }
  130. </style>