detailMap.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. <template>
  2. <view>
  3. <map style="width: 100%; height: 100vh;" :show-location='true' ref="map" id="map" :latitude="dataObj.latitude"
  4. :longitude="dataObj.longitude" :markers="marker" :scale="scale" :polyline="polyline" @callouttap='toDL(dataObj)'>
  5. <cover-view slot="callout">
  6. <block v-for="(item,index) in marker" :key="index">
  7. <cover-view class="customCallout" :marker-id="item.id">
  8. <cover-view class="content row1" style="margin-top: 0;">
  9. {{dataObj.shopNames}}
  10. </cover-view>
  11. <cover-view class="content row2">
  12. 距离{{(info.distance/1000).toFixed(1)}}公里
  13. </cover-view>
  14. <cover-view class="content row3">
  15. 驾车约{{(info.duration/60).toFixed(0)}}分钟
  16. </cover-view>
  17. <cover-view class="dh" >
  18. 导航
  19. </cover-view>
  20. </cover-view>
  21. </block>
  22. </cover-view>
  23. <!-- <view class="to-here">
  24. <image src="../../static/image/to.png" mode="widthFix" style="width: 36rpx;">
  25. </image>
  26. </view> -->
  27. </map>
  28. </view>
  29. </template>
  30. <script>
  31. var that;
  32. var GDMapWX = require('@/js_sdk/js-amap/amap-wx.130.js');
  33. import {
  34. authorizedLocation
  35. } from '@/util/util.js'
  36. export default {
  37. data() {
  38. return {
  39. polyline: [],
  40. dataObj: {},
  41. latitude: '', //纬度
  42. longitude: '', //经度
  43. marker: [],
  44. scale: 14, //缩放级别
  45. info: {},
  46. };
  47. },
  48. onLoad(options) {
  49. that = this
  50. this.isdingwei()
  51. this.dataObj = JSON.parse(options.val)
  52. console.log(this.dataObj)
  53. },
  54. methods: {
  55. getInfo(_origin, _destination) {
  56. return new Promise((resolve, reject) => {
  57. var amapPluginInstance = new GDMapWX.AMapWX({
  58. key: '6bafe91754a563ff2b7c02542c1ef4e8'
  59. });
  60. amapPluginInstance.getDrivingRoute({
  61. origin: _origin,
  62. destination: _destination,
  63. success: function(res) {
  64. console.log(res)
  65. resolve(res)
  66. // let _content = that.dataObj.shopNames+'\n'+"距离约"+1+'公里'+'\n'+'驾车约'+4+"分钟"
  67. // console.log(_content)
  68. // that.marker[0].callout = { //气泡窗口
  69. // content: that.dataObj.shopNames+'\n'+"距离约"+1+'公里'+'\n'+'驾车约'+4+"分钟", //文本
  70. // // color: '#ffffff',
  71. // fontSize: 14,
  72. // borderRadius: 15,
  73. // padding: '10',
  74. // bgColor: '#fff',
  75. // display: 'ALWAYS', //常显
  76. // }
  77. //成功回调
  78. },
  79. fail: function(info) {
  80. //失败回调
  81. console.log(info)
  82. }
  83. })
  84. })
  85. },
  86. toDL(val) {
  87. console.log(val)
  88. let _latitude = val.location.split(",")[0]
  89. let _longitude = val.location.split(",")[1]
  90. uni.openLocation({
  91. latitude: Number(_latitude),
  92. longitude: Number(_longitude),
  93. success: function() {
  94. console.log('success');
  95. },
  96. fail(fail) {
  97. console.log(fail)
  98. },
  99. });
  100. },
  101. isdingwei() {
  102. authorizedLocation().then(async res => {
  103. let _obj = {}
  104. if (res == '取消授权') {
  105. } else {
  106. _obj = {
  107. latitude: res.latitude,
  108. longitude: res.longitude
  109. }
  110. }
  111. this.longitude = _obj.longitude
  112. this.latitude = _obj.latitude
  113. let _origin = this.longitude + ',' + this.latitude
  114. let _destination = this.dataObj.location.split(",")[1] + "," + this.dataObj.location.split(
  115. ",")[0]
  116. let _info = await this.getInfo(_origin, _destination)
  117. this.info = _info.paths[0]
  118. this.marker[0] = {
  119. id: Number(this.dataObj.id),
  120. iconPath: '/static/image/food/location.png', //显示的图标
  121. latitude: Number(this.dataObj.latitude),
  122. longitude: Number(this.dataObj.longitude),
  123. width: 20,
  124. height: 20,
  125. customCallout: {
  126. // content: that.dataObj.shopNames + '\n' + "距离约" + 1 + '公里' + '\n' + '驾车约' + 4 +
  127. // "分钟", //文本
  128. // // color: '#ffffff',
  129. // fontSize: 14,
  130. // borderRadius: 15,
  131. // padding: '10',
  132. // bgColor: '#fff',
  133. display: 'ALWAYS', //常显
  134. }
  135. }
  136. let _polylineList = []
  137. for (let i = 0; i < this.info.steps.length; i++) {
  138. let _polyline = this.info.steps[i].polyline.split(";")
  139. for (let j = 0; j < _polyline.length; j++) {
  140. let _obj = {
  141. latitude: _polyline[j].split(",")[1],
  142. longitude: _polyline[j].split(",")[0]
  143. }
  144. _polylineList.push(_obj)
  145. }
  146. }
  147. this.polyline = [{
  148. points: _polylineList,
  149. color: "#31c27c",
  150. width: 5,
  151. arrowLine: true,
  152. // borderWidth: 2 //线的边框宽度,还有很多参数,请看文档
  153. }]
  154. this.$forceUpdate()
  155. })
  156. },
  157. }
  158. }
  159. </script>
  160. <style lang="scss" scoped>
  161. .customCallout {
  162. width: 400rpx;
  163. position: relative;
  164. background: #fff;
  165. border-radius: 20rpx;
  166. padding: 20rpx;
  167. .content {
  168. margin-top: 10rpx;
  169. }
  170. .row1 {
  171. font-weight: 700;
  172. font-size: 32rpx;
  173. }
  174. .row2,
  175. .row3 {
  176. font-size: 24rpx;
  177. }
  178. .dh {
  179. font-size: 24rpx;
  180. background: #eaad1a;
  181. border-radius: 10rpx;
  182. padding: 10rpx 20rpx;
  183. display: flex;
  184. justify-content: center;
  185. align-items: center;
  186. position: absolute;
  187. right: 20rpx;
  188. bottom: 20rpx;
  189. color: #fff;
  190. z-index: 9999;
  191. }
  192. }
  193. </style>