mapShow.vue 13 KB

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