Merge branch 'main' of ssh://git.wash-painting.cn:2222/cg/-----
This commit is contained in:
42
src/App.vue
42
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] // 创建副本避免遍历时修改数组
|
||||
|
||||
Reference in New Issue
Block a user