routeDetail.vue 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <template>
  2. <map class="map" id="map" ref="map1" :polyline='carRouteList' :markers="markers"></map>
  3. </template>
  4. <script>
  5. import {
  6. record_info
  7. } from '@/api/user.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. record_info({
  28. id: this.id
  29. }).then((e) => {
  30. let data = [{
  31. points: [],
  32. color: '#0BBB62',
  33. width: 5,
  34. arrowLine: true
  35. }]
  36. console.log(data[0]);
  37. e.data.location.forEach((e) => {
  38. const address = e.split(',');
  39. data[0].points.push({
  40. longitude: +address[0],
  41. latitude: +address[1]
  42. })
  43. })
  44. this.carRouteList = data;
  45. const item0 = data[0].points[0];
  46. const item1 = data[0].points[data[0].points.length-1];
  47. this.markers = [
  48. {
  49. id:1,
  50. longitude:item0.longitude,
  51. latitude: item0.latitude,
  52. iconPath:'../../static/image/stImg.png',
  53. width:30,
  54. height:30
  55. },{
  56. id:2,
  57. longitude:item1.longitude,
  58. latitude: item1.latitude,
  59. iconPath:'../../static/image/endImg.png',
  60. width:30,
  61. height:30
  62. }
  63. ]
  64. this.map = uni.createMapContext("map", this);
  65. this.map.includePoints({
  66. padding: [100, 20, 300, 20],
  67. points: data[0].points
  68. })
  69. })
  70. }
  71. }
  72. };
  73. </script>
  74. <style>
  75. page {
  76. height: 100%;
  77. }
  78. .map {
  79. height: 100%;
  80. width: 750rpx;
  81. }
  82. </style>