增加自动定位
This commit is contained in:
26
src/App.vue
26
src/App.vue
@@ -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)
|
||||
|
||||
|
||||
@@ -4,4 +4,5 @@ import vue from '@vitejs/plugin-vue'
|
||||
// https://vite.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [vue()],
|
||||
base: "/web/",
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user