This commit is contained in:
姚宇浩 2024-08-07 14:37:10 +08:00
commit 9f1b41760a
2 changed files with 90 additions and 28 deletions

BIN
dist.zip

Binary file not shown.

View File

@ -613,9 +613,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([
@ -2055,7 +2056,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("无数据");
@ -2075,48 +2076,109 @@ const getServiceCircle = async (communityName, townName) => {
console.error("Error fetching data:", error); console.error("Error fetching data:", error);
} }
}; };
//
const calculateCenterPoint = (coordinates) => {
if (coordinates.length === 0) {
return null;
}
let x = 0.0;
let y = 0.0;
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);
});
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((coord) => {
// 使
const cleanedCoord = coord.replace(/[^0-9.-]/g, "");
return Number(cleanedCoord); //
});
const sum = numericCoordinates.reduce((acc, val) => acc + val, 0); //
const average = sum / numericCoordinates.length; //
// console.log(average, "");
return parseFloat(average.toFixed(5)); // 5
};
//
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 = () => { const addggfwq = () => {
if (fwqList.value.length !== 0) { if (fwqList.value.length !== 0) {
data.fwqCoordinates1 = []; data.fwqCoordinates = [];
data.fwqCoordinates2 = []; // data.fwqCoordinates1 = [];
// data.fwqCoordinates2 = [];
fwqList.value.map((item, index) => { fwqList.value.map((item, index) => {
data.fwqCoordinates1.push(item.point[0]); data.fwqCoordinates.push(item.point);
data.fwqCoordinates2.push(item.point[1]); // data.fwqCoordinates1.push(item.point[0]);
// data.fwqCoordinates2.push(item.point[1]);
createCustomOverlay(item, index); createCustomOverlay(item, index);
}); });
// console.log("", data.fwqCoordinates1, data.fwqCoordinates2);
function calculateAverage(coordinates) {
// const numericCoordinates = coordinates.map(Number); //
const numericCoordinates = coordinates.map((coord) => {
// 使
const cleanedCoord = coord.replace(/[^0-9.-]/g, "");
return Number(cleanedCoord); //
});
const sum = numericCoordinates.reduce((acc, val) => acc + val, 0); //
const average = sum / numericCoordinates.length; //
return parseFloat(average.toFixed(5)); // 5
}
data.fwqCoordinates1 = calculateAverage(data.fwqCoordinates1); const centerPoint = calculateCenterPoint(data.fwqCoordinates);
data.fwqCoordinates2 = calculateAverage(data.fwqCoordinates2);
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("无数据");