111 lines
3.8 KiB
TypeScript
111 lines
3.8 KiB
TypeScript
// 地图数据来源:https://unpkg.com/echarts@4.9.0/map/json/world.json
|
|
// 组件直接导入本地缓存的 ECharts 世界地图 GeoJSON,避免运行时依赖外部网络。
|
|
|
|
import type { IpLocationStatItem } from "../types/api";
|
|
|
|
export const normalizeWorldCountryName = (value?: string | null) => {
|
|
const country = String(value || "").trim();
|
|
const aliases: Record<string, string> = {
|
|
中国: "China",
|
|
China: "China",
|
|
"Mainland China": "China",
|
|
中国香港: "China",
|
|
中国澳门: "China",
|
|
中国台湾: "China",
|
|
美国: "United States",
|
|
"United States": "United States",
|
|
"United States of America": "United States",
|
|
USA: "United States",
|
|
Australia: "Australia",
|
|
澳大利亚: "Australia",
|
|
Japan: "Japan",
|
|
日本: "Japan",
|
|
Singapore: "Singapore",
|
|
新加坡: "Singapore",
|
|
Germany: "Germany",
|
|
德国: "Germany",
|
|
France: "France",
|
|
法国: "France",
|
|
"United Kingdom": "United Kingdom",
|
|
英国: "United Kingdom",
|
|
Canada: "Canada",
|
|
加拿大: "Canada",
|
|
India: "India",
|
|
印度: "India",
|
|
Russia: "Russia",
|
|
俄罗斯: "Russia",
|
|
};
|
|
return aliases[country] || country;
|
|
};
|
|
|
|
export const countryCoordinates: Record<string, [number, number]> = {
|
|
China: [104.1954, 35.8617],
|
|
"United States": [-95.7129, 37.0902],
|
|
Netherlands: [5.2913, 52.1326],
|
|
Türkiye: [35.2433, 38.9637],
|
|
Turkey: [35.2433, 38.9637],
|
|
Australia: [133.7751, -25.2744],
|
|
Japan: [138.2529, 36.2048],
|
|
Singapore: [103.8198, 1.3521],
|
|
Germany: [10.4515, 51.1657],
|
|
France: [2.2137, 46.2276],
|
|
"United Kingdom": [-3.436, 55.3781],
|
|
Canada: [-106.3468, 56.1304],
|
|
India: [78.9629, 20.5937],
|
|
Russia: [105.3188, 61.524],
|
|
};
|
|
|
|
export const cityCoordinates: Record<string, [number, number]> = {
|
|
"局域网": [121.86, 31.45],
|
|
"北京市": [116.4074, 39.9042],
|
|
"天津市": [117.2008, 39.0842],
|
|
"河北省": [114.5025, 38.0455],
|
|
"山西省": [112.5492, 37.857],
|
|
"内蒙古自治区": [111.6708, 40.8183],
|
|
"辽宁省": [123.4315, 41.8057],
|
|
"吉林省": [125.3245, 43.8868],
|
|
"黑龙江省": [126.6424, 45.7567],
|
|
"上海市": [121.4737, 31.2304],
|
|
"江苏省": [118.7633, 32.0617],
|
|
"浙江省": [120.1551, 30.2741],
|
|
"安徽省": [117.2272, 31.8206],
|
|
"福建省": [119.2965, 26.0745],
|
|
"江西省": [115.8582, 28.682],
|
|
"山东省": [117.1201, 36.6512],
|
|
"河南省": [113.6254, 34.7466],
|
|
"湖北省": [114.3055, 30.5928],
|
|
"湖南省": [112.9388, 28.2282],
|
|
"广东省": [113.2644, 23.1291],
|
|
"广西壮族自治区": [108.3669, 22.817],
|
|
"海南省": [110.3312, 20.0311],
|
|
"重庆": [106.5516, 29.563],
|
|
"重庆市": [106.5516, 29.563],
|
|
"四川省": [104.0665, 30.5723],
|
|
"贵州省": [106.6302, 26.647],
|
|
"云南省": [102.8329, 24.8801],
|
|
"西藏自治区": [91.1322, 29.6604],
|
|
"陕西省": [108.9398, 34.3416],
|
|
"甘肃省": [103.8343, 36.0611],
|
|
"青海省": [101.7782, 36.6171],
|
|
"宁夏回族自治区": [106.2309, 38.4872],
|
|
"新疆维吾尔自治区": [87.6168, 43.8256],
|
|
"台湾省": [121.5654, 25.033],
|
|
"香港特别行政区": [114.1694, 22.3193],
|
|
"澳门特别行政区": [113.5439, 22.1987],
|
|
"南京": [118.7969, 32.0603],
|
|
"南京市": [118.7969, 32.0603],
|
|
"San Jose": [-121.8863, 37.3382],
|
|
"South Holland": [4.493, 52.0208],
|
|
"Istanbul": [28.9784, 41.0082],
|
|
};
|
|
|
|
export const resolveSourceCoordinate = (item: IpLocationStatItem): [number, number] | null => {
|
|
if (item.location === "局域网") return cityCoordinates["局域网"];
|
|
const city = String(item.city || "").trim();
|
|
if (city && cityCoordinates[city]) return cityCoordinates[city];
|
|
const province = String(item.province || "").trim();
|
|
if (province && cityCoordinates[province]) return cityCoordinates[province];
|
|
const country = normalizeWorldCountryName(item.country);
|
|
return country ? countryCoordinates[country] || null : null;
|
|
};
|