map.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  1. <template>
  2. <div class="page page-full">
  3. <div style="position: relative; flex: 1">
  4. <div class="map" ref="mapRef" style="height: 100%"></div>
  5. <div class="search-hover">
  6. <!-- <el-input v-model="searchText" @keydown.enter.native="searchPoint" placeholder="地址搜索" style="width:250px">
  7. <template #append>
  8. <el-button :icon="Search" @click="searchPoint"></el-button>
  9. </template>
  10. </el-input> -->
  11. <el-select
  12. v-model="searchText"
  13. filterable
  14. allow-create
  15. default-first-option
  16. :reserve-keyword="false"
  17. placeholder="地址搜索"
  18. style="width: 250px"
  19. @change="searchPoint"
  20. >
  21. <el-option v-for="item in heatList" :key="item.id" :label="item.name" :value="item.id" />
  22. </el-select>
  23. </div>
  24. <!-- 显示弹层区域 -->
  25. <div class="view map-hover-station">
  26. <div class="view-div" v-for="(item, index) in viewList" :key="index">
  27. <div class="view-div-head">
  28. <div class="title">{{ item.name }}环路</div>
  29. <div class="info">
  30. <div class="">环路编号:{{ item.code }}</div>
  31. <div class="ml-4">所属换热站:{{ item.stationInfo.name }}</div>
  32. </div>
  33. </div>
  34. <div class="view-div-content">
  35. <div>路线信息</div>
  36. <div class="mt-1 pl-4">
  37. <p v-for="(point, index) in item.loopViaPointInfo" :key="index">
  38. {{ point.position }}
  39. </p>
  40. </div>
  41. <div class="mt-1">实时温度</div>
  42. <el-table
  43. :data="[
  44. {
  45. outTemperature1: item.outTemperature1,
  46. inTemperature1: item.inTemperature1,
  47. outTemperature2: item.outTemperature2,
  48. inTemperature2: item.inTemperature2,
  49. },
  50. ]"
  51. :border="true"
  52. class="mt-1"
  53. >
  54. <el-table-column label="一网供水温度" prop="outTemperature1" :show-overflow-tooltip="true" />
  55. <el-table-column label="一网回水温度" prop="inTemperature1" :show-overflow-tooltip="true" />
  56. <el-table-column label="二网供水温度" prop="outTemperature2" :show-overflow-tooltip="true" />
  57. <el-table-column label="二网回水温度" prop="inTemperature2" :show-overflow-tooltip="true" />
  58. </el-table>
  59. <div class="mt-1">实时压力(MPa)</div>
  60. <el-table
  61. :data="[
  62. {
  63. outPressure1: item.outPressure1,
  64. inPressure1: item.inPressure1,
  65. outPressure2: item.outPressure2,
  66. inPressure2: item.inPressure2,
  67. },
  68. ]"
  69. :border="true"
  70. class="mt-1"
  71. >
  72. <el-table-column label="一网供水压力" prop="outPressure1" :show-overflow-tooltip="true" />
  73. <el-table-column label="一网回水压力" prop="inPressure1" :show-overflow-tooltip="true" />
  74. <el-table-column label="二网供水压力" prop="outPressure2" :show-overflow-tooltip="true" />
  75. <el-table-column label="二网回水压力" prop="inPressure2" :show-overflow-tooltip="true" />
  76. </el-table>
  77. </div>
  78. </div>
  79. </div>
  80. </div>
  81. </div>
  82. </template>
  83. <script lang="ts" setup>
  84. import { onMounted, ref, watch, nextTick } from 'vue';
  85. import { Search } from '@element-plus/icons-vue';
  86. import { useRouter } from 'vue-router';
  87. import api from '/@/api/heatStation';
  88. import { setMarker, setLine } from '/@/utils/map';
  89. import { useStore } from '/@/store/index';
  90. const router = useRouter();
  91. const mapRef = ref();
  92. const searchText = ref('');
  93. const store = useStore();
  94. const heatList = ref([]);
  95. const viewList = ref<any[]>([]);
  96. let BMapGL = (window as any).BMapGL;
  97. let map: any = null;
  98. let local: any = null;
  99. let getThemeConfig: any = null;
  100. let points: any = [];
  101. let loops: any = [];
  102. // 地图弹窗点击去环路详情,进行跳转
  103. window.mapToDetail = (code: string) => {
  104. router.push('/heating-monitor/loopSupervision/loopDetail?code=' + code);
  105. };
  106. function searchPoint(val: number | string) {
  107. if (typeof val === 'number') {
  108. map.setZoom(15);
  109. const { lat, lnt: lng } = heatList.value.find((item: any) => item.id === val) as any;
  110. setTimeout(() => {
  111. map.centerAndZoom({ lat, lng }, 20);
  112. }, 500);
  113. local && local.search('');
  114. // 选择的换热站
  115. } else {
  116. // 自定义的地址搜索
  117. if (local) {
  118. local.search(searchText.value);
  119. } else {
  120. local = new BMapGL.LocalSearch(map, {
  121. renderOptions: { map },
  122. });
  123. local.search(searchText.value);
  124. }
  125. }
  126. console.log(val);
  127. }
  128. onMounted(() => {
  129. // 获取布局配置信息
  130. getThemeConfig = store.state.themeConfig.themeConfig;
  131. map = new BMapGL.Map(mapRef.value, {});
  132. map.addControl(new BMapGL.ScaleControl()); // 添加比例尺控件
  133. map.addControl(new BMapGL.ZoomControl()); // 添加缩放控件
  134. const testPt = new BMapGL.Point(124.383044, 40.124296);
  135. map.centerAndZoom(testPt, 5);
  136. map.enableScrollWheelZoom();
  137. if (getThemeConfig.isIsDark) {
  138. map.setMapStyleV2({
  139. styleId: 'b8d841ee37fd5bd41e742049b6fcd0f5',
  140. });
  141. }
  142. // 获取环路列表
  143. api.heatStation.getAll().then((res: any) => {
  144. loops = res;
  145. const list = res.filter((item: any) => item.loopViaPointInfo?.length > 1);
  146. // console.log(list)
  147. setLine(list, map);
  148. });
  149. // 获取换热站列表
  150. api.heatStation
  151. .getAllList({
  152. status: 1,
  153. })
  154. .then((res: any) => {
  155. heatList.value = res;
  156. renderStation(res);
  157. });
  158. // 地图缩放事件
  159. map.addEventListener('zoomend', (e: any) => {
  160. // console.log('zoomend', map.getZoom())
  161. let zoom = map.getZoom();
  162. if (zoom > 18.4 && points.length) {
  163. resetAreaPoints()
  164. } else {
  165. viewList.value = [];
  166. }
  167. });
  168. // 地图拖拽事件
  169. map.addEventListener('dragend', (e: any) => {
  170. let zoom = map.getZoom();
  171. if (zoom > 18.4 && points.length) {
  172. resetAreaPoints()
  173. } else {
  174. viewList.value = [];
  175. }
  176. });
  177. // 获取当前视图内的点
  178. // map.getBounds().containsPoint({
  179. // "lng": 124.41798,
  180. // "lat": 40.149303
  181. // })
  182. // window._map = map
  183. });
  184. function resetAreaPoints() {
  185. let arr: any = [];
  186. let viewArrCache: any = [];
  187. points.forEach((point: any) => {
  188. if (map.getBounds().containsPoint(point)) {
  189. arr.push(point);
  190. }
  191. });
  192. arr.forEach((point: any) => {
  193. // 查询环路列表中属于该站点的环路列表,进行显示
  194. const theLoops = loops.filter((item: any) => item.stationInfo?.id === point.data.id);
  195. viewArrCache = viewArrCache.concat(theLoops);
  196. });
  197. viewList.value = viewArrCache;
  198. }
  199. // 监听 vuex 中是否开启深色主题
  200. watch(
  201. () => store.state.themeConfig.themeConfig.isIsDark,
  202. (isIsDark) => {
  203. nextTick(() => {
  204. setTimeout(() => {
  205. map.setMapStyleV2({
  206. styleId: isIsDark ? 'b8d841ee37fd5bd41e742049b6fcd0f5' : '48b5759a53d0d6f607c049543d4c92e4',
  207. });
  208. }, 500);
  209. });
  210. },
  211. {
  212. deep: true,
  213. immediate: true,
  214. }
  215. );
  216. const renderStation = (list: any[]) => {
  217. points = setMarker(list, map);
  218. // 控制标点显示在最佳视野内
  219. if (points && points.length) {
  220. map.setViewport(points);
  221. }
  222. };
  223. </script>
  224. <style lang="scss">
  225. [data-theme='dark'] .map-hover-station {
  226. .view-div-head,
  227. .view-div {
  228. color: #fff;
  229. background: #222;
  230. }
  231. }
  232. .BMap_bubble_pop {
  233. width: 220px;
  234. padding: 0 !important;
  235. border: none !important;
  236. background: transparent !important;
  237. color: #fff !important;
  238. margin-top: 0;
  239. margin-left: -20px;
  240. // pointer-events: none;
  241. & > img {
  242. display: none !important;
  243. }
  244. }
  245. .BMap_bubble_content {
  246. color: #fff !important;
  247. }
  248. // .BMap_bubble_content,
  249. // .BMap_bubble_center {
  250. // height: 150px !important;
  251. // }
  252. .BMap_bubble_content {
  253. height: auto !important;
  254. background: rgba(0, 29, 122, 0.6) !important;
  255. border-radius: 3px;
  256. }
  257. .BMap_bubble_top,
  258. .BMap_bubble_bottom {
  259. display: none !important;
  260. }
  261. .map-hover-box {
  262. color: #fff;
  263. font-size: 12px;
  264. padding: 10px 14px;
  265. .map-hover-title {
  266. line-height: 18px;
  267. font-size: 14px;
  268. font-weight: 500;
  269. }
  270. .map-hover-label {
  271. white-space: nowrap;
  272. }
  273. .map-hover-btn {
  274. white-space: nowrap;
  275. background: #67c23a;
  276. padding: 6px 12px;
  277. border-radius: 4px;
  278. cursor: pointer;
  279. }
  280. .map-hover-row-item {
  281. display: flex;
  282. align-items: flex-start;
  283. margin-top: 4px;
  284. line-height: 1.2;
  285. // gap: 20px;
  286. .map-hover-value {
  287. // font-size: 22px;
  288. color: #ffd228;
  289. font-weight: 500;
  290. word-break: break-all;
  291. }
  292. }
  293. }
  294. </style>
  295. <style scoped lang="scss">
  296. .map-hover-station {
  297. max-height: 98%;
  298. overflow-y: auto;
  299. }
  300. .view {
  301. position: absolute;
  302. top: 10px;
  303. right: 10px;
  304. z-index: 999;
  305. // display: flex;
  306. &-div {
  307. width: 350px;
  308. color: #000;
  309. background-color: #fff;
  310. font-size: 12px;
  311. &:not(:first-child) {
  312. margin-top: 10px;
  313. }
  314. &-head {
  315. background-color: #f2f2f2;
  316. padding: 5px 10px;
  317. .title {
  318. font-size: 13px;
  319. font-weight: bold;
  320. }
  321. .info {
  322. display: flex;
  323. align-items: center;
  324. margin-top: 4px;
  325. }
  326. }
  327. &-content {
  328. padding: 10px;
  329. }
  330. }
  331. }
  332. :deep(.el-table) {
  333. tr {
  334. th {
  335. background-color: #efefef;
  336. }
  337. }
  338. }
  339. :deep(.el-table__cell) {
  340. padding: 2px 0;
  341. }
  342. :deep(.cell) {
  343. padding: 0 2px;
  344. line-height: 14px;
  345. font-weight: 400;
  346. font-size: 12px;
  347. color: #000;
  348. }
  349. .search-hover {
  350. position: absolute;
  351. top: 10px;
  352. left: 10px;
  353. z-index: 999;
  354. width: 350px;
  355. color: #000;
  356. font-size: 12px;
  357. padding: 10px;
  358. }
  359. .suggestId {
  360. height: 30px;
  361. padding: 0 10px;
  362. }
  363. </style>