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({
serviceCircleList: [],
fwqCoordinates: "", //
fwqCoordinates1: [], //
fwqCoordinates2: [], //
fwqCoordinates: [], //
fwqCoordinates1: [], //
fwqCoordinates2: [], //
zoomLevel: null, //
});
//
const jbfwqTotal = ref([
@ -1942,16 +1943,16 @@ const person_detail = (age) => {
const getFwq = () => {
http.get(`/api/ggfwyth/ysyzt/listXzjdAndCsq`).then((res) => {
if (res.code == 200) {
res.data.forEach((item,index) => {
res.data.forEach((item, index) => {
jbfwqTotal.value.push({
name:item.xzjd,
child:[],
})
name: item.xzjd,
child: [],
});
item.csqs.forEach((item2) => {
jbfwqTotal.value[index].child.push({
name:item2.csq,
jc:item2.jc
})
name: item2.csq,
jc: item2.jc,
});
});
});
}
@ -1983,7 +1984,7 @@ const changeFwq = async (id, name, names) => {
map.clearOverlays(); //
addggfwq(); //
setTimeout(() => {
goMapCenter([data.fwqCoordinates1, data.fwqCoordinates2], 16); //
goMapCenter([data.fwqCoordinates1, data.fwqCoordinates2], data.zoomLevel); //
}, 500);
} else {
ElMessage.warning("无数据");
@ -2003,48 +2004,109 @@ const getServiceCircle = async (communityName, townName) => {
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 = () => {
if (fwqList.value.length !== 0) {
data.fwqCoordinates1 = [];
data.fwqCoordinates2 = [];
data.fwqCoordinates = [];
// data.fwqCoordinates1 = [];
// data.fwqCoordinates2 = [];
fwqList.value.map((item, index) => {
data.fwqCoordinates1.push(item.point[0]);
data.fwqCoordinates2.push(item.point[1]);
data.fwqCoordinates.push(item.point);
// data.fwqCoordinates1.push(item.point[0]);
// data.fwqCoordinates2.push(item.point[1]);
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);
data.fwqCoordinates2 = calculateAverage(data.fwqCoordinates2);
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 = []; //
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(
(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
Number(item.point[0].replace(/[^0-9.-]/g, "")),
Number(item.point[1].replace(/[^0-9.-]/g, "")),
Number(centerPoint[0]),
Number(centerPoint[1])
);
distances.push(distance); //
});
let maxDistance = Math.max(...distances); //
maxDistance = Math.ceil(maxDistance * 1.8); //
maxDistance = Math.ceil(maxDistance * 2.2); //
if (maxDistance < 100) {
maxDistance = 150; // 100 150
}
console.log("最大距离:", maxDistance);
data.zoomLevel = calculateZoomLevel(maxDistance);
// console.log(":", maxDistance,data.zoomLevel);
drawACircle(maxDistance);
} else {
ElMessage.warning("无数据");