index.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. <template>
  2. <el-dialog
  3. title="室内定位融合"
  4. :visible.sync="centerDialogVisible"
  5. width="70vw"
  6. center>
  7. <div style="width: 100%;height: 70vh;">
  8. <bd-map :loaded="loaded" map-id="room-map" />
  9. <socket-message
  10. v-if="centerDialogVisible"
  11. :key="`device_uwb001`" :onMessage="onMessage"
  12. :ws="`/ws/point/uwb001`"></socket-message>
  13. </div>
  14. </el-dialog>
  15. </template>
  16. <script>
  17. import { pushDevcLocation } from '@/api/bd/fenceInfo';
  18. import SocketMessage from '@/components/WebsocketMessage/index.vue';
  19. import BdMap from '@/views/bd/map/index.vue';
  20. import maphandle from '@/views/bd/map/maphandle';
  21. import position from '@/views/bd/realtimeLocation/icon/position.png';
  22. import dayjs from 'dayjs';
  23. export default {
  24. name: 'room-map',
  25. mixins: [maphandle],
  26. components: {
  27. BdMap,
  28. SocketMessage,
  29. },
  30. data() {
  31. return {
  32. centerDialogVisible: false,
  33. locationMarkers: {},
  34. mapIns: null,
  35. playInterval: null,
  36. };
  37. },
  38. // 组件卸载前清空图层信息
  39. beforeDestroy() {
  40. this.markLayer && window.map.removeLayersById('markerLayer');
  41. this.playInterval && clearInterval(this.playInterval);
  42. },
  43. created() {
  44. },
  45. mounted() {
  46. this.play();
  47. },
  48. methods: {
  49. dayjs,
  50. loaded(map) {
  51. const vtLayer = new BDLayers.Lib.Layer.CBTileLayer('blayer_ng_s', {
  52. url: 'http://bd.xt.wenhq.top:8083/geoserver/gwc/service/wmts?REQUEST=GetTile&SERVICE=WMTS&VERSION=1.0.0&LAYER=bdlayers:bdl_cyy_pingmian&STYLE=&TILEMATRIX=EPSG:900913:{z}&TILEMATRIXSET=EPSG:900913&Format=image/jpeg&TILECOL={x}&TILEROW={y}',
  53. maxZoom: 22,
  54. minZoom: 15,
  55. });
  56. map.addCustomLayers(vtLayer);
  57. this.markLayer = new BDLayers.Lib.Layer.CBVectorLayer('markerLayer', true);
  58. map.addCustomLayers(this.markLayer);
  59. this.mapIns = map;
  60. map.setPitch(0);
  61. map.setZoom(22);
  62. map.setCenter([118.869046506393, 32.0133281708171]);
  63. },
  64. show() {
  65. this.centerDialogVisible = true;
  66. },
  67. addMarker(data) {
  68. const {
  69. latitude,
  70. longitude,
  71. deviceId,
  72. } = data;
  73. const marker = new BDLayers.Lib.Overlays.MarkerImg(
  74. `marker${deviceId}`,
  75. [longitude, latitude],
  76. {
  77. imgurl: position,
  78. iconSize: [25, 30],
  79. symbol: {
  80. 'textName': 'm4',
  81. 'textSize': 14,
  82. 'markerFile': position,
  83. 'markerHorizontalAlignment': 'middle', // left, middle(默认), right
  84. 'markerVerticalAlignment': 'middle', // top, middle, bottom(默认)
  85. },
  86. },
  87. );
  88. this.markLayer.addMarker(marker);
  89. return marker;
  90. },
  91. onMessage(a) {
  92. const data = JSON.parse(a.data);
  93. const {
  94. latitude,
  95. longitude,
  96. deviceId,
  97. } = data;
  98. console.log('>>>>>>>>>>>>>>>>>>>>>>>>', data);
  99. if (!this.locationMarkers[deviceId]) {
  100. this.locationMarkers[deviceId] = this.addMarker(data);
  101. return;
  102. }
  103. this.locationMarkers[deviceId].moveMarker([longitude, latitude], 2000, false);
  104. },
  105. play() {
  106. const gps = [
  107. [118.869125003231, 32.0132579193923],
  108. [118.869114609672, 32.0132582036815],
  109. [118.869115950776, 32.013238303438],
  110. [118.869116286052, 32.0132195403474],
  111. [118.869116286052, 32.0132144231402],
  112. [118.869113939119, 32.0132064630396],
  113. [118.869105557216, 32.0132021986996],
  114. [118.869093822552, 32.0132021986996],
  115. [118.869086111201, 32.0132021986996],
  116. [118.869077394021, 32.0132021986996],
  117. [118.869073370708, 32.0132021986996],
  118. [118.869070688499, 32.0132044730143],
  119. [118.869070353223, 32.013218118901],
  120. [118.869070353223, 32.0132323333641],
  121. [118.869071359051, 32.0132479692711],
  122. [118.869069012118, 32.0132536550547],
  123. [118.869064988805, 32.0132579193923],
  124. [118.869048224998, 32.0132570665248],
  125. [118.869028778983, 32.0132570665248],
  126. [118.869008327139, 32.0132525178981],
  127. [118.868998939408, 32.0132579193923],
  128. [118.868995586647, 32.0132604779947],
  129. [118.868992233885, 32.0132604779947],
  130. [118.868991228057, 32.0132621837296],
  131. [118.868982510878, 32.0132601937055],
  132. [118.868976140631, 32.0132601937055],
  133. [118.868968764556, 32.0132607622839],
  134. [118.868963735414, 32.0132607622839],
  135. [118.868965411795, 32.0132525178981],
  136. [118.868965747071, 32.0132394405949],
  137. [118.868965747071, 32.0132334705211],
  138. [118.868966082347, 32.0132127174044],
  139. [118.868965747071, 32.0132036201463],
  140. [118.868976811183, 32.0132002086742],
  141. [118.868985193087, 32.0132056101716],
  142. [118.868987204743, 32.0132175503224],
  143. [118.86898485781, 32.0132354605458],
  144. [118.868985528363, 32.0132402934625],
  145. [118.868999274684, 32.0132445578007],
  146. [118.869013021005, 32.0132439892223],
  147. [118.869029784811, 32.0132454106683],
  148. [118.869033472849, 32.0132431363547],
  149. [118.869036155058, 32.0132391563057],
  150. [118.869036155058, 32.0132320490749],
  151. [118.869037160886, 32.0132215303724],
  152. [118.869035484506, 32.0132067473289],
  153. [118.869035484506, 32.0132002086742],
  154. [118.86902039708, 32.0131987872275],
  155. [118.869002962721, 32.0131993558062],
  156. [118.868989551676, 32.0131993558062],
  157. [118.868975805355, 32.0131982186489],
  158. [118.86896239431, 32.0131976500702],
  159. [118.868952336026, 32.0131976500702],
  160. [118.868940266086, 32.0131996400956],
  161. [118.868936913324, 32.0131996400956],
  162. [118.868934231115, 32.0131996400956],
  163. [118.868921155346, 32.0131999243849],
  164. [118.868917132033, 32.0132010615423],
  165. [118.868910091234, 32.013200777253],
  166. [118.868910091234, 32.0132138545616],
  167. [118.868909085406, 32.0132272161577],
  168. [118.868909755958, 32.0132391563057],
  169. [118.868910091234, 32.0132488221386],
  170. [118.868910761786, 32.013257350814],
  171. [118.868909755958, 32.0132636051754],
  172. [118.868942277742, 32.0132627523079],
  173. [118.868973123146, 32.0132644580428],
  174. [118.869001621617, 32.0132638894645],
  175. [118.869058618558, 32.0132636051754],
  176. [118.869081082059, 32.0132624680188],
  177. [118.869094157828, 32.0132624680188],
  178. [118.869112933291, 32.0132624680188],
  179. [118.869124332679, 32.0132604779947],
  180. [118.869125003231, 32.0132579193923],
  181. ];
  182. let i = 0;
  183. this.playInterval && clearInterval(this.playInterval);
  184. this.playInterval = setInterval(() => {
  185. pushDevcLocation({
  186. devcKey: 'uwb001',
  187. lat: gps[i][1],
  188. lng: gps[i][0],
  189. });
  190. if (i === gps.length - 1) {
  191. i = 0;
  192. return;
  193. }
  194. i++;
  195. }, 2000);
  196. },
  197. },
  198. };
  199. </script>