map.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <template>
  2. <view>
  3. <map id="map" style="width: 100%; height: 100vh;" :layer-style='5' :show-location='true' :latitude="latitude"
  4. :longitude="longitude" :markers="marker" :scale="scale" @markertap="markertap"
  5. @callouttap='callouttap'></map>
  6. <view class="cover-box ddflex">
  7. <!-- <view style="justify-content: center;" class="ddflex fflex">
  8. <image class="cover-icon" src="../static/images/baojing.png"></image>
  9. <view>报警</view>
  10. </view> -->
  11. <view style="justify-content: center;" class="ddflex fflex" @click="daohang">
  12. <image class="cover-icon" src="../static/images/daohang.png"></image>
  13. <view>导航</view>
  14. </view>
  15. </view>
  16. <view class="dingwei ddflex" @click="toLocation">
  17. <image src="../static/images/dingwei.png"></image>
  18. </view>
  19. <view class="info-card">
  20. <view class="info-card-title">
  21. GPS
  22. </view>
  23. <view class="ddflex info-card-item">
  24. <view class="fflex">
  25. 设备名称: {{info.user_name}}
  26. </view>
  27. <view class="fflex info-card-item-right">
  28. 设备类型:{{info.product_type}}
  29. </view>
  30. </view>
  31. <view class="ddflex info-card-item">
  32. <view class="fflex">
  33. 设备编号: {{info.sim_id}}
  34. </view>
  35. </view>
  36. <view class="ddflex info-card-item">
  37. <view class="fflex">
  38. 设备定位时间: {{getTime(info.datetime)}}
  39. </view>
  40. </view>
  41. <view class="ddflex info-card-item">
  42. <view class="fflex">
  43. 地址:{{info.address?info.address:''}}
  44. </view>
  45. </view>
  46. </view>
  47. </view>
  48. </template>
  49. <script>
  50. import util from "../../utils/util.js";
  51. const app = getApp();
  52. const req = require("../../utils/request.js");
  53. // 引入SDK核心类
  54. var QQMapWX = require("../../utils/qqmap.js");
  55. export default {
  56. components: {},
  57. props: {},
  58. data() {
  59. return {
  60. id: null,
  61. map: null,
  62. info: {},
  63. latitude: 23.106574, //纬度
  64. longitude: 113.324587, //经度
  65. scale: 13, //缩放级别
  66. marker: [],
  67. }
  68. },
  69. async onLoad(options) {
  70. this.id = options.id
  71. // await this.getMap()
  72. this.toLocation()
  73. },
  74. onShow() {
  75. },
  76. onReady() {
  77. },
  78. mounted() {},
  79. computed: {},
  80. methods: {
  81. getMap() {
  82. return new Promise((r, j) => {
  83. req.getRequest('/admin/v2/battery/bmsLocation', {
  84. batteryId: this.id
  85. }, res => {
  86. // this.info = res
  87. for (let key in res.key) {
  88. let index = res.key[key]
  89. this.info[key] = res.records[0][index]
  90. }
  91. this.marker = [{
  92. id: 0,
  93. latitude: this.info.weidu, //纬度
  94. longitude: this.info.jingdu, //经度
  95. }]
  96. this.getAddress()
  97. uni.setNavigationBarTitle({
  98. title:this.info.user_name
  99. })
  100. r()
  101. })
  102. })
  103. },
  104. //地图点击事件
  105. markertap(e) {
  106. console.log("===你点击了标记点===", e)
  107. },
  108. //地图点击事件
  109. callouttap(e) {
  110. console.log('地图点击事件', e)
  111. },
  112. async toLocation() {
  113. await this.getMap()
  114. console.log('地图控件回到原位');
  115. req.getLocation((res) => {
  116. console.log('当前位置:', res);
  117. console.log('当前位置的经度:' + res.longitude);
  118. console.log('当前位置的纬度:' + res.latitude);
  119. this.longitude = res.longitude;
  120. this.latitude = res.latitude;
  121. this.map = uni.createMapContext("map", this);
  122. this.map.moveToLocation()
  123. })
  124. },
  125. getAddress() {
  126. QQMapWX.initMap();
  127. let location = {
  128. longitude: this.info.jingdu,
  129. latitude: this.info.weidu
  130. }
  131. QQMapWX.reverseGeocoder(location, data => {
  132. this.info.address = data.address
  133. console.log('解析后的地址地址数据:', data);
  134. });
  135. },
  136. getTime(time) {
  137. if (!time) return ''
  138. return util.formatTime(new Date(parseInt(time))).t1
  139. },
  140. daohang() {
  141. let plugin = requirePlugin('routePlan');
  142. let key = req.public.mapLBSKEY; //使用在腾讯位置服务申请的key
  143. let referer = '皮小店商家端'; //调用插件的app的名称
  144. // console.log("名称====" + referer);
  145. let endPoint = JSON.stringify({
  146. //终点
  147. 'name': this.info.user_name,
  148. 'latitude': this.info.weidu,
  149. 'longitude':this.info.jingdu,
  150. });
  151. uni.navigateTo({
  152. url: 'plugin://routePlan/index?key=' + key + '&referer=' + referer + '&endPoint=' + endPoint
  153. });
  154. },
  155. },
  156. mounted() {
  157. },
  158. onPageScroll: function(e) {}
  159. }
  160. </script>
  161. <style>
  162. @import "./map.css";
  163. </style>