App.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <template>
  2. <!-- <div>地图页面</div> -->
  3. <div ref="mapEl" class="map-container"></div>
  4. </template>
  5. <script setup lang="ts">
  6. import AMapLoader from "@amap/amap-jsapi-loader";
  7. import { onMounted, ref } from "vue";
  8. import axios from 'axios';
  9. import { getFuseCodeLink } from "../../view/case/help";
  10. const getQuery = (
  11. caseId: number,
  12. share: boolean = false,
  13. single: boolean = false
  14. ) =>
  15. `${getFuseCodeLink(caseId, true)}${share ? "&share=1" : ""}${single ? "&single=1" : ""
  16. }#show/summary`;
  17. const request = axios.create({
  18. baseURL: '',
  19. timeout: 1000,
  20. headers: {
  21. share: 1,
  22. 'Content-Type': 'application/json'
  23. },
  24. });
  25. const mapEl = ref<HTMLDivElement>();
  26. const getDataQuest = () => {
  27. return new Promise(async (reslove, reject) => {
  28. const res = await request.post('https://xj-mix3d.4dkankan.com/fusion-xj/web/fireProject/queryProject', {
  29. pageNum: 1,
  30. pageSize: 10000
  31. })
  32. console.log('res.data', res)
  33. if (res.status === 200 && res.data.code === 0) {
  34. reslove(res.data.data.list)
  35. } else {
  36. reslove([])
  37. }
  38. })
  39. }
  40. const loadMap = async () => {
  41. const AMap = await AMapLoader.load({
  42. plugins: ["AMap.PlaceSearch"],
  43. key: "e661b00bdf2c44cccf71ef6070ef41b8",
  44. version: "2.0",
  45. });
  46. const map = new AMap.Map(mapEl.value, {
  47. WebGLParams: {
  48. preserveDrawingBuffer: true,
  49. },
  50. resizeEnable: true,
  51. });
  52. //添加插件
  53. AMap.plugin(["AMap.ToolBar", "AMap.Scale", "AMap.HawkEye", 'AMap.MapType'], function () {
  54. //异步同时加载多个插件
  55. // map.addControl(new AMap.HawkEye()); //显示缩略图
  56. map.addControl(new AMap.Scale()); //显示当前地图中心的比例尺
  57. map.addControl(new AMap.MapType()); //显示当前地图中心的比例尺
  58. });
  59. console.log('map', map,)
  60. const initMakers = async () => {
  61. const data = await getDataQuest() as any as any[];
  62. console.log('data', data)
  63. Array.from(data).forEach((item: any) => {
  64. // console.log(item)
  65. const latlng = item.latlng
  66. const coord = latlng.split(',')
  67. console.log('coord', coord, item.caseId)
  68. const url = getQuery(item.caseId, true)
  69. console.log('url', url)
  70. const icon = new AMap.Icon({
  71. image: "//a.amap.com/jsapi_demos/static/demo-center/icons/poi-marker-default.png",
  72. size: new AMap.Size(22, 28), //图标所处区域大小
  73. imageSize: new AMap.Size(22, 28) //图标大小
  74. });
  75. const marker = new AMap.Marker({
  76. icon: icon,
  77. position: coord.reverse(),
  78. title: item.title,
  79. label: item.title,
  80. extData: { url: url, id: item.caseId }
  81. // offset: new AMap.Pixel(-26, -54),
  82. });
  83. marker.setMap(map);
  84. marker.on('click', () => {
  85. const data = marker.getExtData()
  86. window.open(data.url)
  87. console.log('click', data)
  88. })
  89. })
  90. }
  91. initMakers();
  92. };
  93. onMounted(loadMap);
  94. </script>
  95. <style>
  96. body {
  97. padding: 0;
  98. margin: 0;
  99. }
  100. .map-container {
  101. width: 100%;
  102. height: 100vh;
  103. }
  104. </style>