1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
| <template>
| <div ref="wrapRef" :style="{ height, width }"></div>
| </template>
| <script lang="ts" setup>
| import { ref, nextTick, unref, onMounted } from 'vue';
| import { useScript } from '@/hooks/web/useScript';
|
| defineOptions({ name: 'AMap' });
|
| defineProps({
| width: {
| type: String,
| default: '100%',
| },
| height: {
| type: String,
| default: 'calc(100vh - 78px)',
| },
| });
|
| const A_MAP_URL = 'https://webapi.amap.com/maps?v=2.0&key=d7bb98e7185300250dd5f918c12f484b';
|
| const wrapRef = ref<HTMLDivElement | null>(null);
| const { toPromise } = useScript({ src: A_MAP_URL });
|
| async function initMap() {
| await toPromise();
| await nextTick();
| const wrapEl = unref(wrapRef);
| if (!wrapEl) return;
| const AMap = (window as any).AMap;
| new AMap.Map(wrapEl, {
| zoom: 11,
| center: [116.397428, 39.90923],
| viewMode: '3D',
| });
| }
|
| onMounted(async () => {
| await initMap();
| });
| </script>
|
|