mapImg.vue 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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:'',
  11. },
  12. endPoint:{
  13. type:String,
  14. default:'',
  15. },
  16. mtRoutePointList:{
  17. type:Array,
  18. default:()=>{
  19. return []
  20. },
  21. },
  22. pathData:{
  23. type:String,
  24. default:'',
  25. }
  26. },
  27. data() {
  28. return {}
  29. },
  30. methods: {
  31. mercatorToWGS84(data){
  32. let list=data.split(',');
  33. let lonlat={lng:list[1],lat:list[0]};
  34. const coord = {
  35. lat:0,
  36. lng:0
  37. };
  38. const lat = lonlat.lat/20037508.34*180;
  39. let lng = lonlat.lng/20037508.34*180;
  40. lng = 180/Math.PI*(2*Math.atan(Math.exp(lng*Math.PI/180))-Math.PI/2);
  41. coord.lat = lat;
  42. coord.lng = lng;
  43. return coord.lat+','+coord.lng
  44. },
  45. getImg() {
  46. let key = config.key;
  47. if(this.mtRoutePointList.length===0)
  48. {
  49. return 'https://restapi.amap.com/v3/staticmap?location=126.04684,42.68497&zoom=6&key=' + key
  50. }
  51. // let starUrl = 'http://139.215.216.44:9010//fileupload/2022/09/27/star_20220927151629A097.png';
  52. // let endUrl = 'http://139.215.216.44:9010//fileupload/2022/09/27/end_20220927151745A098.png';
  53. let starUrl = 'http://139.215.216.44:9010//fileupload/2022/10/28/star_20221028160708A049.png';
  54. let endUrl = 'http://139.215.216.44:9010//fileupload/2022/10/28/end_20221028160807A050.png';
  55. let starMarkers = this.mercatorToWGS84(this.startPoint);
  56. let endMarkers = this.mercatorToWGS84(this.endPoint);
  57. console.log(starMarkers,'<-------------旧版起始点')
  58. console.log(endMarkers,'<------------旧版结束点')
  59. let weight = '2'
  60. let color = '0x6495ED'
  61. let transparency = '0.2'
  62. let fillcolor = '0x6495ED'
  63. let fillTransparency = '0.4'
  64. let path =this.mtRoutePointList.map(item=>this.mercatorToWGS84(item.pointCoordinate)).join(';')
  65. let paths=weight + ',' + color + ',' + transparency + ',' + fillcolor + ',' + fillTransparency + ':' + path ;
  66. if(this.pathData)
  67. {
  68. let data=this.pathData+';';
  69. paths+='|'+'10' + ',' + '0xFF0000' + ',' + '' + ',' + '' + ',' +'' + ':' +data
  70. }else{
  71. let data=this.pathData+';';
  72. paths+='|'+'10' + ',' + '0x76EE00' + ',' + '' + ',' + '' + ',' +'' + ':' +starMarkers+';'+endMarkers
  73. }
  74. console.log(this.pathData,'this.pathData');
  75. return 'https://restapi.amap.com/v3/staticmap?size=335*256&scale=2&markers=-1,' + starUrl +
  76. ',0:' + starMarkers + '|-1,' + endUrl +
  77. ',0:' + endMarkers + '&paths=' + paths + '&key=' + key
  78. // return 'https://restapi.amap.com/v3/staticmap?size=116*85&scale=2&markers=-1,' + starUrl +',0:' + starMarkers + '|-1,' + endUrl +',0:' + endMarkers + '&paths=' + paths + '&key=' + key
  79. // return 'https://restapi.amap.com/v3/staticmap?size=710*500&markers=-1,'+start+',0:'+A+'|-1,'+end+',0:'+B+'&paths=10,0x3662EC,1,,:'+points.join(';')+'&key='+this.GAODE_KEY;
  80. // return 'https://restapi.amap.com/v3/staticmap?scale=2&markers=large,0xFF0000,起:' + starMarkers +
  81. // '|large,0xFF0000,终:' + endMarkers + '&paths=' + paths + '&key=' + key
  82. },
  83. goMap(){
  84. console.log('去地图展示页');
  85. }
  86. },
  87. }
  88. </script>
  89. <style>
  90. </style>