mapView.vue 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <template>
  2. <view>
  3. <view class="">
  4. <view class="">
  5. <map id="map" class="mapbody" :style="'height:'+mapHeight+'rpx;'" :markers="covers" @regionchange="regionChange">
  6. </map>
  7. </view>
  8. </view>
  9. </view>
  10. </template>
  11. <script>
  12. export default {
  13. name:"mapView",
  14. props: {
  15. pcovers:'',
  16. },
  17. data() {
  18. return {
  19. mapHeight:0,
  20. mapready:false,
  21. covers:[],
  22. includePoints:[],
  23. dcovers: [{
  24. latitude: 39.909,
  25. longitude: 116.39742,
  26. iconPath: '/static/images/dizhil@3x.png'
  27. }, {
  28. latitude: 39.90,
  29. longitude: 116.39,
  30. iconPath: '/static/images/dizhil@3x.png'
  31. }]
  32. };
  33. },
  34. created() {
  35. var info = uni.getSystemInfoSync();
  36. console.log(info);
  37. this.mapHeight=info.windowHeight/2;
  38. this.mapContext = uni.createMapContext("map",this);
  39. console.log("1----------------------");
  40. },
  41. watch: {
  42. pcovers(val){
  43. this.covers = this.pcovers;
  44. let include = [];
  45. for(var i=0;i<this.covers.length;i++){
  46. let poi = {
  47. longitude: this.covers[i].longitude,
  48. latitude: this.covers[i].latitude
  49. }
  50. include.push(poi);
  51. }
  52. this.includePoints = include;
  53. this.mapContext.includePoints({
  54. padding:[180,180,180,180],
  55. include
  56. })
  57. console.log('includePoints',this.includePoints);
  58. }
  59. },
  60. methods: {
  61. regionChange(){
  62. var that = this;
  63. if(!this.mapready){
  64. return;
  65. }
  66. this.mapContext.getCenterLocation({
  67. success: res => {
  68. console.log('getCenterLocation');
  69. },
  70. fail: res => {
  71. console.log("getCenterLocation11")
  72. }
  73. })
  74. },
  75. },
  76. }
  77. </script>
  78. <style>
  79. .mapbody{
  80. width: 100%;
  81. }
  82. </style>