shiftInfo-map.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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: 550px"
  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 greenIcon from "@/assets/icons/green.svg";
  52. import redIcon from "@/assets/icons/red.svg";
  53. export default {
  54. props :{
  55. shift : {
  56. type: Object,
  57. default: null
  58. }
  59. },
  60. data() {
  61. return {
  62. busIcon: busIcon,
  63. stationIcon: stationIcon,
  64. showMapDialog: true,
  65. loading: false,
  66. centerPoint: [112.276585, 30.306401],
  67. stationList: [],
  68. mapPath: [],
  69. vehicle: {},
  70. vehiclePos: [112.276585, 30.306401],
  71. plugin: [
  72. {
  73. pName: "ToolBar",
  74. events: {
  75. init(instance) {
  76. console.log(instance);
  77. }
  78. }
  79. }
  80. ]
  81. }
  82. },
  83. methods: {
  84. loadVehicle(vehicleId) {
  85. vehicleInfoApi.edit(vehicleId).then(response=>{
  86. var jsonData = response.data;
  87. this.vehicle = jsonData.data;
  88. this.vehiclePos = [this.vehicle.longitude,this.vehicle.latitude];
  89. this.centerPoint = this.vehiclePos;
  90. console.log(this.centerPoint);
  91. // setTimeout(()=>{
  92. // this.loadVehicle(vehicleId);
  93. // },60000);
  94. });
  95. },
  96. loadRouteMap(routeId) {
  97. //读取当前路线的站点
  98. this.loading = true;
  99. routeInfoApi.edit(routeId).then((response) => {
  100. this.loading = false;
  101. var jsonData = response.data;
  102. var model = jsonData.data;
  103. var _stationList = model.stationList;
  104. if (model.pathList != null) {
  105. this.mapPath = model.pathList.map((item) => {
  106. return item.split(",");
  107. });
  108. //this.centerPoint = this.mapPath[0];
  109. } else {
  110. this.mapPath = [];
  111. }
  112. if (_stationList.length <= 1) {
  113. this.$message.warning("请先至少设置2个站点!");
  114. } else {
  115. this.stationList = [];
  116. var initMapPath = this.mapPath.length == 0;
  117. _stationList.forEach((item) => {
  118. if (item.location != null && item.location.length > 0) {
  119. var station = {
  120. id: item.id,
  121. title: item.name,
  122. position: item.location.split(","),
  123. icon: stationIcon
  124. };
  125. this.stationList.push(station);
  126. if(item.stationSubInfoList!=null){
  127. item.stationSubInfoList.forEach(subItem=>{
  128. var startToEnd = subItem.startStationId == this.stationList[0].id;
  129. this.stationList.push({
  130. id: subItem.id,
  131. title: item.name + "入口" + (startToEnd ? "(起)" : "(终)"),
  132. position: [subItem.longitude,subItem.latitude],
  133. icon: startToEnd ? greenIcon : redIcon
  134. });
  135. });
  136. }
  137. if (initMapPath) {
  138. this.mapPath.push(station.position);
  139. }
  140. }
  141. });
  142. // if (this.mapPath.length > 0) {
  143. // this.centerPoint = this.mapPath[0];
  144. // }
  145. }
  146. });
  147. }
  148. },
  149. mounted: function () {
  150. console.log("mounted");
  151. console.log(this.shift);
  152. if(this.shift!=null) {
  153. this.loadVehicle(this.shift.vehicleId);
  154. this.loadRouteMap(this.shift.routeId);
  155. }
  156. }
  157. }
  158. </script>
  159. <style>
  160. </style>