diff --git a/.gitignore b/.gitignore index a547bf3..8c3f000 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,4 @@ dist-ssr *.njsproj *.sln *.sw? +.marscode \ No newline at end of file diff --git a/package.json b/package.json index c0adada..6272289 100644 --- a/package.json +++ b/package.json @@ -10,9 +10,10 @@ }, "dependencies": { "@amap/amap-jsapi-loader": "^1.0.1", - "DroneCtrl": "1.0.0", + "DroneCtrl": "1.0.1", "axios": "^1.13.2", "element-plus": "^2.12.0", + "gcoord": "^1.0.7", "vue": "^3.5.24" }, "devDependencies": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 2690139..d9adf3f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -15,14 +15,17 @@ importers: specifier: ^1.0.1 version: 1.0.1 DroneCtrl: - specifier: 1.0.0 - version: 1.0.0 + specifier: 1.0.1 + version: 1.0.1 axios: specifier: ^1.13.2 version: 1.13.2 element-plus: specifier: ^2.12.0 version: 2.12.0(vue@3.5.25) + gcoord: + specifier: ^1.0.7 + version: 1.0.7 vue: specifier: ^3.5.24 version: 3.5.25 @@ -201,7 +204,7 @@ packages: resolution: {integrity: sha512-iHmwV3QcVGGvSC1BG5bZ4z6iwa1SOpAPWmnjOErd4Ske+lZua5K9TtAVdx0gMBClJ28DViCbSmZitjWZsWO3LA==} engines: {node: ^20.19.0 || >=22.12.0} peerDependencies: - vite: npm:rolldown-vite@7.2.5 + vite: ^5.0.0 || ^6.0.0 || ^7.0.0 vue: ^3.2.25 '@vue/compiler-core@3.5.25': @@ -242,8 +245,8 @@ packages: '@vueuse/shared@9.13.0': resolution: {integrity: sha512-UrnhU+Cnufu4S6JLCPZnkWh0WwZGUp72ktOF2DFptMlOs3TOdVv8xJN53zhHGARmVOsz5KqOls09+J1NR6sBKw==} - DroneCtrl@1.0.0: - resolution: {integrity: sha512-V3WFJas+oJEv1tG41pbHg3gnG5KdSG7VmL6V3xB+G0PtztHwekTHdNAHcx10rR2mbIFB5ITYGIU3HskOAGvkbA==} + DroneCtrl@1.0.1: + resolution: {integrity: sha512-3ibzb0sXZGXAkbSTg4Zb8heTx6ASBkWaI2yAO8V+4/Y2ygULruPCzb8o3c89wWlnfQQ/AALWlNmkpVV/ezBujQ==} async-validator@4.2.5: resolution: {integrity: sha512-7HhHjtERjqlNbZtqNqy2rckN/SpOOlmDliet+lP7k+eKZEjPk3DgyeU9lIXLdeLz0uBbbVp+9Qdow9wJWgwwfg==} @@ -338,6 +341,10 @@ packages: function-bind@1.1.2: resolution: {integrity: sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==} + gcoord@1.0.7: + resolution: {integrity: sha512-UCN2iSm69jBOYz2ma2eg5I5imp65Cj70rcTTfMNSNMvZpR1U6oGjmVh080aCvC/6lN1ClkuOoBeaLuebw9AZJg==} + engines: {node: '>=16.11.0'} + get-intrinsic@1.3.0: resolution: {integrity: sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==} engines: {node: '>= 0.4'} @@ -763,7 +770,7 @@ snapshots: - '@vue/composition-api' - vue - DroneCtrl@1.0.0: {} + DroneCtrl@1.0.1: {} async-validator@4.2.5: {} @@ -858,6 +865,8 @@ snapshots: function-bind@1.1.2: {} + gcoord@1.0.7: {} + get-intrinsic@1.3.0: dependencies: call-bind-apply-helpers: 1.0.2 diff --git a/src/App.vue b/src/App.vue index d459c09..1b478b0 100644 --- a/src/App.vue +++ b/src/App.vue @@ -136,11 +136,12 @@ import { ElMessage, ElMessageBox } from 'element-plus' import { WebSocketClient, MockWebSocketDataGenerator } from './utils/websocket.js' import droneImage from './assets/wrj.jpg' import { getConfig } from ".//utils/request"; +import gcoord from 'gcoord'; import DroneCtrl, { UploadAreaReq } from 'DroneCtrl'; -const ctrl = new DroneCtrl.default(getConfig()); +const ctrl = new DroneCtrl(getConfig()); // 地图相关 const mapContainer = ref(null) @@ -180,10 +181,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) @@ -338,7 +361,7 @@ const updateDroneMarker = (lng, lat, heading = 0) => { } // 将地图中心移动到无人机位置(可选,可以注释掉) - // map.setCenter([lng, lat]) + map.setCenter([lng, lat]) } // 检测点是否在多边形内(射线法) @@ -875,7 +898,16 @@ const uploadFence = (fenceId) => { } if (pointsData) { - const points = pointsData.points; + const points = pointsData.points.map(point=> { + const wgsPoint = gcoord.transform( + point, // 原始坐标 + gcoord.GCJ02, // 当前坐标系 + gcoord.WGS84 // 目标坐标系 + ); + return wgsPoint; + }); + console.log(points) + ctrl.UploadArea(new UploadAreaReq(points.map(point=>({ longitude: point[0], latitude: point[1], @@ -945,6 +977,7 @@ const removeFence = (fenceId) => { console.error('删除围栏时出错:', error) } } + ctrl.ClearArea({}); // 从列表中移除 fences.value.splice(index, 1) @@ -982,6 +1015,7 @@ const clearAllFences = async () => { type: 'warning', } ) + await ctrl.ClearArea({}); // 先清除地图上的所有图形 const fencesToRemove = [...fences.value] // 创建副本避免遍历时修改数组 diff --git a/vite.config.js b/vite.config.js index bbcf80c..01fe5bd 100644 --- a/vite.config.js +++ b/vite.config.js @@ -4,4 +4,5 @@ import vue from '@vitejs/plugin-vue' // https://vite.dev/config/ export default defineConfig({ plugins: [vue()], + base: "/web/", })