mapView.vue 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <template>
  2. <view>
  3. <view class="">
  4. <view class="">
  5. <map id="map" class="mapbody" :style="'height:'+mapHeight+'rpx;'" :latitude="latitude" :longitude="longitude" :covers="covers" @regionchange="regionChange">
  6. </map>
  7. </view>
  8. </view>
  9. </view>
  10. </template>
  11. <script>
  12. export default {
  13. name:"mapView",
  14. data() {
  15. return {
  16. covers: [{
  17. latitude: 39.909,
  18. longitude: 116.39742,
  19. iconPath: '/static/images/dizhil@3x.png'
  20. }],
  21. controls:[],
  22. latitude: 39.909,
  23. longitude: 116.39742,
  24. mapHeight:0,
  25. mapready:false
  26. };
  27. },
  28. created() {
  29. var info = uni.getSystemInfoSync();
  30. console.log(info);
  31. this.mapHeight=info.windowHeight;
  32. this.listHight=info.windowHeight;
  33. this.left = 750/4;
  34. this.top = this.mapHeight/6;
  35. this.mapContext = uni.createMapContext("map",this);
  36. },
  37. onReady() {
  38. },
  39. methods: {
  40. regionChange(){
  41. var that = this;
  42. if(!this.mapready){
  43. return;
  44. }
  45. this.controls=[{//在地图上显示控件,控件不随着地图移动
  46. id:1,//控件id
  47. iconPath:'/static/imags/datouzhenl.png',//显示的图标
  48. position:{//控件在地图的位置
  49. left:this.left-6,
  50. top:this.top-10,
  51. width:28,
  52. height:35
  53. },
  54. }];
  55. this.mapContext.getCenterLocation({
  56. success: res => {
  57. console.log('getCenterLocation');
  58. },
  59. fail: res => {
  60. uni.showModal({
  61. content: that.$t('api.dingweishibai'),
  62. showCancel: false
  63. })
  64. }
  65. })
  66. },
  67. },
  68. }
  69. </script>
  70. <style>
  71. .mapbody{
  72. width: 100%;
  73. }
  74. </style>