This commit is contained in:
duanxiaohai 2024-08-07 11:19:31 +08:00
parent 135723f2e6
commit 87323e6cc4
1 changed files with 97 additions and 35 deletions

View File

@ -610,9 +610,10 @@ const tsbqTotal = ref([
]); ]);
const data = reactive({ const data = reactive({
serviceCircleList: [], serviceCircleList: [],
fwqCoordinates: "", // fwqCoordinates: [], //
fwqCoordinates1: [], // fwqCoordinates1: [], //
fwqCoordinates2: [], // fwqCoordinates2: [], //
zoomLevel: null, //
}); });
// //
const jbfwqTotal = ref([ const jbfwqTotal = ref([
@ -1946,12 +1947,12 @@ const getFwq = () => {
jbfwqTotal.value.push({ jbfwqTotal.value.push({
name: item.xzjd, name: item.xzjd,
child: [], child: [],
}) });
item.csqs.forEach((item2) => { item.csqs.forEach((item2) => {
jbfwqTotal.value[index].child.push({ jbfwqTotal.value[index].child.push({
name: item2.csq, name: item2.csq,
jc:item2.jc jc: item2.jc,
}) });
}); });
}); });
} }
@ -1983,7 +1984,7 @@ const changeFwq = async (id, name, names) => {
map.clearOverlays(); // map.clearOverlays(); //
addggfwq(); // addggfwq(); //
setTimeout(() => { setTimeout(() => {
goMapCenter([data.fwqCoordinates1, data.fwqCoordinates2], 16); // goMapCenter([data.fwqCoordinates1, data.fwqCoordinates2], data.zoomLevel); //
}, 500); }, 500);
} else { } else {
ElMessage.warning("无数据"); ElMessage.warning("无数据");
@ -2003,18 +2004,40 @@ const getServiceCircle = async (communityName, townName) => {
console.error("Error fetching data:", error); console.error("Error fetching data:", error);
} }
}; };
// //
const addggfwq = () => { const calculateCenterPoint = (coordinates) => {
if (fwqList.value.length !== 0) { if (coordinates.length === 0) {
data.fwqCoordinates1 = []; return null;
data.fwqCoordinates2 = []; }
fwqList.value.map((item, index) => {
data.fwqCoordinates1.push(item.point[0]); let x = 0.0;
data.fwqCoordinates2.push(item.point[1]); let y = 0.0;
createCustomOverlay(item, index); let z = 0.0;
coordinates.forEach((coord) => {
const lat = (parseFloat(coord[1]) * Math.PI) / 180;
const lon = (parseFloat(coord[0]) * Math.PI) / 180;
x += Math.cos(lat) * Math.cos(lon);
y += Math.cos(lat) * Math.sin(lon);
z += Math.sin(lat);
}); });
// console.log("", data.fwqCoordinates1, data.fwqCoordinates2);
function calculateAverage(coordinates) { const total = coordinates.length;
x /= total;
y /= total;
z /= total;
const centralLon = Math.atan2(y, x);
const centralSquareRoot = Math.sqrt(x * x + y * y);
const centralLat = Math.atan2(z, centralSquareRoot);
return [
((centralLon * 180) / Math.PI).toFixed(6), //
((centralLat * 180) / Math.PI).toFixed(6), //
];
};
const calculateAverage = (coordinates) => {
// const numericCoordinates = coordinates.map(Number); // // const numericCoordinates = coordinates.map(Number); //
const numericCoordinates = coordinates.map((coord) => { const numericCoordinates = coordinates.map((coord) => {
// 使 // 使
@ -2023,28 +2046,67 @@ const addggfwq = () => {
}); });
const sum = numericCoordinates.reduce((acc, val) => acc + val, 0); // const sum = numericCoordinates.reduce((acc, val) => acc + val, 0); //
const average = sum / numericCoordinates.length; // const average = sum / numericCoordinates.length; //
return parseFloat(average.toFixed(5)); // 5 // console.log(average, "");
}
data.fwqCoordinates1 = calculateAverage(data.fwqCoordinates1); return parseFloat(average.toFixed(5)); // 5
data.fwqCoordinates2 = calculateAverage(data.fwqCoordinates2); };
//
const calculateZoomLevel = (maxDistance) => {
//
if (maxDistance < 151) return 18;
if (maxDistance < 400) return 17;
if (maxDistance < 600) return 17.5;
if (maxDistance < 1000) return 16;
if (maxDistance < 2000) return 15;
if (maxDistance < 3000) return 14;
if (maxDistance < 5000) return 13;
return 13;
};
//
const addggfwq = () => {
if (fwqList.value.length !== 0) {
data.fwqCoordinates = [];
// data.fwqCoordinates1 = [];
// data.fwqCoordinates2 = [];
fwqList.value.map((item, index) => {
data.fwqCoordinates.push(item.point);
// data.fwqCoordinates1.push(item.point[0]);
// data.fwqCoordinates2.push(item.point[1]);
createCustomOverlay(item, index);
});
const centerPoint = calculateCenterPoint(data.fwqCoordinates);
data.fwqCoordinates1 = centerPoint[0];
data.fwqCoordinates2 = centerPoint[1];
// data.fwqCoordinates1 = calculateAverage(data.fwqCoordinates1);
// data.fwqCoordinates2 = calculateAverage(data.fwqCoordinates2);
// console.log(centerPoint); //
// console.log("", data.fwqCoordinates1, data.fwqCoordinates2 );
let distances = []; // let distances = []; //
fwqList.value.forEach((item) => { fwqList.value.forEach((item) => {
// let distance = algorithm(
// (item.point[0] = Number(item.point[0].replace(/[^0-9.-]/g, ""))),
// (item.point[1] = Number(item.point[1].replace(/[^0-9.-]/g, ""))),
// data.fwqCoordinates1,
// data.fwqCoordinates2
// );
let distance = algorithm( let distance = algorithm(
(item.point[0] = Number(item.point[0].replace(/[^0-9.-]/g, ""))), Number(item.point[0].replace(/[^0-9.-]/g, "")),
(item.point[1] = Number(item.point[1].replace(/[^0-9.-]/g, ""))), Number(item.point[1].replace(/[^0-9.-]/g, "")),
data.fwqCoordinates1, Number(centerPoint[0]),
data.fwqCoordinates2 Number(centerPoint[1])
); );
distances.push(distance); // distances.push(distance); //
}); });
let maxDistance = Math.max(...distances); // let maxDistance = Math.max(...distances); //
maxDistance = Math.ceil(maxDistance * 1.8); // maxDistance = Math.ceil(maxDistance * 2.2); //
if (maxDistance < 100) { if (maxDistance < 100) {
maxDistance = 150; // 100 150 maxDistance = 150; // 100 150
} }
console.log("最大距离:", maxDistance); data.zoomLevel = calculateZoomLevel(maxDistance);
// console.log(":", maxDistance,data.zoomLevel);
drawACircle(maxDistance); drawACircle(maxDistance);
} else { } else {
ElMessage.warning("无数据"); ElMessage.warning("无数据");