mapindex.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. <template>
  2. <view class="content">
  3. <!-- <button type="primary" @click="location">位置定位</button> -->
  4. <map id="map" class="map" :show-location="true" :latitude="latitude" :longitude="longitude" :enable-3D="true" @markertap="location":markers="markers">
  5. <cover-view class="img-map2">
  6. <cover-image style="width: 100rpx;height: 100rpx;" src="https://zdsz.obs.cn-south-1.myhuaweicloud.com/file/ef712ef2a0bf48f48bf56ea655e8359c.png" @click="clickcontrol"></cover-image>
  7. 调压箱
  8. </cover-view>
  9. <cover-view class="img-map3">
  10. <cover-image style="width: 100rpx;height: 100rpx;" src="https://zdsz.obs.cn-south-1.myhuaweicloud.com/file/6ba09f14edcc49b5bd2ff0f6dee4bdb9.png" @click="getvalveWellPositionlist"></cover-image>
  11. <!-- <u-popup v-model="show" mode="bottom" height='600rpx'>
  12. <view>出淤泥而不染,濯清涟而不妖</view>
  13. </u-popup> -->
  14. 阀井
  15. </cover-view>
  16. </map>
  17. </view>
  18. </template>
  19. <script>
  20. const img = 'https://zdsz.obs.cn-south-1.myhuaweicloud.com/file/6ba09f14edcc49b5bd2ff0f6dee4bdb9.png';
  21. import service from '@/api/index.js'
  22. export default {
  23. data() {
  24. return {
  25. latitude: 43.771703,
  26. longitude: 125.367899,
  27. _mapContext:null,
  28. show:true,
  29. positions:[],
  30. markers:[]
  31. }
  32. },
  33. onReady() {
  34. this.getconter()
  35. this._mapContext = uni.createMapContext("map", this);
  36. // 仅调用初始化,才会触发 on.("markerClusterCreate", (e) => {})
  37. this._mapContext.initMarkerCluster({
  38. enableDefaultStyle: false,
  39. zoomOnClick: true,
  40. gridSize: 10,
  41. complete(res) {
  42. console.log('initMarkerCluster', res)
  43. }
  44. });
  45. this._mapContext.on("markerClusterCreate", (e) => {
  46. console.log("markerClusterCreate", e);
  47. });
  48. },
  49. onShow() {
  50. this.getconter()
  51. setTimeout(()=>{
  52. this.getvalveWellPositionlist()
  53. },100)
  54. },
  55. methods: {
  56. //右下角定位按钮的点击事件
  57. clickcontrol(){
  58. this.show=true
  59. console.log(this.latitude,this.longitude)
  60. uni.authorize({
  61. scope: 'scope.userLocation',
  62. success() {
  63. uni.getLocation({
  64. type: 'gcj02',
  65. altitude: true, //高精度定位
  66. //定位成功,更新定位结果
  67. success: function(res) {
  68. console.log(res)
  69. that.latitude=res.latitude;
  70. that.longitude=res.longitude;
  71. that.covers[0].latitude=res.latitude;
  72. that.covers[0].longitude=res.longitude;
  73. }
  74. });
  75. }
  76. });
  77. this._mapContext.moveToLocation({ //moveToLocation将地图中心移动到当前定位点,需要配合map组件的show-location使用
  78. latitude: this.latitude,
  79. longitude: this.longitude
  80. });
  81. },
  82. getvalveWellPositionlist()
  83. {
  84. service.getvalveWellPositionlist({}).then(res => {
  85. console.log('getwarningPileList', res)
  86. if (res.length == 0) {
  87. this.$UTILS.showPrompt('暂无项目!')
  88. }
  89. this.positions = res;
  90. setTimeout(()=>{this.addMarkers()},1000)
  91. })
  92. },
  93. addMarkers() {
  94. const positions = [
  95. {
  96. latitude: 43.771703,
  97. longitude: 125.376804
  98. },{
  99. latitude: "43.780458",
  100. longitude: "125.367899"
  101. }
  102. ]
  103. this.markers = []
  104. this.positions.forEach((p, i) => {
  105. this.markers.push(
  106. Object.assign({},{
  107. id: p.id,
  108. iconPath: img,
  109. width: 45,
  110. height: 50,
  111. latitude:parseFloat(p.latitude),
  112. longitude:parseFloat(p.longitude),
  113. joinCluster: true, // 指定了该参数才会参与聚合
  114. // label: {
  115. // width: 50,
  116. // height: 30,
  117. // borderWidth: 1,
  118. // borderRadius: 10,
  119. // bgColor: '#ffffff',
  120. // content: p.valveWellName,
  121. // latitude:p.latitude,
  122. // longitude:p.longitude
  123. // },
  124. callout:{
  125. borderWidth: 1,
  126. borderRadius: 10,
  127. bgColor: '#ffffff',
  128. fontSize:20,
  129. padding:3,
  130. content: p.valveWellName,
  131. display:'ALWAYS'
  132. }
  133. })
  134. )
  135. })
  136. console.log(this.markers)
  137. setTimeout(()=>{
  138. this._mapContext.addMarkers({
  139. markers:this.markers,
  140. clear: true,
  141. complete(res) {
  142. console.log('addMarkers', res)
  143. }
  144. })
  145. },100)
  146. },
  147. //位置定位
  148. location(e){
  149. service.getvalveWellPosition(e.markerId).then(res => {
  150. console.log('getwarningPileList', res)
  151. console.log(e)
  152. uni.openLocation({
  153. latitude: parseFloat( res.latitude),
  154. longitude: parseFloat(res.longitude),
  155. success: function (res) {
  156. console.log('打开系统位置地图成功')
  157. },
  158. fail: function (error) {
  159. console.log(error)
  160. }
  161. })
  162. // this.positions = res;
  163. })
  164. },
  165. clickMarker(e)
  166. {
  167. console.log("点击了",e)
  168. this._mapContext.removeMarkers()
  169. },
  170. getconter()
  171. {
  172. var that = this;
  173. // 获取经纬度
  174. uni.authorize({
  175. scope: 'scope.userLocation',
  176. success() {
  177. uni.getLocation({
  178. type: 'gcj02',
  179. altitude: true, //高精度定位
  180. //定位成功,更新定位结果
  181. success: function(res) {
  182. console.log(res)
  183. that.latitude=res.latitude;
  184. that.longitude=res.longitude;
  185. that.latitude=res.latitude;
  186. that.longitude=res.longitude;
  187. console.log(this.latitude,this.longitude)
  188. }
  189. });
  190. }
  191. });
  192. }
  193. }
  194. }
  195. </script>
  196. <style>
  197. .content {
  198. flex: 1;
  199. }
  200. .map {
  201. width:100%;
  202. height: 100rem;
  203. flex: 1;
  204. }
  205. .img-map2{
  206. width: 100rpx;
  207. height: 140rpx;
  208. position: fixed;
  209. bottom: 12vh;
  210. right: 2vh;
  211. text-align: center;
  212. background-color: #FFFFFF;
  213. border-radius: 5px;
  214. }
  215. .img-map3{
  216. width: 100rpx;
  217. height: 140rpx;
  218. position: fixed;
  219. bottom: 23vh;
  220. right: 2vh;
  221. text-align: center;
  222. background-color: #FFFFFF;
  223. border-radius: 5px;
  224. }
  225. </style>