|
|
|
|
@ -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)
|
|
|
|
|
})
|
|
|
|
|
|