mapComponent.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <template>
  2. <view class="box">
  3. <map
  4. id="map"
  5. @markertap="markertap"
  6. :enable-overlooking="true"
  7. enable-3D="true"
  8. :scale="scale"
  9. :style="{ width: '100%', height: height + 'rpx' }"
  10. :markers="markers"
  11. :latitude="latitudeAndLongitude.latitude"
  12. :longitude="latitudeAndLongitude.longitude"
  13. :show-location="latitudeAndLongitude.anchorPoint"
  14. ></map>
  15. </view>
  16. <!-- :show-location="true"定位点 -->
  17. </template>
  18. <script>
  19. export default {
  20. name: 'mapComponent',
  21. props: {
  22. height: {
  23. type: [Number, String],
  24. default: 360
  25. },
  26. latitudeAndLongitude: {
  27. type: Object,
  28. default: {}
  29. },
  30. introduceShow: {
  31. type: Boolean,
  32. default: ''
  33. },
  34. markers: {
  35. type: Array,
  36. default: []
  37. }
  38. },
  39. data() {
  40. return {
  41. latitude: 24.531,
  42. longitude: 118.1918,
  43. scale: 12 //缩放级别,
  44. };
  45. },
  46. mounted() {
  47. // console.log(this.markers, '子组件地图');
  48. },
  49. methods: {
  50. // 点击标记点时触发
  51. markertap(e) {
  52. if (this.introduceShow == false) {
  53. this.$emit('subComponent', true, e.markerId);
  54. // console.log(e, '标记点11');
  55. } else {
  56. // console.log(e, '标记点222');
  57. uni.navigateTo({
  58. url: `/index_fenbao/GuanLi/XiangQing?id=${e.markerId}`
  59. });
  60. }
  61. },
  62. // 获取位置
  63. vicinityBtn() {
  64. const that = this;
  65. uni.getLocation({
  66. type: 'gcj02 ',
  67. geocode: true,
  68. success: function (res) {
  69. // console.log(res, 'resres');
  70. // console.log(that.latitudeAndLongitude, 'this.latitudeAndLongitude');
  71. that.latitudeAndLongitude.longitude = res.longitude;
  72. that.latitudeAndLongitude.latitude = res.latitude;
  73. that.latitudeAndLongitude.anchorPoint = true;
  74. that.$common.successToShow('定位成功');
  75. that.regionTab();
  76. }
  77. });
  78. },
  79. // 定位点
  80. regionTab() {
  81. uni.createMapContext('map', this).moveToLocation({
  82. longitude: this.latitudeAndLongitude.longitude,
  83. latitude: this.latitudeAndLongitude.latitude
  84. });
  85. }
  86. }
  87. };
  88. </script>
  89. <style>
  90. .map_box {
  91. width: 625rpx;
  92. height: 320rpx;
  93. margin: auto;
  94. margin-top: 40rpx;
  95. overflow: hidden;
  96. }
  97. </style>