index.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. <template>
  2. <div id="globalMap">
  3. <div :class="isComponent ? 'global-map' : 'global-map bg'">
  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" :pointType="pointType" />
  7. <Map v-else ref="mapRef" :active-map="activeMap" :pointType="pointType" />
  8. <!--左侧菜单-->
  9. <LeftMenu style="position: absolute; top: 20px; left: 20px" @click-menu="clickMenu" @select-search-marker="selectSearchMarker" />
  10. <!--右侧菜单-->
  11. <RightMenu ref="rightMenuRef" :pointType="pointType" />
  12. <!--更换地图类型-->
  13. <SwitchMapTool :active-map="activeMap" class="tool-box" @switch-map="switchMap" />
  14. <!--时间轴-->
  15. <TimeAxis />
  16. </div>
  17. </div>
  18. </template>
  19. <script lang="ts" setup name="globalMap">
  20. import Map from '@/components/Map/index.vue';
  21. import YztMap from '@/components/Map/YztMap/index.vue';
  22. import MapLogical from '@/components/Map/MapLogical.vue';
  23. import { iconList, logicalData } from './data/mapData';
  24. import SwitchMapTool from '@/views/globalMap/SwitchMapTool.vue';
  25. import LeftMenu from './LeftMenu.vue';
  26. import TimeAxis from '@/components/TimeAxis/index.vue';
  27. import { deepClone } from '@/utils';
  28. import { getPointInfo } from '@/api/globalMap';
  29. import RightMenu from './RightMenu/index.vue';
  30. import { PointType } from '@/api/globalMap/type';
  31. import { c } from 'vite/dist/node/types.d-aGj9QkWt';
  32. interface Props {
  33. isComponent?: boolean;
  34. width?: string;
  35. height?: string;
  36. }
  37. const props = withDefaults(defineProps<Props>(), {
  38. isComponent: false
  39. });
  40. const rightMenuRef = ref(null);
  41. const mapData = reactive(logicalData);
  42. let mapRef = ref(null);
  43. let map2Ref = ref(null);
  44. // logical vectorgraph satellite satellite2 satellite3
  45. let activeMap = ref('vectorgraph');
  46. const switchMap = (key) => {
  47. activeMap.value = key;
  48. };
  49. let pointType = ref<PointType[]>([]);
  50. let markerList = ref([]);
  51. const addMarkers = (item) => {
  52. const dom = activeMap.value === 'satellite2' ? map2Ref.value : mapRef.value;
  53. if (dom) {
  54. if (!item.checked) {
  55. let index = pointType.value.findIndex((item2) => item.component === item2.component);
  56. if (index > -1) {
  57. pointType.value.splice(index, 1);
  58. }
  59. if (pointType.value && pointType.value.length === 0) {
  60. dom.clearMarker('point');
  61. return;
  62. }
  63. } else {
  64. // 右侧图层分析状态
  65. item.checked2 = true;
  66. pointType.value.push(item);
  67. }
  68. let path = [];
  69. pointType.value.forEach((item) => {
  70. path.push(item.component);
  71. });
  72. getPointInfo(path.toString()).then((res) => {
  73. const data = res.data && res.data.list ? res.data?.list : [];
  74. markerList.value = data;
  75. data.forEach((item2) => {
  76. // 获取图标
  77. if (iconList[item2.dataType]) {
  78. item2.image = iconList[item2.dataType].image;
  79. item2.size = iconList[item2.dataType].size;
  80. } else {
  81. item2.image = iconList['common'].image;
  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. } else {
  93. item.checked = !item.checked;
  94. }
  95. };
  96. // 跳转指定地点
  97. const toAddress = (item) => {
  98. const dom = activeMap.value === 'satellite2' ? map2Ref.value : mapRef.value;
  99. dom.setCenter(item);
  100. };
  101. let showDrawTools = ref(false);
  102. // 右侧菜单
  103. // 点击菜单
  104. const clickMenu = (item, dataList) => {
  105. if (item.path === '1') {
  106. // 空间分析
  107. if (item.component === 'spatial') {
  108. showDrawTools.value = !showDrawTools.value;
  109. }
  110. rightMenuRef.value.updateMenu(item.checked ? '1' : '2', item);
  111. } else if (item.path === '2') {
  112. let checked = item.checked ? '1' : '2';
  113. let index = findChecked(dataList, item.name);
  114. // 打点信息
  115. addMarkers(item);
  116. if (item.checked || (!item.checked && index === 0)) {
  117. rightMenuRef.value.updateMenu(checked, ['易涝隐患点'].includes(item.name) ? item : { name: '图层分析', meta: { icon: 'icon1' } });
  118. }
  119. }
  120. };
  121. const findChecked = (dataList, name) => {
  122. let index = 0;
  123. dataList.forEach((item) => {
  124. if (item.name !== name && item.path === '2' && !!item.checked) {
  125. index++;
  126. }
  127. if (item.children && item.children.length > 0) {
  128. let res = findChecked(item.children, name);
  129. index += res;
  130. }
  131. });
  132. return index;
  133. };
  134. // 点击搜索结果,添加标注
  135. const selectSearchMarker = (item) => {
  136. const dom = activeMap.value === 'satellite2' ? map2Ref.value : mapRef.value;
  137. let item2 = deepClone(item);
  138. if (iconList[item.component]) {
  139. item2.image = iconList[item.component].image;
  140. item2.size = iconList[item.component].size;
  141. }
  142. dom.addSearchMarker(item2);
  143. };
  144. // 获取地图元素操作
  145. const getMap = () => {
  146. if (['satellite2', 'satellite3'].includes(activeMap.value)) {
  147. return map2Ref.value.getMap();
  148. } else if (['vectorgraph', 'satellite'].includes(activeMap.value)) {
  149. return mapRef.value.getMap();
  150. }
  151. return {};
  152. };
  153. const getDrawTool = () => {
  154. if (['satellite2', 'satellite3'].includes(activeMap.value)) {
  155. return map2Ref.value.drawTool;
  156. } else if (['vectorgraph', 'satellite'].includes(activeMap.value)) {
  157. return mapRef.value.drawTool;
  158. }
  159. return {};
  160. };
  161. provide('getMap', getMap);
  162. provide('getDrawTool', getDrawTool);
  163. </script>
  164. <style lang="scss" scoped>
  165. #globalMap {
  166. width: 100%;
  167. height: 100%;
  168. }
  169. .bg {
  170. background: url('@/assets/images/bg.jpg') no-repeat 100% 100%;
  171. background-size: cover;
  172. }
  173. .global-map {
  174. width: 100%;
  175. height: 100%;
  176. position: relative;
  177. //overflow: hidden;
  178. .tool-box {
  179. position: absolute;
  180. right: 170px;
  181. bottom: 50px;
  182. z-index: 10;
  183. color: #fff;
  184. }
  185. }
  186. .box {
  187. position: absolute;
  188. top: 20px;
  189. right: 20px;
  190. width: 300px;
  191. background-color: #041d55;
  192. display: flex;
  193. flex-direction: column;
  194. padding: 20px;
  195. color: #fff;
  196. font-size: 16px;
  197. height: 500px;
  198. max-height: 90%;
  199. div {
  200. line-height: 30px;
  201. cursor: pointer;
  202. }
  203. }
  204. .fixed {
  205. position: fixed !important;
  206. }
  207. </style>