shiftInfo-map.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <template>
  2. <div>
  3. <el-amap
  4. ref="shiftMap"
  5. vid="shiftMap"
  6. :plugin="plugin"
  7. :center="centerPoint"
  8. :zoom="15"
  9. style="width: 100%; height: 400px"
  10. >
  11. <!--车辆当前位置-->
  12. <el-amap-marker
  13. :zIndex="2"
  14. :position="vehiclePos"
  15. :title="vehicle.licensePlateNumber"
  16. :icon="busIcon"
  17. ></el-amap-marker>
  18. <!--站点-->
  19. <el-amap-marker
  20. :zIndex="1"
  21. v-for="station in stationList"
  22. :key="station.id"
  23. :position="station.position"
  24. :title="station.title"
  25. :icon="station.icon"
  26. ></el-amap-marker>
  27. <!--路线-->
  28. <el-amap-polyline
  29. :path="mapPath"
  30. :zIndex="2"
  31. :isOutline="true"
  32. :outlineColor="'#ffeeff'"
  33. :borderWeight="3"
  34. :strokeColor="'#3366FF'"
  35. :strokeOpacity="1"
  36. :strokeWeight="6"
  37. :strokeStyle="'solid'"
  38. :strokeDasharray="[10, 5]"
  39. :lineJoin="'round'"
  40. :lineCap="'round'"
  41. :editable="false"
  42. ></el-amap-polyline>
  43. </el-amap>
  44. </div>
  45. </template>
  46. <script>
  47. import routeInfoApi from "@/api/bus/routeInfo";
  48. import vehicleInfoApi from "@/api/bus/vehicleInfo";
  49. import busIcon from "@/assets/icons/bus.svg";
  50. import stationIcon from "@/assets/icons/station.svg";
  51. import subIcon from "@/assets/icons/sub.svg";
  52. export default {
  53. props :{
  54. shift : {
  55. type: Object,
  56. default: null
  57. }
  58. },
  59. data() {
  60. return {
  61. busIcon: busIcon,
  62. stationIcon: stationIcon,
  63. showMapDialog: true,
  64. loading: false,
  65. centerPoint: [112.276585, 30.306401],
  66. stationList: [],
  67. mapPath: [],
  68. vehicle: {},
  69. vehiclePos: [112.276585, 30.306401],
  70. plugin: [
  71. {
  72. pName: "ToolBar",
  73. events: {
  74. init(instance) {
  75. console.log(instance);
  76. }
  77. }
  78. }
  79. ]
  80. }
  81. },
  82. methods: {
  83. loadVehicle(vehicleId) {
  84. vehicleInfoApi.edit(vehicleId).then(response=>{
  85. var jsonData = response.data;
  86. this.vehicle = jsonData.data;
  87. this.vehiclePos = [this.vehicle.longitude,this.vehicle.latitude];
  88. this.centerPoint = this.vehiclePos;
  89. console.log(this.centerPoint);
  90. setTimeout(()=>{
  91. this.loadVehicle(vehicleId);
  92. },60000);
  93. });
  94. },
  95. loadRouteMap(routeId) {
  96. //读取当前路线的站点
  97. this.loading = true;
  98. routeInfoApi.edit(routeId).then((response) => {
  99. this.loading = false;
  100. var jsonData = response.data;
  101. var model = jsonData.data;
  102. var _stationList = model.stationList;
  103. if (model.pathList != null) {
  104. this.mapPath = model.pathList.map((item) => {
  105. return item.split(",");
  106. });
  107. //this.centerPoint = this.mapPath[0];
  108. } else {
  109. this.mapPath = [];
  110. }
  111. if (_stationList.length <= 1) {
  112. this.$message.warning("请先至少设置2个站点!");
  113. } else {
  114. this.stationList = [];
  115. var initMapPath = this.mapPath.length == 0;
  116. _stationList.forEach((item) => {
  117. if (item.location != null && item.location.length > 0) {
  118. var station = {
  119. id: item.id,
  120. title: item.name,
  121. position: item.location.split(","),
  122. icon: stationIcon
  123. };
  124. this.stationList.push(station);
  125. if(item.stationSubInfoList!=null){
  126. item.stationSubInfoList.forEach(subItem=>{
  127. this.stationList.push({
  128. id: subItem.id,
  129. title: item.name + "入口",
  130. position: [subItem.longitude,subItem.latitude],
  131. icon: subIcon
  132. });
  133. });
  134. }
  135. if (initMapPath) {
  136. this.mapPath.push(station.position);
  137. }
  138. }
  139. });
  140. // if (this.mapPath.length > 0) {
  141. // this.centerPoint = this.mapPath[0];
  142. // }
  143. }
  144. });
  145. }
  146. },
  147. mounted: function () {
  148. console.log("mounted");
  149. console.log(this.shift);
  150. if(this.shift!=null) {
  151. this.loadVehicle(this.shift.vehicleId);
  152. this.loadRouteMap(this.shift.routeId);
  153. }
  154. }
  155. }
  156. </script>
  157. <style>
  158. </style>