fix(global): use iso_a3_eh

This commit is contained in:
hamster1963 2024-11-26 17:50:49 +08:00
parent 269e2fcd13
commit 2c6dcdf53f
2 changed files with 10 additions and 8 deletions

View File

@ -7,14 +7,14 @@ import { InteractiveMap } from "./InteractiveMap";
export default async function ServerGlobal() {
const nezhaServerList = await GetNezhaData();
const countrytList: string[] = [];
const countryList: string[] = [];
const serverCounts: { [key: string]: number } = {};
nezhaServerList.result.forEach((server) => {
if (server.host.CountryCode) {
const countryCode = server.host.CountryCode.toUpperCase();
if (!countrytList.includes(countryCode)) {
countrytList.push(countryCode);
if (!countryList.includes(countryCode)) {
countryList.push(countryCode);
}
serverCounts[countryCode] = (serverCounts[countryCode] || 0) + 1;
}
@ -25,15 +25,15 @@ export default async function ServerGlobal() {
const geoJson = JSON.parse(geoJsonString);
const filteredFeatures = geoJson.features.filter(
(feature: any) => feature.properties.iso_a3 !== "",
(feature: any) => feature.properties.iso_a3_eh !== "",
);
return (
<section className="flex flex-col gap-4 mt-[3.2px]">
<GlobalInfo countries={countrytList} />
<GlobalInfo countries={countryList} />
<div className="w-full overflow-x-auto">
<InteractiveMap
countries={countrytList}
countries={countryList}
serverCounts={serverCounts}
width={width}
height={height}

View File

@ -57,11 +57,13 @@ export function InteractiveMap({
<g>
{filteredFeatures.map((feature, index) => {
const isHighlighted = countries_alpha3.includes(
feature.properties.iso_a3,
feature.properties.iso_a3_eh,
);
const countryCode = Object.entries(countryCodeMapping).find(
([, alpha3]) => alpha3 === feature.properties.iso_a3,
([, alpha3]) => alpha3 === feature.properties.iso_a3_eh,
)?.[0];
const serverCount = countryCode
? serverCounts[countryCode] || 0
: 0;