修复地图错误

This commit is contained in:
CN-JS-HuiBai
2026-04-06 00:49:31 +08:00
parent b2f14528a9
commit 62747f0fcf

View File

@@ -571,32 +571,29 @@
// Transform to Pacific-centered correctly
const transformCoords = (coords) => {
if (!Array.isArray(coords)) return;
if (typeof coords[0] === 'number') return; // Point
if (typeof coords[0][0] === 'number') { // Ring
// Calculate average to decide if we should shift the whole ring
if (!Array.isArray(coords) || coords.length === 0) return;
const first = coords[0];
if (!Array.isArray(first)) return;
if (typeof first[0] === 'number') { // Ring
let sum = 0;
coords.forEach(pt => sum += pt[0]);
let avg = sum / coords.length;
if (avg < -20) {
coords.forEach(pt => pt[0] += 360);
}
// Fix internal wrap-around jumps to keep polygons contiguous
for (let i = 1; i < coords.length; i++) {
let prev = coords[i - 1][0];
while (coords[i][0] - prev > 180) coords[i][0] -= 360;
while (coords[i][0] - prev < -180) coords[i][0] += 360;
}
} else {
coords.forEach(transformCoords);
}
};
worldJSON.features.forEach(feature => {
if (feature.geometry && feature.geometry.coordinates) {
transformCoords(feature.geometry.coordinates);
}
});
if (worldJSON && worldJSON.features) {
worldJSON.features.forEach(feature => {
if (feature.geometry && feature.geometry.coordinates) {
transformCoords(feature.geometry.coordinates);
}
});
}
echarts.registerMap('world', worldJSON);
@@ -634,9 +631,9 @@
geo: {
map: 'world',
roam: true,
center: [160, 25], // Centered slightly better for global view
center: [165, 20], // Centered in Pacific
zoom: 1.1,
aspectScale: 0.85, // Adjust aspect ratio to reduce vertical stretching in northern regions
aspectScale: 0.85,
emphasis: {
label: { show: false },
itemStyle: { areaColor: isLight ? '#f0f2f5' : '#2d334d' }
@@ -682,11 +679,11 @@
myMap2D.setOption({
geo: {
itemStyle: {
areaColor: isLight ? '#eef0f5' : '#1a1d2d',
areaColor: isLight ? '#f4f6fa' : '#1a1d2e',
borderColor: isLight ? '#cbd5e1' : '#2d334d'
},
emphasis: {
itemStyle: { areaColor: isLight ? '#f0f2f5' : '#2d334d' }
itemStyle: { areaColor: isLight ? '#f4f8ff' : '#2d334d' }
}
}
});