Merge branch 'main' of https://git.cityme.com.cn/xiangshan/ggfwjsc
This commit is contained in:
commit
9f1b41760a
|
@ -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,18 +2076,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) => {
|
||||||
// 使用正则表达式去除非数字字符(保留小数点和负号)
|
// 使用正则表达式去除非数字字符(保留小数点和负号)
|
||||||
|
@ -2095,28 +2118,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("无数据");
|
||||||
|
|
Loading…
Reference in New Issue