map.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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}}
  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. iconPath: '', //显示的图标
  96. rotate: 0, // 旋转度数
  97. width: 20, //宽
  98. height: 30, //高
  99. // title:'我在这里',//标注点名
  100. alpha: 0.5, //透明度
  101. callout: { //自定义标记点上方的气泡窗口 点击有效
  102. content: this.info.user_name, //文本
  103. color: '#ffffff', //文字颜色
  104. fontSize: 14, //文本大小
  105. borderRadius: 15, //边框圆角
  106. borderWidth: '10',
  107. bgColor: '#e51860', //背景颜色
  108. display: 'ALWAYS', //常显
  109. }
  110. }]
  111. this.getAddress()
  112. uni.setNavigationBarTitle({
  113. title:this.info.user_name
  114. })
  115. r()
  116. })
  117. })
  118. },
  119. //地图点击事件
  120. markertap(e) {
  121. console.log("===你点击了标记点===", e)
  122. },
  123. //地图点击事件
  124. callouttap(e) {
  125. console.log('地图点击事件', e)
  126. },
  127. toLocation() {
  128. console.log('地图控件回到原位');
  129. req.getLocation((res) => {
  130. console.log('当前位置:', res);
  131. console.log('当前位置的经度:' + res.longitude);
  132. console.log('当前位置的纬度:' + res.latitude);
  133. this.longitude = res.longitude;
  134. this.latitude = res.latitude;
  135. this.map = uni.createMapContext("map", this);
  136. this.map.moveToLocation()
  137. })
  138. },
  139. getAddress() {
  140. QQMapWX.initMap();
  141. this.location = {
  142. longitude: this.info.jingdu,
  143. latitude: this.info.weidu
  144. }
  145. QQMapWX.reverseGeocoder(location, data => {
  146. this.info.address = data.address
  147. console.log('解析后的地址地址数据:', data);
  148. });
  149. },
  150. getTime(time) {
  151. if (!time) return ''
  152. return util.formatTime(new Date(parseInt(time))).t1
  153. },
  154. daohang() {
  155. let plugin = requirePlugin('routePlan');
  156. let key = req.public.mapLBSKEY; //使用在腾讯位置服务申请的key
  157. let referer = '皮小店商家端'; //调用插件的app的名称
  158. // console.log("名称====" + referer);
  159. let endPoint = JSON.stringify({
  160. //终点
  161. 'name': this.info.user_name,
  162. 'latitude': this.info.weidu,
  163. 'longitude':this.info.jingdu,
  164. });
  165. uni.navigateTo({
  166. url: 'plugin://routePlan/index?key=' + key + '&referer=' + referer + '&endPoint=' + endPoint
  167. });
  168. },
  169. },
  170. mounted() {
  171. },
  172. onPageScroll: function(e) {}
  173. }
  174. </script>
  175. <style>
  176. @import "./map.css";
  177. </style>