vue3中使用天地图三维服务
时间: 2023-11-12 10:14:18 浏览: 194
要在Vue3中使用天地图三维服务,你需要进行以下步骤:
1. 在index.html文件中添加天地图API的引用:
```html
<script src="http://api.tianditu.gov.cn/api/js4.0/3dmap/init3dmap.js"></script>
```
2. 在Vue3组件中引用天地图API,并创建地图对象:
```javascript
import { ref, onMounted } from 'vue';
export default {
name: 'MapComponent',
setup() {
const map = ref(null);
onMounted(() => {
const options = {
center: new TMap.LngLat(116.40769, 39.89945),
zoom: 16,
pitch: 45,
viewMode: "3D",
mapType: TMAP_NORMAL_MAP,
};
map.value = new TMap.Map("map", options);
});
return { map };
},
};
```
3. 在Vue3模板中,使用id为“map”的div元素来显示地图:
```html
<template>
<div id="map" style="width: 100%; height: 100vh;"></div>
</template>
```
这样就可以在Vue3中使用天地图三维服务了。你可以根据自己的需求,修改地图的选项和样式。
阅读全文
相关推荐
















