mapShow.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  1. <template>
  2. <view class="page" :style="{ height: pageHeight + 'px', flexDirection: flexDirection }">
  3. <view id="map" :style="{ height: pageHeight + 'px' }" class='map' />
  4. <!-- <view class="fab">
  5. <uni-fab ref="fab" :pattern="fab.pattern" :content="fab.content" :horizontal="fab.horizontal"
  6. :vertical="fab.vertical" :direction="fab.direction" @trigger="trigger" @fabClick="fabClick" />
  7. </view> -->
  8. <view v-show="popupShow" :style="{ height: popupHeight + 'px' }" class="popup">
  9. <uni-list v-for="(item, index) in players" :key="index" :border="true">
  10. <!-- 右侧带角标 -->
  11. <!-- <uni-list-chat :title="item.name" avatar="https://web-assets.dcloud.net.cn/unidoc/zh/unicloudlogo.png"
  12. note="您收到一条新的消息" time="2020-02-02 20:20" badge-text="12"></uni-list-chat> -->
  13. <uni-list-item
  14. :title="item.name + ' 打点数: ' + item.effectivenum + ' / ' + item.totalcontrolnum + ' 距离: ' + item.distance + '米 配速: ' + item.pace"
  15. :note="'平均心率: ' + item.avghr + ' 最大心率: ' + item.maxhr + ' CAL: ' + item.calorie + ' Ck: ' + item.ck + ' Ei: ' + item.ei">
  16. </uni-list-item>
  17. </uni-list>
  18. </view>
  19. </view>
  20. </template>
  21. <script module="leaflet" lang="renderjs">
  22. import 'leaflet/dist/leaflet.css'
  23. import '@/utils/map/leafletHelper.css'
  24. // import mapHelper from '@/utils/mapHelper'
  25. import leafletHelper from '@/utils/map/leafletHelper'
  26. export default {
  27. components: {},
  28. // data() {
  29. // return {},
  30. // },
  31. mounted() {
  32. uni.$on('myEvent', this.myEventHandler);
  33. },
  34. destroyed() {
  35. uni.$off('myEvent', this.myEventHandler);
  36. },
  37. beforeDestroy() {
  38. // console.log("beforeDestroy")
  39. // clearInterval(this.interval)
  40. leafletHelper.free()
  41. },
  42. methods: {
  43. myEventHandler(data) {
  44. console.log('视图层接收到数据:', data);
  45. },
  46. initMap() {
  47. // leafletHelper.init(this, 'map', [36.67175772119628, 117.12792580603369], 17)
  48. // const mapid = this.actionDetail.mapinfo.lid
  49. const mapurl = this.actionDetail.mapinfo.mapurl
  50. const centPoint = [this.actionDetail.mapinfo.centerlatitude, this.actionDetail.mapinfo.centerlongitude]
  51. const zoomNum = this.actionDetail.mapinfo.defscale
  52. leafletHelper.init(this, 'map', centPoint, zoomNum)
  53. leafletHelper.addMapLayer(mapurl)
  54. },
  55. handleMapDrawRoute() {
  56. // leafletHelper.global.setCheckPoints(this.checkPoints)
  57. leafletHelper.global.setRoutes(this.actionDetail.routesList)
  58. // leafletHelper.checkPoint.drawAllCheckPoints()
  59. // leafletHelper.checkPoint.drawPath()
  60. leafletHelper.route.drawAllRoutes()
  61. leafletHelper.route.drawAllPath()
  62. },
  63. handleMapDrawPlayer() {
  64. // leafletHelper.global.setPlayers(this.players)
  65. // leafletHelper.global.setPlayersPosition(this.players_position)
  66. leafletHelper.player.drawAllPlayers()
  67. // leafletHelper.player.drawOneTrail(1, 10000, true)
  68. // leafletHelper.player.drawOneTrail(2, 0, false)
  69. leafletHelper.player.drawAllTrails(5000)
  70. },
  71. handleMapToggle() {
  72. // leafletHelper.checkPoint.toggle(true)
  73. leafletHelper.route.toggle(true)
  74. leafletHelper.player.togglePlayer(true)
  75. leafletHelper.player.toggleTooltip(true)
  76. leafletHelper.player.toggleTrail(true)
  77. },
  78. },
  79. }
  80. </script>
  81. <script>
  82. import {
  83. DefaultRequest,
  84. IdRequest
  85. } from "@/grpc/base_pb.js"
  86. export default {
  87. components: {},
  88. data() {
  89. return {
  90. interval: null,
  91. systemInfo: null,
  92. deviceOrientation: 'portrait', // 设备方向(竖屏 portrait | 横屏 landscape)
  93. flexDirection: 'column',
  94. pageHeight: 0,
  95. // mapHeight: 0,
  96. popupHeight: 200,
  97. popupType: 'bottom',
  98. popupShow: false,
  99. actionId: 2,
  100. actionDetail: {},
  101. mapUrl: null,
  102. mapInfo: {},
  103. map: null,
  104. checkPoints: [{
  105. cp_id: 1, // 检查点ID
  106. serial_num: 1, // 序号
  107. c_type: 1, // 检查点类型 1:起始点 2:途经点 3:结束点 4:其他
  108. category: 1, // 检查点种类 1:实体点 2:虚拟点 3:VR点
  109. latitude: 36.67205,
  110. longitude: 117.126945
  111. },
  112. {
  113. cp_id: 2,
  114. serial_num: 2,
  115. c_type: 1,
  116. category: 1,
  117. latitude: 36.670871,
  118. longitude: 117.12725
  119. },
  120. {
  121. cp_id: 3,
  122. serial_num: 3,
  123. c_type: 1,
  124. category: 1,
  125. latitude: 36.671723,
  126. longitude: 117.128565
  127. },
  128. {
  129. cp_id: 4,
  130. serial_num: 4,
  131. c_type: 1,
  132. category: 1,
  133. latitude: 36.672704,
  134. longitude: 117.128415
  135. },
  136. {
  137. cp_id: 5,
  138. serial_num: 5,
  139. c_type: 1,
  140. category: 1,
  141. latitude: 36.672003,
  142. longitude: 117.129305
  143. },
  144. {
  145. cp_id: 6,
  146. serial_num: 6,
  147. c_type: 1,
  148. category: 1,
  149. latitude: 36.672416,
  150. longitude: 117.127116
  151. },
  152. {
  153. cp_id: 7,
  154. serial_num: 7,
  155. c_type: 1,
  156. category: 1,
  157. latitude: 36.671689,
  158. longitude: 117.127798
  159. },
  160. {
  161. cp_id: 8,
  162. serial_num: 8,
  163. c_type: 1,
  164. category: 1,
  165. latitude: 36.67094,
  166. longitude: 117.128522
  167. },
  168. ],
  169. players: [{
  170. id: 1,
  171. name: '小鱼儿',
  172. phone: '13105310001',
  173. },
  174. {
  175. id: 2,
  176. name: '花无缺',
  177. phone: '13105310002',
  178. },
  179. {
  180. id: 3,
  181. name: '李大嘴',
  182. phone: '13105310003',
  183. },
  184. {
  185. id: 4,
  186. name: '叶南天',
  187. phone: '13105310004',
  188. },
  189. ],
  190. players_position: [{
  191. id: 1,
  192. latitude: 36.671357,
  193. longitude: 117.127925
  194. },
  195. {
  196. id: 2,
  197. latitude: 36.671657,
  198. longitude: 117.125925
  199. },
  200. {
  201. id: 3,
  202. latitude: 36.672257,
  203. longitude: 117.128925
  204. },
  205. {
  206. id: 4,
  207. latitude: 36.670433,
  208. longitude: 117.127873
  209. }
  210. ],
  211. }
  212. },
  213. computed: {},
  214. mounted() {},
  215. onLoad() {
  216. // 逻辑层中触发自定义事件
  217. uni.$emit('myEvent', { name: 'Uniapp', version: '2.0.0' })
  218. this.loadData(this.actionId)
  219. },
  220. onReady() {
  221. this.layoutInit()
  222. },
  223. onShow() {
  224. console.log('[onShow]')
  225. uni.onWindowResize(res => {
  226. // console.log('[onWindowResize]', res)
  227. // this.deviceOrientation = res.deviceOrientation
  228. // console.log('[onWindowResize] deviceOrientation', this.deviceOrientation)
  229. this.layoutInit()
  230. });
  231. },
  232. beforeDestroy() {
  233. // console.log("beforeDestroy")
  234. clearInterval(this.interval)
  235. // leafletHelper.free()
  236. },
  237. methods: {
  238. // 布局初始化 设置地图高度
  239. layoutInit() {
  240. this.systemInfo = uni.getSystemInfoSync()
  241. // console.log('[layoutInit] systemInfo', this.systemInfo)
  242. this.pageHeight = this.systemInfo.windowHeight
  243. this.deviceOrientation = this.systemInfo.deviceOrientation
  244. if (this.deviceOrientation == 'portrait') { // 竖屏
  245. console.log('[layoutInit] 竖屏')
  246. this.flexDirection = 'column'
  247. // if (this.popupShow) {
  248. // this.mapHeight = this.pageHeight - this.popupHeight
  249. // } else {
  250. // this.mapHeight = this.pageHeight
  251. // }
  252. } else if (this.deviceOrientation == 'landscape') { // 横屏
  253. console.log('[layoutInit] 横屏')
  254. this.flexDirection = 'row'
  255. // this.mapHeight = this.pageHeight
  256. }
  257. },
  258. popupToggle() {
  259. // console.log('[popupToggle]')
  260. this.popupShow = !this.popupShow
  261. },
  262. async loadData() {
  263. this.actionDetail = await this.getToActionDetail(this.actionId)
  264. uni.setNavigationBarTitle({
  265. title: this.actionDetail.name
  266. });
  267. // console.log(this.actionDetail)
  268. this.initMap()
  269. this.handleMapDrawRoute()
  270. if (this.interval != null) {
  271. clearInterval(this.interval)
  272. }
  273. let that = this
  274. that.players = await that.getToUsersInGameDetail(that.actionId)
  275. // console.log('players', that.players)
  276. // leafletHelper.global.setPlayers(this.players)
  277. that.players_position = await that.getToUsersInGameGpsQuery(that.actionId)
  278. // leafletHelper.global.setPlayersPosition(this.players_position)
  279. that.handleMapDrawPlayer()
  280. this.interval = setInterval(async function() {
  281. that.players_position = await that.getToUsersInGameGpsQuery(that.actionId)
  282. //// leaflet.leafletHelper.global.setPlayers(that.players)
  283. // leafletHelper.global.setPlayersPosition(that.players_position)
  284. }, 1000);
  285. // await mapHelper.handleMapInfo(this, this.mapInfo)
  286. this.handleMapToggle()
  287. },
  288. //场控端_活动详情
  289. async getToActionDetail(actId) {
  290. try {
  291. return new Promise((resolve, reject) => {
  292. // 创建请求参数并赋值
  293. var request = new IdRequest()
  294. request.setId(actId)
  295. // 调用客户端相应的grpc方法,发送grpc请求,并接受后台发送回来的返回值
  296. this.$client.toActionDetail(request, {}, (err, response) => {
  297. if (err) {
  298. console.log(`[toActionDetail] err: code = ${err.code}` +
  299. `, message = "${err.message}"`)
  300. reject(err)
  301. } else {
  302. let res = response.toObject()
  303. console.log('[toActionDetail]', res)
  304. resolve(res)
  305. }
  306. })
  307. });
  308. } catch (e) {
  309. console.log('[getToActionDetail] err', e)
  310. reject(e)
  311. }
  312. },
  313. //场控端_正在进行中所有用户实时信息
  314. async getToUsersInGameDetail(actId) {
  315. try {
  316. return new Promise((resolve, reject) => {
  317. // 创建请求参数并赋值
  318. var request = new IdRequest()
  319. request.setId(actId)
  320. // 调用客户端相应的grpc方法,发送grpc请求,并接受后台发送回来的返回值
  321. this.$client.toUsersInGameDetail(request, {}, (err, response) => {
  322. if (err) {
  323. console.log(`[toUsersInGameDetail] err: code = ${err.code}` +
  324. `, message = "${err.message}"`)
  325. reject(err)
  326. } else {
  327. let res = response.toObject()
  328. // console.log('[toUsersInGameDetail]', res)
  329. resolve(res.usersList)
  330. }
  331. })
  332. });
  333. } catch (e) {
  334. console.log('[getToUsersInGameDetail] err', e)
  335. reject(e)
  336. }
  337. },
  338. //场控端_正在进行中所有用户实时gps查询
  339. async getToUsersInGameGpsQuery(actId) {
  340. try {
  341. return new Promise((resolve, reject) => {
  342. // 创建请求参数并赋值
  343. var request = new IdRequest()
  344. request.setId(actId)
  345. // 调用客户端相应的grpc方法,发送grpc请求,并接受后台发送回来的返回值
  346. this.$client.toUsersInGameGpsQuery(request, {}, (err, response) => {
  347. if (err) {
  348. console.log(`[toUsersInGameGpsQuery] err: code = ${err.code}` +
  349. `, message = "${err.message}"`)
  350. reject(err)
  351. } else {
  352. let res = response.toObject()
  353. // console.log('[toUsersInGameGpsQuery]', res)
  354. resolve(res.gpsinfoList)
  355. }
  356. })
  357. });
  358. } catch (e) {
  359. console.log('[getToUsersInGameGpsQuery] err', e)
  360. reject(e)
  361. }
  362. },
  363. // trigger(e) {
  364. // console.log(e)
  365. // this.content[e.index].active = !e.item.active
  366. // uni.showModal({
  367. // title: '提示',
  368. // content: `您${this.content[e.index].active ? '选中了' : '取消了'}${e.item.text}`,
  369. // success: function(res) {
  370. // if (res.confirm) {
  371. // console.log('用户点击确定')
  372. // } else if (res.cancel) {
  373. // console.log('用户点击取消')
  374. // }
  375. // }
  376. // })
  377. // },
  378. // fabClick() {
  379. // uni.showToast({
  380. // title: '点击了悬浮按钮',
  381. // icon: 'none'
  382. // })
  383. // },
  384. }
  385. }
  386. </script>
  387. <style lang="scss" scoped>
  388. .page {
  389. background-color: red;
  390. display: flex;
  391. }
  392. .map {
  393. flex: 1 1 auto;
  394. background-color: white;
  395. z-index: 0;
  396. // display: flex;
  397. // justify-content: center;
  398. // align-items: center;
  399. }
  400. .popup {
  401. // height: 200px;
  402. }
  403. // .fab {
  404. // z-index: 1000;
  405. // width: 20px;
  406. // }
  407. </style>