index.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <template>
  2. <el-dialog
  3. title="室内定位"
  4. :visible.sync="centerDialogVisible"
  5. width="60%"
  6. center>
  7. <div style="width: 100%;height: 50vh;">
  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 SocketMessage from '@/components/WebsocketMessage/index.vue';
  18. import BdMap from '@/views/bd/map/index.vue';
  19. import maphandle from '@/views/bd/map/maphandle';
  20. import position from '@/views/bd/realtimeLocation/icon/position.png';
  21. import dayjs from 'dayjs';
  22. export default {
  23. name: 'room-map',
  24. mixins: [maphandle],
  25. components: {
  26. BdMap,
  27. SocketMessage,
  28. },
  29. data() {
  30. return {
  31. centerDialogVisible: false,
  32. locationMarkers: {},
  33. mapIns: null,
  34. };
  35. },
  36. // 组件卸载前清空图层信息
  37. beforeDestroy() {
  38. this.markLayer && window.map.removeLayersById('markerLayer');
  39. },
  40. created() {
  41. },
  42. mounted() {
  43. },
  44. methods: {
  45. dayjs,
  46. loaded(map) {
  47. const vtLayer = new BDLayers.Lib.Layer.CBTileLayer('blayer_ng_s', {
  48. 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}',
  49. maxZoom: 22,
  50. minZoom: 15,
  51. });
  52. map.addCustomLayers(vtLayer);
  53. this.markLayer = new BDLayers.Lib.Layer.CBVectorLayer('markerLayer', true);
  54. map.addCustomLayers(this.markLayer);
  55. this.mapIns = map;
  56. map.setPitch(0);
  57. map.setZoom(22);
  58. map.setCenter([118.869046506393, 32.0133281708171]);
  59. },
  60. show() {
  61. this.centerDialogVisible = true;
  62. },
  63. addMarker(data) {
  64. const {
  65. latitude,
  66. longitude,
  67. deviceId,
  68. } = data;
  69. const marker = new BDLayers.Lib.Overlays.MarkerImg(
  70. `marker${deviceId}`,
  71. [longitude, latitude],
  72. {
  73. imgurl: position,
  74. iconSize: [60, 45],
  75. symbol: {
  76. 'textName': 'm4',
  77. 'textSize': 14,
  78. 'markerFile': position,
  79. 'markerHorizontalAlignment': 'middle', // left, middle(默认), right
  80. 'markerVerticalAlignment': 'middle', // top, middle, bottom(默认)
  81. },
  82. },
  83. );
  84. this.markLayer.addMarker(marker);
  85. return marker;
  86. },
  87. onMessage(a) {
  88. const data = JSON.parse(a.data);
  89. const {
  90. latitude,
  91. longitude,
  92. deviceId,
  93. } = data;
  94. console.log('>>>>>>>>>>>>>>>>>>>>>>>>', data);
  95. if (!this.locationMarkers[deviceId]) {
  96. this.locationMarkers[deviceId] = this.addMarker(data);
  97. return;
  98. }
  99. this.locationMarkers[deviceId].moveMarker([longitude, latitude], 2000, false);
  100. },
  101. },
  102. };
  103. </script>