index.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. <template>
  2. <div id="globalMap">
  3. <div class="global-map">
  4. <MapLogical v-if="activeMap === 'logical'" :map-data="mapData" />
  5. <!-- <YMap v-else-if="['satellite2', 'satellite3'].includes(activeMap)" :activeMap="activeMap" />-->
  6. <YztMap v-else-if="['satellite2', 'satellite3'].includes(activeMap)" ref="map2Ref" :active-map="activeMap" :point-type="pointType" />
  7. <Map v-else ref="mapRef" :active-map="activeMap" :point-type="pointType" @handle-show-video="handleShowVideo" @handleShowWarehouse="handleShowWarehouse" />
  8. <!--左侧菜单-->
  9. <LeftMenu style="position: absolute; top: 20px; left: 20px" @click-menu="clickMenu" @select-search-marker="selectSearchMarker" />
  10. <!--右侧菜单-->
  11. <RightMenu ref="rightMenuRef" :point-type="pointType" />
  12. <!--更换地图类型-->
  13. <SwitchMapTool :active-map="activeMap" class="tool-box" @switch-map="switchMap" />
  14. <!--时间轴-->
  15. <TimeAxis />
  16. <DrawTools v-if="showDrawTools" @handle-analysis-data="handleAnalysisData" />
  17. <NearbyVideos v-if="showNearbyVideos" v-model="showNearbyVideos" :location="location" />
  18. <MaterialDetail v-if="showWarehouse" v-model="showWarehouse" :warehouseData="warehouseData" />
  19. </div>
  20. </div>
  21. </template>
  22. <script lang="ts" setup name="globalMap">
  23. import Map from '@/components/Map/index.vue';
  24. import YztMap from '@/components/Map/YztMap/index.vue';
  25. import MapLogical from '@/components/Map/MapLogical.vue';
  26. import { iconList, logicalData } from './data/mapData';
  27. import SwitchMapTool from '@/views/globalMap/SwitchMapTool.vue';
  28. import LeftMenu from './LeftMenu.vue';
  29. import MaterialDetail from './MaterialDetail.vue';
  30. import TimeAxis from '@/components/TimeAxis/index.vue';
  31. import { deepClone } from '@/utils';
  32. import { getPointInfo } from '@/api/globalMap';
  33. import RightMenu from './RightMenu/index.vue';
  34. import { PointType } from '@/api/globalMap/type';
  35. import DrawTools from '@/views/globalMap/RightMenu/DrawTools.vue';
  36. const rightMenuRef = ref(null);
  37. const mapData = reactive(logicalData);
  38. let mapRef = ref(null);
  39. let map2Ref = ref(null);
  40. // logical vectorgraph satellite satellite2 satellite3
  41. let activeMap = ref('logical');
  42. const switchMap = (key) => {
  43. activeMap.value = key;
  44. };
  45. let pointType = ref<PointType[]>([]);
  46. let markerList = ref([]);
  47. const addMarkers = (item) => {
  48. const dom = activeMap.value === 'satellite2' ? map2Ref.value : mapRef.value;
  49. if (dom) {
  50. if (!item.checked) {
  51. let index = pointType.value.findIndex((item2) => item.component === item2.component);
  52. if (index > -1) {
  53. pointType.value.splice(index, 1);
  54. }
  55. if (pointType.value && pointType.value.length === 0) {
  56. dom.clearMarker('point');
  57. return;
  58. }
  59. } else {
  60. // 右侧图层分析状态
  61. item.checked2 = true;
  62. pointType.value.push(item);
  63. }
  64. let path = [];
  65. pointType.value.forEach((item) => {
  66. path.push(item.component);
  67. });
  68. getPointInfo(path.toString()).then((res) => {
  69. const data = res.data && res.data.list ? res.data?.list : [];
  70. markerList.value = data;
  71. data.forEach((item2) => {
  72. // 获取图标
  73. if (iconList[item2.dataType]) {
  74. item2.icon = iconList[item2.dataType].image;
  75. item2.image = iconList[item2.dataType].image;
  76. item2.imageHover = iconList[item2.dataType].imageHover;
  77. item2.size = iconList[item2.dataType].size;
  78. } else {
  79. item2.icon = iconList['common'].image;
  80. item2.image = iconList['common'].image;
  81. item2.imageHover = iconList['common'].imageHover;
  82. item2.size = iconList['common'].size;
  83. }
  84. if (item2.materia_name) {
  85. item2.name = item2.materia_name;
  86. }
  87. item2.parentId = item.component;
  88. item2.lnglat = [item2.longitude, item2.latitude];
  89. });
  90. dom.addMarker(data);
  91. });
  92. }
  93. };
  94. // 跳转指定地点
  95. const toAddress = (item) => {
  96. const dom = activeMap.value === 'satellite2' ? map2Ref.value : mapRef.value;
  97. dom.setCenter(item);
  98. };
  99. let showDrawTools = ref(false);
  100. // 右侧菜单
  101. // 点击菜单
  102. const clickMenu = (item, dataList) => {
  103. if (item.path === '1') {
  104. // 空间分析
  105. if (item.component === 'spatial') {
  106. showDrawTools.value = !showDrawTools.value;
  107. }
  108. rightMenuRef.value.updateMenu(item.checked ? '1' : '2', item);
  109. } else if (item.path === '2') {
  110. let checked = item.checked ? '1' : '2';
  111. let index = findChecked(dataList, item.name);
  112. // 打点信息
  113. addMarkers(item);
  114. if (item.checked || (!item.checked && index === 0)) {
  115. rightMenuRef.value.updateMenu(
  116. checked,
  117. ['易涝隐患点', '无人机', '铁塔运行监测', '物资与装备', '通讯保障', '手机工作台'].includes(item.name) ? item : { name: '图层分析', meta: { icon: 'icon1' } }
  118. );
  119. }
  120. }
  121. };
  122. const findChecked = (dataList, name) => {
  123. let index = 0;
  124. dataList.forEach((item) => {
  125. if (item.name !== name && item.path === '2' && !!item.checked) {
  126. index++;
  127. }
  128. if (item.children && item.children.length > 0) {
  129. let res = findChecked(item.children, name);
  130. index += res;
  131. }
  132. });
  133. return index;
  134. };
  135. // 点击搜索结果,添加标注
  136. const selectSearchMarker = (item) => {
  137. const dom = activeMap.value === 'satellite2' ? map2Ref.value : mapRef.value;
  138. let item2 = deepClone(item);
  139. if (iconList[item.component]) {
  140. item2.image = iconList[item.component].image;
  141. item2.size = iconList[item.component].size;
  142. }
  143. dom.addSearchMarker(item2);
  144. };
  145. const handleAnalysisData = (data) => {
  146. rightMenuRef.value.handleMenu('空间分析', data);
  147. };
  148. // 获取地图元素操作
  149. const getMap = () => {
  150. if (['satellite2', 'satellite3'].includes(activeMap.value)) {
  151. return map2Ref.value.getMap();
  152. } else if (['vectorgraph', 'satellite'].includes(activeMap.value)) {
  153. return mapRef.value.getMap();
  154. }
  155. return {};
  156. };
  157. const showDetail = (data, dataType) => {
  158. if (['satellite2', 'satellite3'].includes(activeMap.value)) {
  159. return map2Ref.value.handleHover(data, dataType);
  160. } else if (['vectorgraph', 'satellite'].includes(activeMap.value)) {
  161. return mapRef.value.handleHover(data, dataType);
  162. }
  163. return {};
  164. };
  165. const getDrawTool = () => {
  166. if (['satellite2', 'satellite3'].includes(activeMap.value)) {
  167. return map2Ref.value.drawTool;
  168. } else if (['vectorgraph', 'satellite'].includes(activeMap.value)) {
  169. return mapRef.value.drawTool;
  170. }
  171. return {};
  172. };
  173. const getMarkers = () => {
  174. if (['satellite2', 'satellite3'].includes(activeMap.value)) {
  175. return map2Ref.value.getMarkers();
  176. } else if (['vectorgraph', 'satellite'].includes(activeMap.value)) {
  177. return mapRef.value.getMarkers();
  178. }
  179. return {};
  180. };
  181. let showNearbyVideos = ref(false);
  182. let location = reactive([]);
  183. // 显示附近视频
  184. const handleShowVideo = (data) => {
  185. location = [data.longitude, data.latitude];
  186. showNearbyVideos.value = true;
  187. };
  188. let showWarehouse = ref(false);
  189. let warehouseData = ref('');
  190. const handleShowWarehouse = (data) => {
  191. warehouseData.value = data;
  192. showWarehouse.value = true;
  193. };
  194. // const handleResize = () => {
  195. // debugger
  196. // }
  197. // onMounted(() => {
  198. // mapRef.value.addEventListener('resize', handleResize);
  199. // })
  200. provide('getMap', getMap);
  201. provide('showDetail', showDetail);
  202. provide('getDrawTool', getDrawTool);
  203. provide('getMarkers', getMarkers);
  204. </script>
  205. <style lang="scss" scoped>
  206. #globalMap {
  207. width: 100%;
  208. height: 100%;
  209. }
  210. .global-map {
  211. width: 100%;
  212. height: 100%;
  213. position: relative;
  214. //overflow: hidden;
  215. .tool-box {
  216. position: absolute;
  217. right: 430px;
  218. bottom: 180px;
  219. z-index: 10;
  220. color: #fff;
  221. }
  222. }
  223. .box {
  224. position: absolute;
  225. top: 20px;
  226. right: 20px;
  227. width: 300px;
  228. background-color: #041d55;
  229. display: flex;
  230. flex-direction: column;
  231. padding: 20px;
  232. color: #fff;
  233. font-size: 16px;
  234. height: 500px;
  235. max-height: 90%;
  236. div {
  237. line-height: 30px;
  238. cursor: pointer;
  239. }
  240. }
  241. .fixed {
  242. position: fixed !important;
  243. }
  244. </style>