index.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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. interface Props {
  32. isComponent?: boolean;
  33. width?: string;
  34. height?: string;
  35. }
  36. const props = withDefaults(defineProps<Props>(), {
  37. isComponent: false
  38. });
  39. const rightMenuRef = ref(null);
  40. const mapData = reactive(logicalData);
  41. let mapRef = ref(null);
  42. let map2Ref = ref(null);
  43. // logical vectorgraph satellite satellite2 satellite3
  44. let activeMap = ref('vectorgraph');
  45. const switchMap = (key) => {
  46. activeMap.value = key;
  47. };
  48. let pointType = ref<PointType[]>([]);
  49. let markerList = ref([]);
  50. const addMarkers = (item) => {
  51. const dom = activeMap.value === 'satellite2' ? map2Ref.value : mapRef.value;
  52. if (dom) {
  53. if (!item.checked) {
  54. let index = pointType.value.findIndex((item2) => item.component === item2.component);
  55. if (index > -1) {
  56. pointType.value.splice(index, 1);
  57. }
  58. if (pointType.value && pointType.value.length === 0) {
  59. dom.clearMarker('point');
  60. return;
  61. }
  62. } else {
  63. // 右侧图层分析状态
  64. item.checked2 = true;
  65. pointType.value.push(item);
  66. }
  67. let path = [];
  68. pointType.value.forEach((item) => {
  69. path.push(item.component);
  70. });
  71. getPointInfo(path.toString()).then((res) => {
  72. const data = res.data && res.data.list ? res.data?.list : [];
  73. markerList.value = data;
  74. data.forEach((item2) => {
  75. // 获取图标
  76. if (iconList[item2.dataType]) {
  77. item2.image = iconList[item2.dataType].image;
  78. item2.size = iconList[item2.dataType].size;
  79. } else {
  80. item2.image = iconList['common'].image;
  81. item2.size = iconList['common'].size;
  82. }
  83. if (item2.materia_name) {
  84. item2.name = item2.materia_name;
  85. }
  86. item2.parentId = item.component;
  87. item2.lnglat = [item2.longitude, item2.latitude];
  88. });
  89. dom.addMarker(data);
  90. });
  91. } else {
  92. item.checked = !item.checked;
  93. }
  94. };
  95. // 跳转指定地点
  96. const toAddress = (item) => {
  97. const dom = activeMap.value === 'satellite2' ? map2Ref.value : mapRef.value;
  98. dom.setCenter(item);
  99. };
  100. let showDrawTools = ref(false);
  101. // 右侧菜单
  102. // 点击菜单
  103. const clickMenu = (item) => {
  104. if (item.path === '1') {
  105. // 空间分析
  106. if (item.component === 'spatial') {
  107. showDrawTools.value = !showDrawTools.value;
  108. }
  109. rightMenuRef.value.updateMenu(item.checked ? '1' : '2', item);
  110. } else if (item.path === '2') {
  111. // 打点信息
  112. addMarkers(item);
  113. rightMenuRef.value.handleMenu('图层分析');
  114. }
  115. };
  116. // 点击搜索结果,添加标注
  117. const selectSearchMarker = (item) => {
  118. const dom = activeMap.value === 'satellite2' ? map2Ref.value : mapRef.value;
  119. let item2 = deepClone(item);
  120. if (iconList[item.component]) {
  121. item2.image = iconList[item.component].image;
  122. item2.size = iconList[item.component].size;
  123. }
  124. dom.addSearchMarker(item2);
  125. };
  126. // 获取地图元素操作
  127. const getMap = () => {
  128. if (['satellite2', 'satellite3'].includes(activeMap.value)) {
  129. return map2Ref.value.getMap();
  130. } else if (['vectorgraph', 'satellite'].includes(activeMap.value)) {
  131. return mapRef.value.getMap();
  132. }
  133. return {};
  134. };
  135. const getDrawTool = () => {
  136. if (['satellite2', 'satellite3'].includes(activeMap.value)) {
  137. return map2Ref.value.drawTool;
  138. } else if (['vectorgraph', 'satellite'].includes(activeMap.value)) {
  139. return mapRef.value.drawTool;
  140. }
  141. return {};
  142. };
  143. provide('getMap', getMap);
  144. provide('getDrawTool', getDrawTool);
  145. </script>
  146. <style lang="scss" scoped>
  147. #globalMap {
  148. width: 100%;
  149. height: 100%;
  150. }
  151. .bg {
  152. background: url('@/assets/images/bg.jpg') no-repeat 100% 100%;
  153. background-size: cover;
  154. }
  155. .global-map {
  156. width: 100%;
  157. height: 100%;
  158. position: relative;
  159. //overflow: hidden;
  160. .tool-box {
  161. position: absolute;
  162. right: 170px;
  163. bottom: 50px;
  164. z-index: 10;
  165. color: #fff;
  166. }
  167. }
  168. .box {
  169. position: absolute;
  170. top: 20px;
  171. right: 20px;
  172. width: 300px;
  173. background-color: #041d55;
  174. display: flex;
  175. flex-direction: column;
  176. padding: 20px;
  177. color: #fff;
  178. font-size: 16px;
  179. height: 500px;
  180. max-height: 90%;
  181. div {
  182. line-height: 30px;
  183. cursor: pointer;
  184. }
  185. }
  186. .fixed {
  187. position: fixed !important;
  188. }
  189. </style>