lp.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <template>
  2. <div class="zy-template">
  3. <div class="zy-main-title">设备列表-路牌</div>
  4. <div class="zy-module">
  5. <el-select v-model="selectedNum" filterable clearable placeholder=" " size="mini">
  6. <el-option v-for="item in openNumList" :key="item" :value="item" />
  7. </el-select>
  8. <el-button type="primary" plain size="mini" style="margin-left: 30px;" @click="searchSubmit()">搜索
  9. </el-button>
  10. </div>
  11. <div id="map" class="map">
  12. <div class="map__panel" v-if="selectedDevice != null">
  13. <p>设 备 号: {{selectedDevice.deviceId}}</p>
  14. <p>电 量: {{selectedDevice.batteryNum}}</p>
  15. <p>信号强度: {{selectedDevice.signalNum}}</p>
  16. <p>定位模式: {{selectedDevice.mode==1?"GPS定位":"基站定位"}}</p>
  17. <p>经 度: {{selectedDevice.lon}}</p>
  18. <p>纬 度: {{selectedDevice.lat}}</p>
  19. <p>移动速度: {{selectedDevice.speed}}</p>
  20. <p>卫星颗数: {{selectedDevice.num}}</p>
  21. <p>上传时间: {{selectedDevice.dataCreateTime}}</p>
  22. <p>位置: {{selectedDevice.site}}</p>
  23. </div>
  24. </div>
  25. </div>
  26. </template>
  27. <script>
  28. export default {
  29. data() {
  30. return {
  31. map: null, //地图对象
  32. markers: [], //地图中已经有的标记
  33. icon: '', //地图中的图标
  34. selectedNum: '', //搜索选择的设备号
  35. openNumList: [], // 选择框匹配的设备号
  36. deviceList: [], //全部的设备集合
  37. selectedDevice: null, //选中的设备对象
  38. }
  39. },
  40. activated() {
  41. this.initMap();
  42. this.getDeviceList();
  43. },
  44. methods: {
  45. /**
  46. * 初始化地图
  47. */
  48. initMap: function() {
  49. const option = {
  50. zoom: 5
  51. };
  52. this.map = new AMap.Map('map', option);
  53. //默认图标样式
  54. this.icon = new AMap.Icon({
  55. size: [45, 45],
  56. image: "/static/img/point.png",
  57. imageSize: [45, 45]
  58. })
  59. },
  60. /**
  61. * 提交搜索
  62. */
  63. searchSubmit: function() {
  64. if (this.selectedNum === "") return;
  65. this.deviceList.forEach(item => {
  66. if (this.selectedNum === item.deviceId) {
  67. this.map.setZoomAndCenter(11, [parseFloat(item.lon), parseFloat(item.lat)]);
  68. this.selectedDevice = item;
  69. }
  70. })
  71. },
  72. /**
  73. * 向地图中添加标记
  74. */
  75. addMarkers: function(devices) {
  76. const that = this;
  77. const markers = [];
  78. //清空原来的标记点
  79. if (this.markers != null && this.markers.length !== 0) {
  80. this.map.remove(this.markers);
  81. }
  82. devices.forEach(item => {
  83. if (item.latGcj != null && item.lonGcj != null) {
  84. markers.push(that.buildMarker(item))
  85. }
  86. });
  87. var marker = new AMap.Marker({
  88. position: new AMap.LngLat(116.406315,39.908775), // 经纬度对象,也可以是经纬度构成的一维数组[116.39, 39.9]
  89. title: '北京',
  90. offset: new AMap.Pixel(-10, -10),
  91. });
  92. this.map.add(marker);
  93. this.markers = markers;
  94. },
  95. /**
  96. * 构建 地图标记物
  97. */
  98. buildMarker: function(item) {
  99. const that = this;
  100. return new AMap.Marker({
  101. position: [parseFloat(item.lonGcj), parseFloat(item.latGcj)],
  102. icon: this.icon, // 添加 Icon 图标 URL
  103. // title: item.deviceId,
  104. // animation: "AMAP_ANIMATION_DROP"
  105. })
  106. // .on("click", function() {
  107. // that.map.setZoomAndCenter(16, [parseFloat(item.lonGcj), parseFloat(item.latGcj)]);
  108. // that.selectedDevice = item;
  109. // })
  110. },
  111. /**
  112. * 获取设备列表
  113. */
  114. getDeviceList: function() {
  115. this.$http.Get(this.$global.lp.listAll, {}).then(res => {
  116. this.deviceList = res.data;
  117. console.log(res.data);
  118. this.openNumList = res.data.map(item => {
  119. return item.openNum;
  120. });
  121. this.addMarkers(this.deviceList);
  122. });
  123. }
  124. }
  125. }
  126. </script>
  127. <style scoped lang="scss">
  128. .zy-template {
  129. height: 100%;
  130. .map {
  131. width: 100%;
  132. height: 100%;
  133. position: relative;
  134. &__panel {
  135. color: white;
  136. box-sizing: border-box;
  137. z-index: 9;
  138. position: absolute;
  139. right: 10px;
  140. top: 10px;
  141. width: 350px;
  142. padding: 10px;
  143. border-radius: 5px;
  144. background: rgba(0, 0, 0, .5);
  145. & p {
  146. font-size: 14px;
  147. line-height: 20px;
  148. margin: 0 0 3px;
  149. }
  150. }
  151. }
  152. }
  153. </style>