index.vue 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <template>
  2. <view id="container" class=""></view>
  3. </template>
  4. <script>
  5. import 'ol/ol.css';
  6. import {
  7. Map,
  8. View
  9. } from 'ol';
  10. import TileLayer from 'ol/layer/Tile';
  11. import OSM from 'ol/source/OSM';
  12. const getUserInfo = () => {
  13. apiUserInfo().then(res => {
  14. console.log(res);
  15. userinfo.value = res.data
  16. })
  17. }
  18. let map: any = null
  19. export default {
  20. name: "map-view",
  21. data() {
  22. return {
  23. }
  24. },
  25. mounted() {
  26. this.initAMap();
  27. // this.initMap();
  28. },
  29. unmounted() {
  30. map && map.destroy();
  31. },
  32. methods: {
  33. initAMap() {
  34. map = new AMap.Map("container", {
  35. viewMode: "3D", // 是否为3D地图模式
  36. zoom: 11,
  37. center: [116.397428, 39.90923],
  38. });
  39. // 设置离线地图
  40. map.setPlugins({
  41. 'AMap.Offline': {}
  42. });
  43. // 添加离线地图数据
  44. map.offline.setCity('北京');
  45. },
  46. initMap() {
  47. // 创建地图实例
  48. map = new Map({
  49. target: 'container',
  50. layers: [
  51. new TileLayer({
  52. source: new OSM()
  53. })
  54. ],
  55. view: new View({
  56. center: [0, 0], // 地图中心点坐标
  57. zoom: 2 // 缩放级别
  58. })
  59. });
  60. }
  61. },
  62. };
  63. </script>
  64. <style scoped>
  65. #container {
  66. width: 100%;
  67. height: 100vh;
  68. }
  69. </style>