mapVisualization.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <template>
  2. <view>
  3. <cu-custom bgColor="bg-blue" :isBack="true">
  4. <block slot="backText">返回</block>
  5. <block slot="content"> 地图可视化</block>
  6. </cu-custom>
  7. <!-- <view>
  8. <web-view src="/hybrid/html/map.html" @onPostMessage="handlePostMessage" @message="handlePostMessage"
  9. :webview-styles="webviewStyles">
  10. </web-view>
  11. </view> -->
  12. <!--绑定点击事件-->
  13. <!--地图容器-->
  14. <map id="myMap" :markers="markers" style="width: 100%;" :style="'height:' + windowHeight + 'px;'"
  15. :longitude="m_longitude" :latitude="m_latitude" scale='15' @markertap="markertap">
  16. </map>
  17. </view>
  18. </template>
  19. <script>
  20. // 引入SDK核心类
  21. var QQMapWX = require('../../libs/qqmap-wx-jssdk.js');
  22. // 实例化API核心类
  23. var qqmapsdk = new QQMapWX({
  24. key: '4OWBZ-KZICJ-PCPFK-XWKUM-FLKFJ-C5FI2' // 必填
  25. });
  26. import mapVisualizationService from '@/api/map/mapVisualization'
  27. export default {
  28. data() {
  29. return {
  30. windowHeight: uni.getSystemInfoSync().windowHeight - 45, //屏幕高度
  31. markers: [],
  32. m_longitude: 120.139726,
  33. m_latitude: 33.345562,
  34. currentWebview: '',
  35. webviewStyles: { // web-view样式
  36. width: "100%",
  37. height: "100%",
  38. top: 90,
  39. },
  40. }
  41. },
  42. components: {},
  43. onReady() {
  44. },
  45. mounted() {
  46. this.getBuildingList()
  47. },
  48. methods: {
  49. markertap(e) {
  50. // 获取点击的marker的customData
  51. let markerId = e.detail.markerId;
  52. let selectedMarker = this.markers.find(marker => marker.id === markerId);
  53. let customData = selectedMarker.customData
  54. uni.navigateTo({
  55. url: '/pages/map/companyShow?buildingId=' + customData.buildingId +
  56. '&buildingName=' + customData.buildingName
  57. });
  58. },
  59. convert2TecentMap(lng, lat) {
  60. if (lng == '' && lat == '') {
  61. return {
  62. lng: '',
  63. lat: ''
  64. }
  65. }
  66. var x_pi = 3.14159265358979324 * 3000.0 / 180.0
  67. var x = lng - 0.0065
  68. var y = lat - 0.006
  69. var z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * x_pi)
  70. var theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * x_pi)
  71. var qqlng = z * Math.cos(theta)
  72. var qqlat = z * Math.sin(theta)
  73. return {
  74. lng: qqlng,
  75. lat: qqlat
  76. }
  77. },
  78. //获取楼宇信息
  79. getBuildingList() {
  80. uni.showLoading()
  81. mapVisualizationService.getBuildingList().then(({
  82. data
  83. }) => {
  84. if (data != null && data.length > 0) {
  85. let mar_arr = []
  86. data.forEach((item, index) => {
  87. //百度坐标转腾讯
  88. let convertPoint = this.convert2TecentMap(item.building_longitude, item.building_latitude)
  89. mar_arr.push({
  90. id: index,
  91. title: item.building_name,
  92. longitude: convertPoint.lng,
  93. latitude: convertPoint.lat,
  94. iconPath: '/static/img/building_ph.png',
  95. width: 35,
  96. callout: {
  97. content: item.building_name,
  98. display: 'ALWAYS'
  99. },
  100. customData: {
  101. buildingId: item.building_id,
  102. buildingName: item.building_name
  103. }
  104. })
  105. })
  106. this.markers = mar_arr
  107. this.getCenterPoint(this.markers)
  108. }
  109. uni.hideLoading()
  110. }).catch((e) => {
  111. uni.hideLoading()
  112. })
  113. },
  114. //计算所有点的中心点
  115. getCenterPoint(markers) {
  116. let minLat = 90, maxLat = -90, minLng = 180, maxLng = -180;
  117. markers.forEach(marker => {
  118. if (marker.latitude < minLat) minLat = marker.latitude;
  119. if (marker.latitude > maxLat) maxLat = marker.latitude;
  120. if (marker.longitude < minLng) minLng = marker.longitude;
  121. if (marker.longitude > maxLng) maxLng = marker.longitude;
  122. });
  123. this.m_latitude = (minLat + maxLat) / 2
  124. this.m_longitude = (minLng + maxLng) / 2
  125. },
  126. //获取天地图参数
  127. handlePostMessage(data) {
  128. console.log('天地图发来的数据', data.detail.data[0].buildingId)
  129. //企业数量检测
  130. // uni.showLoading()
  131. // mapVisualizationService.getCompanyNum(data.detail.data[0].buildingId).then(({
  132. // data
  133. // }) => {
  134. // if (data != null && data > 0) {
  135. // }
  136. // uni.hideLoading()
  137. // }).catch((e) => {
  138. // uni.hideLoading()
  139. // })
  140. uni.navigateTo({
  141. url: '/pages/map/companyShow?buildingId=' + data.detail.data[0].buildingId +
  142. '&buildingName=' + data.detail.data[0].buildingName
  143. });
  144. },
  145. }
  146. }
  147. </script>
  148. <style scoped lang="scss">
  149. </style>