routeDetail.vue 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <template>
  2. <map class="map" id="map" ref="map1" :polyline='carRouteList' :markers="markers"></map>
  3. </template>
  4. <script>
  5. import {
  6. getRouterDetail
  7. } from '@/api/rent.js';
  8. export default {
  9. data() {
  10. return {
  11. // 路线图
  12. carRouteList: [],
  13. id: 0,
  14. map: '',
  15. markers: [],
  16. };
  17. },
  18. onLoad: function(option) {
  19. this.id = option.id
  20. },
  21. onReady() {
  22. this.info()
  23. },
  24. methods: {
  25. // 获取路径详细
  26. info() {
  27. getRouterDetail({
  28. id: this.id,
  29. type: 'record'
  30. }).then((e) => {
  31. let data = [{
  32. points: [],
  33. color: '#0BBB62',
  34. width: 5,
  35. arrowLine: true
  36. }]
  37. const startRouter = data[0];
  38. e.data.location.forEach((e) => {
  39. const address = e.split(',');
  40. startRouter.points.push({
  41. longitude: +address[0],
  42. latitude: +address[1]
  43. })
  44. })
  45. this.carRouteList = data;
  46. const item0 = startRouter.points[0];
  47. const item1 = startRouter.points[startRouter.points.length - 1];
  48. this.markers = [{
  49. id: 1,
  50. longitude: item0.longitude,
  51. latitude: item0.latitude,
  52. iconPath: '../static/stImg.png',
  53. width: 30,
  54. height: 30
  55. }, {
  56. id: 2,
  57. longitude: item1.longitude,
  58. latitude: item1.latitude,
  59. iconPath: '../static/endImg.png',
  60. width: 30,
  61. height: 30
  62. }]
  63. this.map = uni.createMapContext("map", this);
  64. this.map.includePoints({
  65. padding: [100, 20, 300, 20],
  66. points: startRouter.points
  67. })
  68. })
  69. }
  70. }
  71. };
  72. </script>
  73. <style>
  74. .map {
  75. height: 100vh;
  76. width: 750rpx;
  77. }
  78. </style>