map.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <template>
  2. <view class="safety" id="container">
  3. <map style="width: 100%; height: 75%;" :latitude="latitude" :longitude="longitude" scale="10"  
  4. :markers="markers" :show-location="true" @markertap="markertap">
  5. </map>
  6. <view class="model">
  7. <view class="info">
  8. <image class="img" :src="image(model.shopsPic)"></image>
  9. <view class="info-data">
  10. <view class="info-title">名称:{{model.shopsName ? model.shopsName : '-'}}</view>
  11. <view class="info-text">电话:{{model.shopsTel ? model.shopsTel : '-'}}</view>
  12. <view class="info-shopsIntroduce">地址:{{model.shopsAddress ? model.shopsAddress : '-'}}</view>
  13. <view class="info-shopsIntroduce">简介:{{model.shopsIntroduce ? model.shopsIntroduce : '-'}}</view>
  14. </view>
  15. </view>
  16. </view>
  17. </view>
  18. </template>
  19. <script>
  20. import amap from '@/lib/amap-wx.130.js'
  21. import server from "@/api/index";
  22. import http from '@/common/http.js'
  23. export default {
  24. data() {
  25. return {
  26. pageNo: 1,
  27. pageSize: 10,
  28. id: 0,
  29. clickable: true,
  30. latitude: 43.616996,
  31. longitude: 125.323643,
  32. mapKey: '1dc63f21c12985e199a715faf4c02f36',
  33. markers: [],
  34. list: [],
  35. model:{
  36. shopsName: '',
  37. shopsTel: '',
  38. shopsIntroduce: '',
  39. shopsPic: '',
  40. shopsAddress: ''
  41. }
  42. }
  43. },
  44. onLoad() {
  45. let that = this;
  46. this.amapPlugin = new amap.AMapWX({
  47. key: this.mapKey //该key 是在高德中申请的微信小程序key
  48. });
  49. this.amapPlugin.getRegeo({
  50. type: 'gcj02', //map 组件使用的经纬度是国测局坐标, type 为 gcj02
  51. success: function(res) {
  52. const latitude = res[0].latitude;
  53. const longitude = res[0].longitude;
  54. that.longitude = longitude;
  55. that.latitude = latitude;
  56. console.log(that.longitude, that.latitude)
  57. that.mapInfo = res[0];
  58. },
  59. fail: (res) => {
  60. console.log(JSON.stringify(res));
  61. }
  62. });
  63. this.getFn()
  64. },
  65. methods: {
  66. image(e) {
  67. return http.webUrl + e
  68. },
  69. getFn() {
  70. server.getYongJun().then(res =>{
  71. res.forEach((item, index) => {
  72. this.markers.push({
  73. id: item.shopsId,
  74. latitude: Number(item.shopsLat),
  75. longitude: Number(item.shopsLng),
  76. iconPath: '../../../static/dian.png',
  77. width: 24,
  78. height: 24,
  79. clickable: true,
  80. shopsName: item.shopsName,
  81. shopsTel: item.shopsTel,
  82. shopsIntroduce: item.shopsIntroduce,
  83. shopsPic: item.shopsPic,
  84. shopsAddress: item.shopsAddress
  85. })
  86. })
  87. if (this.markers[0]) {
  88. this.model.shopsName = this.markers[0].shopsName
  89. this.model.shopsTel = this.markers[0].shopsTel
  90. this.model.shopsIntroduce = this.markers[0].shopsIntroduce
  91. this.model.shopsPic = this.markers[0].shopsPic
  92. this.model.shopsAddress = this.markers[0].shopsAddress
  93. }
  94. })
  95. },
  96. markertap(e) {
  97. this.markers.forEach(item => {
  98. if (e.detail.markerId === item.id) {
  99. this.model.shopsName = item.shopsName
  100. this.model.shopsTel = item.shopsTel
  101. this.model.shopsIntroduce = item.shopsIntroduce
  102. this.model.shopsPic = item.shopsPic
  103. this.model.shopsAddress = item.shopsAddress
  104. }
  105. })
  106. }
  107. }
  108. }
  109. </script>
  110. <style lang="scss" scoped>
  111. .safety {
  112. position: absolute;
  113. width: 100%;
  114. height: 100%;
  115. box-sizing: border-box;
  116. }
  117. .model {
  118. width: 100%;
  119. height: 25%;
  120. position: absolute;
  121. left: 0upx;
  122. bottom: 0upx;
  123. background-color: #FFFFFF;
  124. z-index: 9999;
  125. padding: 0rpx 30rpx;
  126. .info {
  127. width: 100%;
  128. height: 100%;
  129. display: flex;
  130. flex-direction: row;
  131. align-items: center;
  132. justify-content: space-around;
  133. .img{
  134. width: 180rpx;
  135. height: 180rpx;
  136. }
  137. .info-data{
  138. width: calc(100% - 180rpx);
  139. padding-left: 20upx;
  140. }
  141. .info-title{
  142. }
  143. .info-text{
  144. padding-top: 10upx;
  145. }
  146. .info-shopsIntroduce{
  147. padding-top: 10upx;
  148. line-height: 40rpx;
  149. height: auto;
  150. overflow: visible;
  151. }
  152. }
  153. }
  154. </style>