warnMap.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <template>
  2. <view class="container">
  3. <map
  4. id="myMap"
  5. :longitude="alarmInfo.longitude"
  6. :latitude="alarmInfo.latitude"
  7. scale="14"
  8. :markers="marker"
  9. @markertap="bindMarkertap"
  10. show-location
  11. style="width: 100%; height: 100vh"
  12. @tap="bindTapMap"
  13. ></map>
  14. </view>
  15. </template>
  16. <script>
  17. // pages/warmMap/warnMap.js
  18. const config = require('../../common/config.js');
  19. const common = require('../../common/common.js');
  20. var storage = require('../../common/storage.js');
  21. var QQMapWX = require('../../libs/qqmap-wx-jssdk.js');
  22. var qqmapsdk;
  23. export default {
  24. data() {
  25. return {
  26. alarmInfo: {
  27. longitude: '',
  28. latitude: ''
  29. },
  30. marker: []
  31. };
  32. }
  33. /**
  34. * 生命周期函数--监听页面加载
  35. */,
  36. onLoad: function (options) {
  37. uni.setNavigationBarTitle({
  38. title: this.$t('报警位置')
  39. });
  40. const index = options.index;
  41. this.readyAlarmInfo();
  42. },
  43. onShow() {
  44. uni.setNavigationBarTitle({
  45. title: this.$t('报警位置')
  46. });
  47. },
  48. methods: {
  49. readyAlarmInfo() {
  50. const me = this;
  51. // 实例化API核心类
  52. qqmapsdk = new QQMapWX({
  53. key: config.QQ_MAP_KEY
  54. });
  55. const thisAlarm = storage.getAlarmInfo();
  56. console.log(thisAlarm);
  57. qqmapsdk.reverseGeocoder({
  58. location: {
  59. latitude: thisAlarm.latitude,
  60. longitude: thisAlarm.longitude
  61. },
  62. success: function (res) {
  63. console.log(res);
  64. const formatted_addresses = res.result.formatted_addresses;
  65. const address = res.result.address; //+ formatted_addresses.recommend
  66. let ps = '';
  67. let tmp_addr = me.$t('地址')+': '+ + address;
  68. while (tmp_addr.length > 15) {
  69. ps += tmp_addr.substring(0, 15) + '\n';
  70. tmp_addr = tmp_addr.substring(15);
  71. }
  72. ps += tmp_addr;
  73. const content =
  74. me.$t('名称')+': ' +
  75. thisAlarm.macid +
  76. '\n'+me.$t('状态')+ ': ' +
  77. thisAlarm.alarm_desc +
  78. '\n'+me.$t('信号')+ ': ' +
  79. common.formatTime(thisAlarm.gps_time) +
  80. '\n'+me.$t('时间')+ ': ' +
  81. common.formatTime(thisAlarm.send_time) +
  82. '\n' +
  83. ps;
  84. me.setData({
  85. alarmInfo: thisAlarm,
  86. marker: [
  87. {
  88. id: 1,
  89. latitude: thisAlarm.latitude,
  90. longitude: thisAlarm.longitude,
  91. name: '',
  92. iconPath: 'https://qiniu.bms16.com/FkjUlfdPB1qabw-qNWCRQtiD-s55',
  93. width: 35,
  94. height: 35,
  95. callout: {
  96. content: content,
  97. padding: 10,
  98. borderRadius: 4,
  99. boxShadow: '4px 8px 16px 0 rgba(0,0,0,0.3)',
  100. display: 'ALWAYS'
  101. }
  102. }
  103. ]
  104. });
  105. }
  106. });
  107. console.log(this.alarmInfo);
  108. },
  109. bindMarkertap() {
  110. console.log('占位:函数 bindMarkertap 未声明');
  111. },
  112. bindTapMap() {
  113. console.log('占位:函数 bindTapMap 未声明');
  114. }
  115. }
  116. };
  117. </script>
  118. <style>
  119. @import './warnMap.css';
  120. </style>