mapindex.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  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. <view class="img-map2">
  6. <cover-image style="width: 100rpx;height: 100rpx;" src="https://121.37.40.217/app/images/ef712ef2a0bf48f48bf56ea655e8359c.png" @click="getregulatorBoxList "></cover-image>
  7. 调压箱
  8. </view>
  9. <view class="img-map3">
  10. <cover-image style="width: 100rpx;height: 100rpx;" src="https://121.37.40.217/app/images/6ba09f14edcc49b5bd2ff0f6dee4bdb9.png" @click="getvalveWellPositionlist"></cover-image>
  11. <!-- <u-popup v-model="show" mode="bottom" height='600rpx'>
  12. <view>出淤泥而不染,濯清涟而不妖</view>
  13. </u-popup> -->
  14. 阀井
  15. </view>
  16. </map>
  17. </view>
  18. </template>
  19. <script>
  20. // const img = 'https://121.37.40.217/app/images/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. type:1
  32. }
  33. },
  34. onReady() {
  35. this.getconter()
  36. this._mapContext = uni.createMapContext("map", this);
  37. // 仅调用初始化,才会触发 on.("markerClusterCreate", (e) => {})
  38. this._mapContext.initMarkerCluster({
  39. enableDefaultStyle: false,
  40. zoomOnClick: true,
  41. gridSize: 10,
  42. complete(res) {
  43. console.log('initMarkerCluster', res)
  44. }
  45. });
  46. this._mapContext.on("markerClusterCreate", (e) => {
  47. console.log("markerClusterCreate", e);
  48. });
  49. },
  50. onShow() {
  51. this.getconter()
  52. setTimeout(()=>{
  53. this.getvalveWellPositionlist()
  54. },100)
  55. },
  56. methods: {
  57. //右下角定位按钮的点击事件
  58. clickcontrol(){
  59. this.show=true
  60. console.log(this.latitude,this.longitude)
  61. uni.authorize({
  62. scope: 'scope.userLocation',
  63. success() {
  64. uni.getLocation({
  65. type: 'gcj02',
  66. altitude: true, //高精度定位
  67. //定位成功,更新定位结果
  68. success: function(res) {
  69. console.log(res)
  70. that.latitude=res.latitude;
  71. that.longitude=res.longitude;
  72. that.covers[0].latitude=res.latitude;
  73. that.covers[0].longitude=res.longitude;
  74. }
  75. });
  76. }
  77. });
  78. this._mapContext.moveToLocation({ //moveToLocation将地图中心移动到当前定位点,需要配合map组件的show-location使用
  79. latitude: this.latitude,
  80. longitude: this.longitude
  81. });
  82. },
  83. getvalveWellPositionlist()
  84. {
  85. service.getvalveWellPositionlist({}).then(res => {
  86. console.log('getwarningPileList', res)
  87. if (res.length == 0) {
  88. this.$UTILS.showPrompt('暂无项目!')
  89. }
  90. this.positions = res;
  91. let img='https://121.37.40.217/app/images/6ba09f14edcc49b5bd2ff0f6dee4bdb9.png'
  92. setTimeout(()=>{this.addMarkers(img)},1000)
  93. })
  94. },
  95. getregulatorBoxList()
  96. {
  97. this.positions=[]
  98. service.getregulatorBoxList({}).then(res => {
  99. console.log('getwarningPileList', res)
  100. if (res.length == 0) {
  101. this.$UTILS.showPrompt('暂无项目!')
  102. }
  103. this.positions = res.rows;
  104. let img='https://121.37.40.217/app/images/ef712ef2a0bf48f48bf56ea655e8359c.png'
  105. setTimeout(()=>{this.addMarkers2(img)},1000)
  106. })
  107. },
  108. addMarkers2(img) {
  109. this.type=2
  110. const positions = [
  111. {
  112. latitude: 43.771703,
  113. longitude: 125.376804
  114. },{
  115. latitude: "43.780458",
  116. longitude: "125.367899"
  117. }
  118. ]
  119. this.markers = []
  120. this.positions.forEach((p, i) => {
  121. this.markers.push(
  122. Object.assign({},{
  123. id: p.id,
  124. type:2,
  125. iconPath: img,
  126. width: 45,
  127. height: 50,
  128. latitude:parseFloat(p.latitude),
  129. longitude:parseFloat(p.longitude),
  130. joinCluster: true, // 指定了该参数才会参与聚合
  131. // label: {
  132. // width: 50,
  133. // height: 30,
  134. // borderWidth: 1,
  135. // borderRadius: 10,
  136. // bgColor: '#ffffff',
  137. // content: p.valveWellName,
  138. // latitude:p.latitude,
  139. // longitude:p.longitude
  140. // },
  141. callout:{
  142. borderWidth: 1,
  143. borderRadius: 10,
  144. bgColor: '#ffffff',
  145. fontSize:20,
  146. padding:3,
  147. content: p.name,
  148. display:'ALWAYS'
  149. }
  150. })
  151. )
  152. })
  153. console.log(this.markers)
  154. setTimeout(()=>{
  155. this._mapContext.addMarkers({
  156. markers:this.markers,
  157. clear: true,
  158. complete(res) {
  159. console.log('addMarkers', res)
  160. }
  161. })
  162. },100)
  163. },
  164. addMarkers(img) {
  165. this.type=1
  166. const positions = [
  167. {
  168. latitude: 43.771703,
  169. longitude: 125.376804
  170. },{
  171. latitude: "43.780458",
  172. longitude: "125.367899"
  173. }
  174. ]
  175. this.markers = []
  176. this.positions.forEach((p, i) => {
  177. this.markers.push(
  178. Object.assign({},{
  179. id: p.id,
  180. type:1,
  181. iconPath: img,
  182. width: 45,
  183. height: 50,
  184. latitude:parseFloat(p.latitude),
  185. longitude:parseFloat(p.longitude),
  186. joinCluster: true, // 指定了该参数才会参与聚合
  187. // label: {
  188. // width: 50,
  189. // height: 30,
  190. // borderWidth: 1,
  191. // borderRadius: 10,
  192. // bgColor: '#ffffff',
  193. // content: p.valveWellName,
  194. // latitude:p.latitude,
  195. // longitude:p.longitude
  196. // },
  197. callout:{
  198. borderWidth: 1,
  199. borderRadius: 10,
  200. bgColor: '#ffffff',
  201. fontSize:20,
  202. padding:3,
  203. content: p.valveWellName,
  204. display:'ALWAYS'
  205. }
  206. })
  207. )
  208. })
  209. console.log(this.markers)
  210. setTimeout(()=>{
  211. this._mapContext.addMarkers({
  212. markers:this.markers,
  213. clear: true,
  214. complete(res) {
  215. console.log('addMarkers', res)
  216. }
  217. })
  218. },100)
  219. },
  220. //位置定位
  221. location(e){
  222. if(this.type==1)
  223. {
  224. console.log(e)
  225. service.getvalveWellPosition(e.markerId).then(res => {
  226. console.log('getwarningPileList', res)
  227. console.log(e)
  228. uni.openLocation({
  229. latitude: parseFloat( res.latitude),
  230. longitude: parseFloat(res.longitude),
  231. success: function (res) {
  232. console.log('打开系统位置地图成功')
  233. },
  234. fail: function (error) {
  235. console.log(error)
  236. }
  237. })
  238. // this.positions = res;
  239. })
  240. }else{
  241. console.log(e)
  242. service.getregulatorBox(e.markerId).then(res => {
  243. console.log('getwarningPileList', res)
  244. console.log(e)
  245. uni.openLocation({
  246. latitude: parseFloat( res.latitude),
  247. longitude: parseFloat(res.longitude),
  248. success: function (res) {
  249. console.log('打开系统位置地图成功')
  250. },
  251. fail: function (error) {
  252. console.log(error)
  253. }
  254. })
  255. // this.positions = res;
  256. })
  257. }
  258. },
  259. clickMarker(e)
  260. {
  261. console.log("点击了",e)
  262. this._mapContext.removeMarkers()
  263. },
  264. getconter()
  265. {
  266. var that = this;
  267. // 获取经纬度
  268. uni.authorize({
  269. scope: 'scope.userLocation',
  270. success() {
  271. uni.getLocation({
  272. type: 'gcj02',
  273. altitude: true, //高精度定位
  274. //定位成功,更新定位结果
  275. success: function(res) {
  276. console.log(res)
  277. that.latitude=res.latitude;
  278. that.longitude=res.longitude;
  279. that.latitude=res.latitude;
  280. that.longitude=res.longitude;
  281. console.log(this.latitude,this.longitude)
  282. }
  283. });
  284. }
  285. });
  286. }
  287. }
  288. }
  289. </script>
  290. <style>
  291. .content {
  292. flex: 1;
  293. }
  294. .map {
  295. width:100%;
  296. height: 100rem;
  297. flex: 1;
  298. }
  299. .img-map2{
  300. width: 100rpx;
  301. height: 140rpx;
  302. position: fixed;
  303. bottom: 12vh;
  304. right: 2vh;
  305. text-align: center;
  306. display: flex;
  307. flex-direction: column;
  308. background-color: #FFFFFF;
  309. border-radius: 5px;
  310. }
  311. .img-map3{
  312. width: 100rpx;
  313. height: 140rpx;
  314. position: fixed;
  315. bottom: 23vh;
  316. right: 2vh;
  317. text-align: center;
  318. display: flex;
  319. flex-direction: column;
  320. background-color: #FFFFFF;
  321. border-radius: 5px;
  322. }
  323. </style>