mapShow.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  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>
  12. <uni-list :border="true">
  13. <!-- 右侧带角标 -->
  14. <uni-list-chat title="uni-app" avatar="https://web-assets.dcloud.net.cn/unidoc/zh/unicloudlogo.png"
  15. note="您收到一条新的消息" time="2020-02-02 20:20" badge-text="12"></uni-list-chat>
  16. </uni-list-chat>
  17. </uni-list>
  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. windowInfo: null,
  44. mapHeight: 0,
  45. popupHeight: 300,
  46. popupType: 'bottom',
  47. popupShow: false,
  48. actionId: 2,
  49. actionDetail: {},
  50. mapUrl: null,
  51. mapInfo: {},
  52. map: null,
  53. checkPoints: [{
  54. cp_id: 1, // 检查点ID
  55. serial_num: 1, // 序号
  56. c_type: 1, // 检查点类型 1:起始点 2:途经点 3:结束点 4:其他
  57. category: 1, // 检查点种类 1:实体点 2:虚拟点 3:VR点
  58. latitude: 36.67205,
  59. longitude: 117.126945
  60. },
  61. {
  62. cp_id: 2,
  63. serial_num: 2,
  64. c_type: 1,
  65. category: 1,
  66. latitude: 36.670871,
  67. longitude: 117.12725
  68. },
  69. {
  70. cp_id: 3,
  71. serial_num: 3,
  72. c_type: 1,
  73. category: 1,
  74. latitude: 36.671723,
  75. longitude: 117.128565
  76. },
  77. {
  78. cp_id: 4,
  79. serial_num: 4,
  80. c_type: 1,
  81. category: 1,
  82. latitude: 36.672704,
  83. longitude: 117.128415
  84. },
  85. {
  86. cp_id: 5,
  87. serial_num: 5,
  88. c_type: 1,
  89. category: 1,
  90. latitude: 36.672003,
  91. longitude: 117.129305
  92. },
  93. {
  94. cp_id: 6,
  95. serial_num: 6,
  96. c_type: 1,
  97. category: 1,
  98. latitude: 36.672416,
  99. longitude: 117.127116
  100. },
  101. {
  102. cp_id: 7,
  103. serial_num: 7,
  104. c_type: 1,
  105. category: 1,
  106. latitude: 36.671689,
  107. longitude: 117.127798
  108. },
  109. {
  110. cp_id: 8,
  111. serial_num: 8,
  112. c_type: 1,
  113. category: 1,
  114. latitude: 36.67094,
  115. longitude: 117.128522
  116. },
  117. ],
  118. players: [{
  119. id: 1,
  120. nickName: '小鱼儿',
  121. phone: '13105310001',
  122. },
  123. {
  124. id: 2,
  125. nickName: '花无缺',
  126. phone: '13105310002',
  127. },
  128. {
  129. id: 3,
  130. nickName: '李大嘴',
  131. phone: '13105310003',
  132. },
  133. {
  134. id: 4,
  135. nickName: '叶南天',
  136. phone: '13105310004',
  137. },
  138. ],
  139. players_position: [{
  140. id: 1,
  141. lat: 36.671357,
  142. lng: 117.127925
  143. },
  144. {
  145. id: 2,
  146. lat: 36.671657,
  147. lng: 117.125925
  148. },
  149. {
  150. id: 3,
  151. lat: 36.672257,
  152. lng: 117.128925
  153. },
  154. {
  155. id: 4,
  156. lat: 36.670433,
  157. lng: 117.127873
  158. }
  159. ],
  160. // fab: {
  161. // horizontal: 'left',
  162. // vertical: 'bottom',
  163. // direction: 'horizontal',
  164. // pattern: {
  165. // color: '#7A7E83',
  166. // backgroundColor: '#fff',
  167. // selectedColor: '#007AFF',
  168. // buttonColor: '#007AFF',
  169. // iconColor: '#fff'
  170. // },
  171. // is_color_type: false,
  172. // content: [{
  173. // iconPath: '/static/image.png',
  174. // selectedIconPath: '/static/image-active.png',
  175. // text: '玩家',
  176. // active: false
  177. // },
  178. // {
  179. // iconPath: '/static/home.png',
  180. // selectedIconPath: '/static/home-active.png',
  181. // text: '统计',
  182. // active: false
  183. // },
  184. // {
  185. // iconPath: '/static/star.png',
  186. // selectedIconPath: '/static/star-active.png',
  187. // text: '设置',
  188. // active: false
  189. // }
  190. // ]
  191. // },
  192. }
  193. },
  194. computed: {},
  195. mounted() {
  196. // this.handleDrawMap()
  197. },
  198. onLoad() {
  199. this.getToActionDetail(this.actionId)
  200. },
  201. onReady() {
  202. this.layoutInit()
  203. },
  204. beforeDestroy() {
  205. // console.log("beforeDestroy")
  206. leafletHelper.free()
  207. },
  208. methods: {
  209. // 布局初始化 设置地图高度
  210. layoutInit() {
  211. this.windowInfo = uni.getWindowInfo()
  212. console.log('[layoutInit] windowInfo', this.windowInfo)
  213. this.mapHeight = this.windowInfo.windowHeight
  214. },
  215. popupToggle() {
  216. this.popupShow = !this.popupShow
  217. if (this.popupShow) {
  218. this.mapHeight = this.windowInfo.windowHeight - this.popupHeight
  219. } else {
  220. this.mapHeight = this.windowInfo.windowHeight
  221. }
  222. },
  223. async getToActionDetail(actId) {
  224. try {
  225. // 创建请求参数并赋值
  226. var request = new IdRequest()
  227. request.setId(actId)
  228. // 调用客户端相应的grpc方法,发送grpc请求,并接受后台发送回来的返回值
  229. this.$client.toActionDetail(request, {}, async (err, response) => {
  230. if (err) {
  231. console.log(`[toActionDetail] err: code = ${err.code}` +
  232. `, message = "${err.message}"`)
  233. } else {
  234. let res = response.toObject()
  235. console.log('[toActionDetail]', res)
  236. this.actionDetail = res
  237. uni.setNavigationBarTitle({
  238. title: this.actionDetail.name
  239. });
  240. // await mapHelper.handleMapInfo(this, this.mapInfo)
  241. this.handleDrawMap()
  242. }
  243. })
  244. } catch (e) {
  245. console.log('[getShopMap] err', e)
  246. }
  247. },
  248. handleDrawMap() {
  249. // leafletHelper.init(this, 'map', [36.67175772119628, 117.12792580603369], 17)
  250. // const mapid = this.actionDetail.mapinfo.lid
  251. const mapurl = this.actionDetail.mapinfo.mapurl
  252. const centPoint = [this.actionDetail.mapinfo.centerlatitude, this.actionDetail.mapinfo.centerlongitude]
  253. const zoomNum = this.actionDetail.mapinfo.defscale
  254. leafletHelper.init(this, 'map', centPoint, zoomNum)
  255. leafletHelper.global.setCheckPoints(this.checkPoints)
  256. leafletHelper.global.setPlayers(this.players)
  257. leafletHelper.global.setPlayersPosition(this.players_position)
  258. leafletHelper.addMapLayer(mapurl)
  259. leafletHelper.checkPoint.drawAllCheckPoints()
  260. leafletHelper.checkPoint.drawPath()
  261. leafletHelper.player.drawAllPlayers()
  262. // leafletHelper.player.drawOneTrail(1, 10000, true)
  263. // leafletHelper.player.drawOneTrail(2, 0, false)
  264. leafletHelper.player.drawAllTrails(5000)
  265. leafletHelper.checkPoint.toggle(true)
  266. leafletHelper.player.togglePlayer(true)
  267. leafletHelper.player.toggleTooltip(true)
  268. leafletHelper.player.toggleTrail(true)
  269. },
  270. trigger(e) {
  271. console.log(e)
  272. this.content[e.index].active = !e.item.active
  273. uni.showModal({
  274. title: '提示',
  275. content: `您${this.content[e.index].active ? '选中了' : '取消了'}${e.item.text}`,
  276. success: function(res) {
  277. if (res.confirm) {
  278. console.log('用户点击确定')
  279. } else if (res.cancel) {
  280. console.log('用户点击取消')
  281. }
  282. }
  283. })
  284. },
  285. fabClick() {
  286. uni.showToast({
  287. title: '点击了悬浮按钮',
  288. icon: 'none'
  289. })
  290. },
  291. //type: 弹出方式 [ top center bottom left right ]
  292. popup(type) {
  293. this.type = type
  294. if (!this.popupShow) {
  295. this.$refs.popup.open(type)
  296. this.popupShow = true
  297. } else {
  298. this.$refs.popup.close()
  299. this.popupShow = false
  300. }
  301. },
  302. onPopupChange(e) {
  303. console.log('[onPopupChange] 当前模式:' + e.type + ', 状态:' + e.show);
  304. },
  305. // ========================================================= //
  306. // getEl: function(el) {
  307. // if (typeof el === 'string' || typeof el === 'number') return el;
  308. // return el instanceof HTMLElement ? el : el.$el;
  309. // },
  310. // // 获取角度
  311. // getAngle(angx, angy) {
  312. // return Math.atan2(angy, angx) * 180 / Math.PI;
  313. // },
  314. // // 根据起点终点返回方向 1向上 2向下 3向左 4向右 0未滑动
  315. // getDirection(startx, starty, endx, endy) {
  316. // var angx = endx - startx;
  317. // var angy = endy - starty;
  318. // var result = 0;
  319. // //如果滑动距离太短
  320. // if (Math.abs(angx) < 2 && Math.abs(angy) < 2) {
  321. // return result;
  322. // }
  323. // var angle = this.getAngle(angx, angy);
  324. // if (angle >= -135 && angle <= -45) {
  325. // result = 1;
  326. // } else if (angle > 45 && angle < 135) {
  327. // result = 2;
  328. // } else if ((angle >= 135 && angle <= 180) || (angle >= -180 && angle < -135)) {
  329. // result = 3;
  330. // } else if (angle >= -45 && angle <= 45) {
  331. // result = 4;
  332. // }
  333. // return result;
  334. // },
  335. // // 手势滑动开始
  336. // handleTouchStart(e) {
  337. // this.startx = e.changedTouches[0].pageX;
  338. // this.starty = e.changedTouches[0].pageY;
  339. // },
  340. // // 手势滑动结束
  341. // handleTouchEnd(e) {
  342. // var endx, endy;
  343. // endx = e.changedTouches[0].pageX;
  344. // endy = e.changedTouches[0].pageY;
  345. // var direction = this.getDirection(this.startx, this.starty, endx, endy);
  346. // switch (direction) {
  347. // // 未滑动!
  348. // case 0:
  349. // break;
  350. // // 向上滑动
  351. // case 1:
  352. // if (!this.isTop) {
  353. // this.goTop();
  354. // this.isTop = true
  355. // this.scrollable = true
  356. // }
  357. // break;
  358. // // 向下滑动
  359. // case 2:
  360. // if (this.isTop && this.contentOffsetY == 0) {
  361. // this.goBottom();
  362. // this.isTop = false
  363. // this.scrollable = false
  364. // }
  365. // break;
  366. // // 向左
  367. // case 3:
  368. // break;
  369. // // 向右
  370. // case 4:
  371. // break;
  372. // default:
  373. // }
  374. // },
  375. // handleTouchMove(e) {},
  376. // // 上滑操作
  377. // goTop() {
  378. // console.log("上滑操作")
  379. // let box = this.getEl(this.$refs.testdiv);
  380. // let topHeight = this.topHeight
  381. // // Binding.bind({
  382. // // eventType: 'timing',
  383. // // exitExpression: {
  384. // // origin: 't>800'
  385. // // },
  386. // // props: [{
  387. // // element: box,
  388. // // property: 'transform.translateY',
  389. // // expression: {
  390. // // origin: "easeOutQuint(t, 0, - " + topHeight + ", 800)"
  391. // // }
  392. // // }]
  393. // // });
  394. // },
  395. // // 下滑操作
  396. // goBottom() {
  397. // console.log("下滑操作")
  398. // let box = this.getEl(this.$refs.testdiv);
  399. // let topHeight = this.topHeight
  400. // // Binding.bind({
  401. // // eventType: 'timing',
  402. // // exitExpression: {
  403. // // origin: 't>800'
  404. // // },
  405. // // props: [{
  406. // // element: box,
  407. // // property: 'transform.translateY',
  408. // // expression: {
  409. // // origin: "easeOutQuint(t, - " + topHeight + ", " + topHeight + ", 800)"
  410. // // }
  411. // // }, ]
  412. // // });
  413. // // setTimeout(() => {
  414. // // this.refreshing = false
  415. // // }, 100)
  416. // },
  417. }
  418. }
  419. </script>
  420. <style lang="scss" scoped>
  421. .map {
  422. z-index: 0;
  423. width: 100vw;
  424. // height: 95vh;
  425. display: flex;
  426. justify-content: center;
  427. align-items: center;
  428. background-color: white;
  429. }
  430. .fab {
  431. z-index: 1000;
  432. width: 20px;
  433. }
  434. // @mixin flex {
  435. // /* #ifndef APP-NVUE */
  436. // display: flex;
  437. // /* #endif */
  438. // flex-direction: row;
  439. // }
  440. // @mixin height {
  441. // /* #ifndef APP-NVUE */
  442. // height: 100%;
  443. // /* #endif */
  444. // /* #ifdef APP-NVUE */
  445. // flex: 1;
  446. // /* #endif */
  447. // }
  448. .popup-bottom {
  449. width: 100%;
  450. height: 200px;
  451. }
  452. .popup-right {
  453. // @include height;
  454. width: 200px;
  455. height: 100%;
  456. }
  457. </style>