mapImg2.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <template>
  2. <image :src="getImg()" style="width: 100%;height: 100%;border-radius: 15rpx;"></image>
  3. </template>
  4. <script>
  5. import config from '@/config'
  6. export default {
  7. props: {
  8. startPoint: {
  9. type: String,
  10. default: '125.324652,43.877198',
  11. },
  12. endPoint: {
  13. type: String,
  14. default: '125.325385,43.879278',
  15. },
  16. mtRoutePointList: {
  17. type: Array,
  18. default: () => {
  19. return [
  20. '116.477462800,39.994629400','116.475796400,39.999226200','116.486139200,40.002975600','116.487805600,39.998378800'
  21. ]
  22. },
  23. },
  24. pathData: {
  25. type: String,
  26. // default:''
  27. default: '125.324652,43.877198;125.32462532533114,43.87730358488015;125.324496,43.877003;125.324649,43.876538;125.325385,43.879278',
  28. }
  29. },
  30. data() {
  31. return {}
  32. },
  33. methods: {
  34. mercatorToWGS84(data) {
  35. let list = data.split(',');
  36. let lonlat = {
  37. lng: list[1],
  38. lat: list[0]
  39. };
  40. const coord = {
  41. lat: 0,
  42. lng: 0
  43. };
  44. const lat = lonlat.lat / 20037508.34 * 180;
  45. let lng = lonlat.lng / 20037508.34 * 180;
  46. lng = 180 / Math.PI * (2 * Math.atan(Math.exp(lng * Math.PI / 180)) - Math.PI / 2);
  47. coord.lat = lat;
  48. coord.lng = lng;
  49. return coord.lat + ',' + coord.lng
  50. },
  51. getImg() {
  52. let key = config.key;
  53. if (this.mtRoutePointList.length === 0) {
  54. return 'https://restapi.amap.com/v3/staticmap?location=126.04684,42.68497&zoom=6&key=' + key
  55. }
  56. // let starUrl = 'http://139.215.216.44:9010//fileupload/2022/09/27/star_20220927151629A097.png';
  57. // let endUrl = 'http://139.215.216.44:9010//fileupload/2022/09/27/end_20220927151745A098.png';
  58. let starUrl = 'http://139.215.216.44:9010//fileupload/2022/10/12/start_20221012172044A003.png';
  59. let endUrl = 'http://139.215.216.44:9010//fileupload/2022/10/12/end_20221012172112A004.png';
  60. let starMarkers = this.startPoint;
  61. let endMarkers = this.endPoint;
  62. let weight = '10'
  63. let color = '0x6495ED'
  64. let transparency = '0.2'
  65. let fillcolor = '0x6495ED'
  66. let fillTransparency = '0.4'
  67. let path = this.mtRoutePointList.join(';')
  68. let paths = weight + ',' + color + ',' + '' + ',' + '' + ',' + '' + ':' +
  69. '125.324652,43.877198;125.32462532533114,43.87730358488015;125.324496,43.877003;125.324649,43.876538;125.325385,43.879278';
  70. // if (this.pathData) {
  71. // let data = this.pathData + ';';
  72. // paths += '|' + '10' + ',' + color + ',' + '' + ',' + '' + ',' + '' + ':' + starMarkers + ';' + data +
  73. // endMarkers
  74. // }
  75. //计算中心点
  76. this.latitude = eval('43.877198' + '+' + '43.879278') / 2
  77. this.longitude = eval('125.324652' + '+' +'125.325385') / 2
  78. // 335/256
  79. let lcation=this.longitude+','+this.latitude;
  80. // let url='https://restapi.amap.com/v3/staticmap?size=335*256&location='+lcation+'&zoom=15&scale=2&markers=-1,' + starUrl +
  81. // ',0:' + starMarkers + '|-1,' + endUrl +
  82. // ',0:' + endMarkers +'&paths='+paths + '&key=' + key;
  83. let url='https://restapi.amap.com/v3/staticmap?size=335*256'+'&scale=2&markers=-1,' + starUrl +
  84. ',0:' + starMarkers + '|-1,' + endUrl +
  85. ',0:' + endMarkers +'&paths='+paths + '&key=' + key;
  86. return url;
  87. },
  88. goMap() {
  89. console.log('去地图展示页');
  90. }
  91. },
  92. }
  93. </script>
  94. <style>
  95. </style>