weizhimap - 副本.nvue 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <template>
  2. <view>
  3. <map id="map" class="mapbody" :style="'height:'+height+'rpx;'" scale="18" show-location="true" :latitude="latitude" :longitude="longitude" :markers="marker">
  4. </map>
  5. </view>
  6. </template>
  7. <script>
  8. import api from "@/pages/api/api.js"
  9. export default {
  10. name:"weizhimap",
  11. props:{
  12. covers:'',
  13. height:0
  14. },
  15. data() {
  16. return {
  17. latitude:0,
  18. longitude:0,
  19. marker:'',
  20. markImage:'/static/images/dizhil@3x.png',
  21. };
  22. },
  23. onReady() {
  24. },
  25. watch:{
  26. covers(val){
  27. console.log('-----',val);
  28. this.markImage = val[0].iconPath;
  29. setTimeout(()=>{
  30. this.setLocat(val[0].latitude,val[0].longitude,1,3);
  31. },500)
  32. }
  33. },
  34. methods:{
  35. setLocat(latitude,longitude,f,t){
  36. this.latitude=latitude;
  37. this.longitude = longitude;
  38. this.marker=[{
  39. id:1,//控件id
  40. latitude: this.latitude,
  41. longitude: this.longitude,
  42. iconPath: this.markImage
  43. }];
  44. console.log(this.marker);
  45. return;
  46. var latlng = longitude+','+latitude;
  47. api('setLocat',{
  48. latlng:latlng,
  49. from:f,
  50. to:t
  51. },res=>{
  52. this.latitude=res.data.data.result[0].y;
  53. this.longitude = res.data.data.result[0].x;
  54. this.marker=[{
  55. latitude: this.latitude,
  56. longitude: this.longitude,
  57. iconPath: this.markImage
  58. }];
  59. },failc=>{
  60. //console.log('getadvertis----',failc)
  61. })
  62. },
  63. }
  64. }
  65. </script>
  66. <style>
  67. .mapbody{
  68. width: 750upx;
  69. height: 400rpx;
  70. }
  71. </style>