|
|
|
|
@ -762,6 +762,55 @@ const setItemsId = (e) => {
|
|
|
|
|
const locationData = ref({})
|
|
|
|
|
const currentPosition = ref({})
|
|
|
|
|
|
|
|
|
|
function calcRectangleFromPoints(points) {
|
|
|
|
|
if (!points || points.length !== 4) throw new Error("必须传入四个点");
|
|
|
|
|
|
|
|
|
|
const R = 111320;
|
|
|
|
|
const lat0 = points.reduce((a, b) => a + b.lat, 0) / 4;
|
|
|
|
|
const cosLat = Math.cos((lat0 * Math.PI) / 180);
|
|
|
|
|
|
|
|
|
|
// 经纬度转平面坐标
|
|
|
|
|
const toXY = p => ({
|
|
|
|
|
name: p.name,
|
|
|
|
|
x: p.lon * R * cosLat,
|
|
|
|
|
y: p.lat * R
|
|
|
|
|
});
|
|
|
|
|
const [p1, p2, p3, p4] = points.map(toXY);
|
|
|
|
|
|
|
|
|
|
// 距离函数
|
|
|
|
|
const dist = (a, b) => Math.sqrt((a.x - b.x) ** 2 + (a.y - b.y) ** 2);
|
|
|
|
|
|
|
|
|
|
// 各边长度
|
|
|
|
|
const top = dist(p2, p3);
|
|
|
|
|
const bottom = dist(p1, p4);
|
|
|
|
|
const left = dist(p4, p3);
|
|
|
|
|
const right = dist(p1, p2);
|
|
|
|
|
|
|
|
|
|
// 判断梯形:上下边差异超过5%
|
|
|
|
|
const trapezoid = Math.abs(top - bottom) / Math.max(top, bottom) > 0.05;
|
|
|
|
|
|
|
|
|
|
let width, height;
|
|
|
|
|
|
|
|
|
|
if (trapezoid) {
|
|
|
|
|
// 使用平均宽高
|
|
|
|
|
width = (top + bottom) / 2;
|
|
|
|
|
height = (left + right) / 2;
|
|
|
|
|
} else {
|
|
|
|
|
width = bottom;
|
|
|
|
|
height = right;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 计算旋转角度(p1→p2)
|
|
|
|
|
const angle = Math.atan2(p2.y - p1.y, p2.x - p1.x) * 180 / Math.PI;
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
width: width.toFixed(2),
|
|
|
|
|
height: height.toFixed(2),
|
|
|
|
|
angle: angle.toFixed(2)
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function getXYDistanceFromMin(current, minPoint) {
|
|
|
|
|
const R = 6371000; // 地球半径(米)
|
|
|
|
|
@ -1229,15 +1278,16 @@ const saveAreaPoint = () => {
|
|
|
|
|
})
|
|
|
|
|
Promise.all(arr).then(() => {
|
|
|
|
|
ElMessage.success('保存成功')
|
|
|
|
|
let data = getBoundingBoxAndSize(areaPoints.value)
|
|
|
|
|
// let data = getBoundingBoxAndSize(areaPoints.value)
|
|
|
|
|
let data = calcRectangleFromPoints(areaPoints.value)
|
|
|
|
|
console.log(data)
|
|
|
|
|
areaData.value = data
|
|
|
|
|
area = {
|
|
|
|
|
"LatMin": data.minLat,
|
|
|
|
|
"LatMax": data.maxLat,
|
|
|
|
|
"LonMin": data.minLon,
|
|
|
|
|
"LonMax": data.maxLon
|
|
|
|
|
}
|
|
|
|
|
// areaData.value = data
|
|
|
|
|
// area = {
|
|
|
|
|
// "LatMin": data.minLat,
|
|
|
|
|
// "LatMax": data.maxLat,
|
|
|
|
|
// "LonMin": data.minLon,
|
|
|
|
|
// "LonMax": data.maxLon
|
|
|
|
|
// }
|
|
|
|
|
}).catch((err) => {
|
|
|
|
|
ElMessage.error(err)
|
|
|
|
|
})
|
|
|
|
|
|