修复地图错误

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