修改显示

main
suixy 2 months ago
parent 0bb0501166
commit 08776fc2d4

@ -1038,39 +1038,6 @@ const table1Current = (e, v) => {
console.log(e)
}
const getBoundingBoxAndSize = (points) => {
if (!points || points.length === 0) return null;
// 1.
let lons = points.map(p => p.lon);
let lats = points.map(p => p.lat);
let maxLon = Math.max(...lons);
let minLon = Math.min(...lons);
let maxLat = Math.max(...lats);
let minLat = Math.min(...lats);
// 2. ()
const R = 6371000; //
const toRad = d => d * Math.PI / 180;
let dLat = toRad(maxLat - minLat);
let dLon = toRad(maxLon - minLon);
//
let midLat = (maxLat + minLat) / 2;
let midLatRad = toRad(midLat);
// 3.
let height = dLat * R;
let width = dLon * R * Math.cos(midLatRad);
return {
maxLon, minLon, maxLat, minLat,
width: Math.abs(width),
height: Math.abs(height)
};
}
const options1 = ref([])
const options2 = ref([])
@ -1100,6 +1067,38 @@ const getArea2 = () => {
areaPoints.value = res.data
})
}
function getBoundingBoxAndSize(points) {
if (!points || points.length === 0) {
}
let maxLon = Math.max(...points.map(p => p.lon));
let minLon = Math.min(...points.map(p => p.lon));
let maxLat = Math.max(...points.map(p => p.lat));
let minLat = Math.min(...points.map(p => p.lat));
const R = 6371000;
const toRad = deg => deg * Math.PI / 180;
// Haversine
const haversineDistance = (lat1, lon1, lat2, lon2) => {
const dLat = toRad(lat2 - lat1);
const dLon = toRad(lon2 - lon1);
const a =
Math.sin(dLat / 2) ** 2 +
Math.cos(toRad(lat1)) * Math.cos(toRad(lat2)) * Math.sin(dLon / 2) ** 2;
const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
return R * c;
};
const width = haversineDistance(minLat, minLon, minLat, maxLon);
const height = haversineDistance(minLat, minLon, maxLat, minLon);
return {width, height};
}
const saveAreaPoint = () => {
let arr = []
areaPoints.value.forEach((v, k) => {
@ -1107,6 +1106,7 @@ const saveAreaPoint = () => {
})
Promise.all(arr).then(() => {
ElMessage.success('保存成功')
console.log(getBoundingBoxAndSize(areaPoints.value))
}).catch((err) => {
ElMessage.error(err)
})

Loading…
Cancel
Save