App.vue 2.8 KB

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