增加自动定位

This commit is contained in:
2025-12-07 18:48:40 +08:00
parent 478642e780
commit 0a7a594149
2 changed files with 25 additions and 2 deletions

View File

@@ -132,7 +132,7 @@ import DroneCtrl, {
UploadAreaReq
} from 'DroneCtrl';
const ctrl = new DroneCtrl.default(getConfig());
const ctrl = new DroneCtrl(getConfig());
// 地图相关
const mapContainer = ref(null)
@@ -171,10 +171,32 @@ const initMap = async () => {
map = new AMap.Map('map-container', {
viewMode: '3D',
zoom: 13,
center: [116.397428, 39.90923], // 默认北京天安门
// center: [116.397428, 39.90923], // 默认北京天安门
mapStyle: 'amap://styles/normal'
})
AMap.plugin('AMap.Geolocation', function () {
// 插件加载完成后才能使用
const geolocation = new AMap.Geolocation({
enableHighAccuracy: true,
timeout: 10000,
maximumAge: 0,
convert: true,
showButton: false
});
map.addControl(geolocation);
// 获取当前位置
geolocation.getCurrentPosition(function (status, result) {
if (status === 'complete') {
console.log('定位成功:', result.position.lng, result.position.lat);
} else {
console.error('定位失败:', result);
}
});
});
// 创建鼠标工具实例
mouseTool = new AMap.MouseTool(map)

View File

@@ -4,4 +4,5 @@ import vue from '@vitejs/plugin-vue'
// https://vite.dev/config/
export default defineConfig({
plugins: [vue()],
base: "/web/",
})