layout.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. <template>
  2. <div class="map-layout" v-loading="!loaded || captureing">
  3. <div class="custom_bar">
  4. <div class="back_container" v-if="!queryMode">
  5. <el-button :icon="Back" circle type="primary" @click="router.back()" />
  6. </div>
  7. <div class="nav_container">
  8. <div
  9. v-for="menu in menus"
  10. :key="menu.name"
  11. class="nav_item"
  12. :class="{
  13. active: menu.router.includes(router.currentRoute.value.name.toString()),
  14. }"
  15. @click="router.replace({ name: menu.router[Number(queryMode)] })"
  16. >
  17. <el-icon size="20">
  18. <component :is="menu.icon" />
  19. </el-icon>
  20. <span>{{ menu.name }}</span>
  21. </div>
  22. </div>
  23. </div>
  24. <div class="map-oper-layout">
  25. <div class="map-container" :ref="setMapContainer">
  26. <div class="board" :ref="setBoardContainer"></div>
  27. <div class="map-top-out-pano">
  28. <template v-if="!isCoordPage">
  29. <el-button @click="capture" v-if="loaded"> 提取位置图 </el-button>
  30. <el-button @click="showPoints = !showPoints">
  31. <el-checkbox :modelValue="showPoints" label="点位" size="large" />
  32. </el-button>
  33. </template>
  34. <div class="tile-select">
  35. <el-select
  36. v-model="tileType"
  37. placeholder="选择底图"
  38. style="width: 120px"
  39. class="tile-type-select"
  40. >
  41. <el-option
  42. v-for="item in tileOptions"
  43. :key="item"
  44. :label="item"
  45. :value="item"
  46. />
  47. </el-select>
  48. </div>
  49. </div>
  50. <div class="map-bottom-out-pano">
  51. <div class="point-info">
  52. <div>
  53. <el-icon size="20" color="rgb(230, 162, 60)">
  54. <locationIcon />
  55. </el-icon>
  56. <p>RTK点位</p>
  57. </div>
  58. <div>
  59. <el-icon size="20" color="rgba(64, 158, 255)">
  60. <locationIcon />
  61. </el-icon>
  62. <p>地图选点</p>
  63. </div>
  64. </div>
  65. </div>
  66. </div>
  67. <div class="data-panel">
  68. <RouterView v-slot="{ Component }" v-if="loaded">
  69. <component :is="Component" />
  70. </RouterView>
  71. </div>
  72. </div>
  73. </div>
  74. </template>
  75. <script setup lang="ts">
  76. import { router } from "@/router";
  77. import { Back } from "@element-plus/icons-vue";
  78. import vectorIcon from "@/assets/vector.svg";
  79. import locationIcon from "@/assets/location.svg";
  80. import { COORD_NAME, POYS_NAME, QUERY_COORD_NAME, QUERY_POYS_NAME } from "@/router";
  81. import {
  82. mapManage,
  83. board,
  84. autoInitPos,
  85. tileOptions,
  86. defaultCenter,
  87. tileType,
  88. } from "./install";
  89. import { computed, nextTick, ref, watch } from "vue";
  90. import { initRelics, relics } from "@/store/relics";
  91. import { queryMode } from "./install";
  92. import { PoPoint } from "drawing-board";
  93. import { boardData } from "@/store/scene";
  94. import saveAs from "@/util/file-serve";
  95. const menus = [
  96. {
  97. icon: locationIcon,
  98. name: "坐标",
  99. router: [COORD_NAME, QUERY_COORD_NAME],
  100. },
  101. {
  102. icon: vectorIcon,
  103. name: "矢量图",
  104. router: [POYS_NAME, QUERY_POYS_NAME],
  105. },
  106. ];
  107. const setMapContainer = (dom: HTMLDivElement) => setTimeout(() => mapManage.mount(dom));
  108. const setBoardContainer = (dom: HTMLDivElement) =>
  109. setTimeout(() => board.setProps({ dom }));
  110. const loaded = ref(false);
  111. watch(
  112. () => router.currentRoute.value.params?.relicsId,
  113. (rid) => {
  114. if (!rid) return;
  115. loaded.value = false;
  116. initRelics(Number(rid)).finally(() => {
  117. if (!relics.value) {
  118. return router.replace({ name: "relics" });
  119. }
  120. if (mapManage && !autoInitPos()) {
  121. mapManage.flyUserCenter(defaultCenter);
  122. }
  123. loaded.value = true;
  124. });
  125. },
  126. { immediate: true }
  127. );
  128. const isCoordPage = computed(() => {
  129. const name = router.currentRoute.value.name;
  130. return name && [COORD_NAME, QUERY_COORD_NAME].includes(name.toString());
  131. });
  132. const showPoints = ref(true);
  133. watch(
  134. () => [isCoordPage.value, boardData.value, showPoints.value] as const,
  135. ([isCoordPage, _, showPoints]) => {
  136. if (!board.polygon) return;
  137. board.polygon.children.forEach((entity) => {
  138. if (entity instanceof PoPoint) {
  139. if (isCoordPage) {
  140. entity.visible(entity.attrib.rtk);
  141. } else {
  142. entity.visible(showPoints);
  143. }
  144. } else {
  145. entity.visible(!isCoordPage);
  146. }
  147. });
  148. },
  149. { immediate: true, flush: "post" }
  150. );
  151. const captureing = ref(false);
  152. const capture = async () => {
  153. captureing.value = true;
  154. await new Promise((resolve) => setTimeout(resolve, 300));
  155. try {
  156. const dataURL = await board.toDataURL(2);
  157. await saveAs(dataURL, "map.png");
  158. } finally {
  159. captureing.value = false;
  160. }
  161. };
  162. </script>
  163. <style lang="scss" scoped>
  164. .map-layout {
  165. display: flex;
  166. flex-direction: row;
  167. height: 100%;
  168. }
  169. .custom_bar {
  170. width: 60px;
  171. height: 100%;
  172. background-color: white;
  173. // padding-top: 76px;
  174. .back_container {
  175. display: flex;
  176. justify-content: center;
  177. align-items: center;
  178. color: #606266;
  179. height: 76px;
  180. }
  181. .nav_container {
  182. display: flex;
  183. flex-direction: column;
  184. align-items: center;
  185. color: #606266;
  186. .nav_item {
  187. display: flex;
  188. flex-direction: column;
  189. align-items: center;
  190. justify-content: center;
  191. padding: 10px 0;
  192. cursor: pointer;
  193. user-select: none;
  194. width: 100%;
  195. span {
  196. line-height: 26px;
  197. font-size: var(--font14);
  198. }
  199. &.active {
  200. .icon {
  201. color: #409eff;
  202. }
  203. color: #409eff;
  204. background-color: #ecf5ff;
  205. position: relative;
  206. &::before {
  207. content: "";
  208. height: 100%;
  209. width: 4px;
  210. position: absolute;
  211. top: 0;
  212. left: 0;
  213. background-color: #409eff;
  214. }
  215. }
  216. }
  217. }
  218. }
  219. .map-oper-layout {
  220. display: flex;
  221. flex-direction: row;
  222. height: 100%;
  223. flex: 1;
  224. }
  225. .map-container {
  226. flex: 1;
  227. position: relative;
  228. .map-component {
  229. pointer-events: none;
  230. position: absolute;
  231. width: 100%;
  232. height: 100%;
  233. left: 0;
  234. top: 0;
  235. z-index: 9;
  236. }
  237. .board {
  238. position: absolute;
  239. left: 0;
  240. top: 0;
  241. bottom: 0;
  242. right: 0;
  243. z-index: 1;
  244. }
  245. }
  246. .data-panel {
  247. width: 320px;
  248. padding: 15px;
  249. border-left: 1px solid var(--border-color);
  250. position: relative;
  251. z-index: 3;
  252. }
  253. .map-top-out-pano {
  254. display: flex;
  255. position: absolute;
  256. right: 10px;
  257. top: 10px;
  258. z-index: 3;
  259. > * {
  260. margin-left: 10px;
  261. }
  262. }
  263. .map-bottom-out-pano {
  264. position: absolute;
  265. right: 10px;
  266. bottom: 10px;
  267. z-index: 3;
  268. }
  269. .point-info {
  270. background: #ffffff;
  271. border-radius: 4px 4px 4px 4px;
  272. padding: 10px;
  273. > div {
  274. display: flex;
  275. align-items: center;
  276. &:not(:last-child) {
  277. margin-bottom: 10px;
  278. }
  279. p {
  280. font-size: 16px;
  281. color: #606266;
  282. margin: 0;
  283. margin-left: 6px;
  284. }
  285. }
  286. }
  287. </style>