修改显示

main
suixy 2 months ago
parent 0db01fa839
commit 2c2bffed3d

@ -762,6 +762,55 @@ const setItemsId = (e) => {
const locationData = ref({}) const locationData = ref({})
const currentPosition = 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;
}
// p1p2
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) { function getXYDistanceFromMin(current, minPoint) {
const R = 6371000; // const R = 6371000; //
@ -1229,15 +1278,16 @@ const saveAreaPoint = () => {
}) })
Promise.all(arr).then(() => { Promise.all(arr).then(() => {
ElMessage.success('保存成功') ElMessage.success('保存成功')
let data = getBoundingBoxAndSize(areaPoints.value) // let data = getBoundingBoxAndSize(areaPoints.value)
let data = calcRectangleFromPoints(areaPoints.value)
console.log(data) console.log(data)
areaData.value = data // areaData.value = data
area = { // area = {
"LatMin": data.minLat, // "LatMin": data.minLat,
"LatMax": data.maxLat, // "LatMax": data.maxLat,
"LonMin": data.minLon, // "LonMin": data.minLon,
"LonMax": data.maxLon // "LonMax": data.maxLon
} // }
}).catch((err) => { }).catch((err) => {
ElMessage.error(err) ElMessage.error(err)
}) })

Loading…
Cancel
Save