From a0ccafc6ee49b52e2bee795e1c4a3ecea24e462d Mon Sep 17 00:00:00 2001 From: ryan Date: Sat, 18 Jul 2026 13:52:20 +0800 Subject: [PATCH] =?UTF-8?q?fix(geo):=20=E4=BF=AE=E5=A4=8D=E9=A6=99?= =?UTF-8?q?=E6=B8=AF=E7=AD=89=E8=8A=82=E7=82=B9=E5=9C=B0=E5=9B=BE=E8=B4=A8?= =?UTF-8?q?=E5=BF=83=E7=BC=BA=E5=A4=B1=E8=90=BD=E5=88=B0=E5=8D=97=E7=BE=8E?= =?UTF-8?q?=E5=8D=A0=E4=BD=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 补全 Hong Kong/Singapore/Taiwan 质心数据,并改进复合地名与 ISO 匹配, 避免 geo 无精确经纬度时错误回退到巴西等地的占位坐标。 --- docs/changelog/index.md | 1 + .../dashboard/data/country-centroids.json | 870 ++++++++++++++---- .../components/dashboard/world-stage-map.tsx | 51 +- pkg/geoip/country_centroid.go | 19 +- pkg/geoip/country_centroid_test.go | 31 + 5 files changed, 792 insertions(+), 180 deletions(-) diff --git a/docs/changelog/index.md b/docs/changelog/index.md index 3bd2ab2a..54e4b2bc 100644 --- a/docs/changelog/index.md +++ b/docs/changelog/index.md @@ -46,6 +46,7 @@ sidebar: false - 明确 OpenResty 健康权威:当前 status/message 以节点表为准,ClickHouse 仅存 status 与连接时序(不含 message)。 - 看板与节点观测不再展示或采集宿主机网卡入/出站;网络趋势仅保留访问日志的已提供/接收数据。 - 宿主机磁盘读/写趋势改为按小时速率(B/s)展示,摘要为近 24 小时平均速率。 +- 修复节点地图在缺少精确经纬度时把香港/新加坡/台湾等地区回退到错误占位坐标的问题;补全质心数据并改进复合地名匹配。 - Pages 部署包上传体积限制改为系统动态配置,默认仍为 100 MiB,可按环境调整。 - 上传新部署后会按保留策略自动清理超出数量的历史部署包,减少磁盘占用。 - Agent 在同步 Pages 部署时信任控制面已完成的包校验,不再重复限制文件数与展开体积,仅校验下载完整性并安全解压到本地。 diff --git a/frontend/app/(main)/components/dashboard/data/country-centroids.json b/frontend/app/(main)/components/dashboard/data/country-centroids.json index 0d8ae267..6bbf19cf 100644 --- a/frontend/app/(main)/components/dashboard/data/country-centroids.json +++ b/frontend/app/(main)/components/dashboard/data/country-centroids.json @@ -1,172 +1,702 @@ { - "Afghanistan": [65.99254367483304, 33.83349410470984], - "Angola": [17.563198329790602, -12.334557680834592], - "Albania": [20.035803636476235, 41.179283471608585], - "United Arab Emirates": [54.30345828396012, 23.905698042805522], - "Argentina": [-65.15670576062132, -35.178771590782524], - "Armenia": [44.929379894609674, 40.29884592895426], - "France": [165.43817082439585, -21.285375782391018], - "Australia": [134.361180723562, -25.574955774991995], - "Austria": [14.10165807418182, 47.57042831528493], - "Azerbaijan": [47.636777782137415, 40.3311508093757], - "Burundi": [29.873065896828848, -3.3802825292327188], - "Belgium": [4.628129604331132, 50.646494813466056], - "Benin": [2.323507643298733, 9.63048313950481], - "Burkina Faso": [-1.7757430610210276, 12.260370131848955], - "Bangladesh": [90.21009840315206, 23.88793565572049], - "Bulgaria": [25.225364036830744, 42.77785706066581], - "The Bahamas": [-78.02733865351972, 24.719920319716515], - "Bosnia and Herzegovina": [17.762461846176542, 44.16398853722456], - "Belarus": [28.04895281233843, 53.53432933090482], - "Belize": [-88.72096138346826, 17.17073148225863], - "Bolivia": [-64.69104972918655, -16.70141507507877], - "Brazil": [-53.113858151998855, -10.827995867833263], - "Brunei": [114.54229268997476, 4.451218476864121], - "Bhutan": [90.40562361681495, 27.40133623508629], - "Botswana": [23.791788508036337, -22.185333985163894], - "Central African Republic": [20.490781591297914, 6.563625165826992], - "Canada": [-102.31777616484295, 57.94457487676815], - "Switzerland": [8.205812860319684, 46.805544047201984], - "Chile": [-71.34891661948937, -35.98028631773855], - "China": [103.79804331240364, 36.61094167680319], - "Ivory Coast": [-5.569771898429842, 7.626172775954684], - "Cameroon": [12.739868035578002, 5.692692453534944], - "Democratic Republic of the Congo": [23.64811688254194, -2.8775533309965056], - "Republic of the Congo": [15.21207418503586, -0.8564004333096924], - "Colombia": [-73.07794094917405, 3.9235618261252663], - "Costa Rica": [-84.21742467558424, 9.986463158070535], - "Cuba": [-78.8954025482625, 21.62136808001903], - "Northern Cyprus": [33.39079188058263, 35.225753269439686], - "Cyprus": [33.02409208254226, 34.91304424540028], - "Czech Republic": [15.330767057694615, 49.70160772219921], - "Germany": [10.380496796525602, 51.083853487429664], - "Djibouti": [42.56788631653962, 11.745988995518626], - "Denmark": [-41.29088868109839, 74.72535220460091], - "Dominican Republic": [-70.48595892120278, 18.896879062003393], - "Algeria": [2.6175172555729325, 28.158202786113698], - "Ecuador": [-78.38384779532852, -1.4454571869341688], - "Egypt": [29.86739912685152, 26.49286512797635], - "Eritrea": [38.835037148217566, 15.359809600209143], - "Spain": [-3.5708365129134876, 40.391564705240064], - "Estonia": [25.811350172874032, 58.69303019372469], - "Ethiopia": [39.60372599651433, 8.621595995236198], - "Finland": [26.28958351526606, 64.52279699210293], - "Fiji": [177.98415179869738, -17.827004078184217], - "United Kingdom": [-36.367082569942795, -54.468348288665524], - "Gabon": [11.774048593462979, -0.5859798536474902], - "Georgia": [43.48650319000057, 42.175027555818694], - "Ghana": [-1.2150159067556041, 7.94078880601944], - "Guinea": [-10.943568403941383, 10.44078010915303], - "Gambia": [-16.21304964555284, 13.37062695465985], - "Guinea Bissau": [-14.929646023453557, 12.05088889829685], - "Equatorial Guinea": [10.481670786028316, 1.5660796013647418], - "Greece": [22.53435219348475, 39.517734832602365], - "Guatemala": [-90.35344030476544, 15.679044168855697], - "Guyana": [-58.978019347627985, 4.800329726037504], - "Honduras": [-86.65651796671759, 14.821029518594349], - "Croatia": [16.458685366615978, 45.18567759026696], - "Haiti": [-72.67866559866681, 18.916195586860297], - "Hungary": [19.410867145831855, 47.168542742918525], - "Indonesia": [101.52237404492608, -0.44681277438152994], - "India": [79.58636900833257, 22.901586798523514], - "Ireland": [-8.117695195030898, 53.2341315203433], - "Iran": [54.266246557433305, 32.57616445788996], - "Iraq": [43.74006501790808, 33.0341456153028], - "Iceland": [-18.509670948264166, 65.03034972428229], - "Israel": [35.241573878810335, 31.94758544099519], - "Italy": [12.16233842748749, 43.51281131035235], - "Jamaica": [-77.32850498837172, 18.172957893241634], - "Jordan": [36.76131486689134, 31.237145277490367], - "Japan": [137.97352453982398, 36.589925009528365], - "Kashmir": [77.08733723957188, 35.415738932286466], - "Kazakhstan": [67.27815427190085, 48.155989088140196], - "Kenya": [37.795078751163835, 0.5967194222965451], - "Kyrgyzstan": [74.58224715420873, 41.48363475100716], - "Cambodia": [104.90702345739547, 12.717932969523966], - "South Korea": [127.87280447602005, 36.475157799464604], - "Kosovo": [20.851519165302378, 42.51783231278167], - "Kuwait": [47.566177395781736, 29.316145203902064], - "Laos": [103.75263811609112, 18.494354885305256], - "Lebanon": [35.88502277707876, 33.91528991779158], - "Liberia": [-9.325867879201954, 6.453996218817175], - "Libya": [18.008785486000946, 27.031457363755713], - "Sri Lanka": [80.70055059693914, 7.649883097905021], - "Lesotho": [28.24303757633595, -29.57351232727891], - "Lithuania": [23.872793668340726, 55.3142460584835], - "Luxembourg": [6.070340274408408, 49.76746140228473], - "Latvia": [24.89496154477673, 56.853143698564296], - "Morocco": [-8.459192831832421, 29.83932361976915], - "Moldova": [28.446472517363826, 47.2017924696845], - "Madagascar": [46.70172536870331, -19.374776628372288], - "Mexico": [-102.51849775988345, 23.943713432682014], - "Macedonia": [21.704642152886493, 41.60373573782414], - "Mali": [-3.5321833143642736, 17.347810147640345], - "Myanmar": [96.49588816533908, 21.22201469728619], - "Montenegro": [19.233365413523355, 42.78395456212118], - "Mongolia": [103.06423533091326, 46.82560864032323], - "Mozambique": [35.53173663088568, -17.27297477254694], - "Mauritania": [-10.34307896458181, 20.259793585678146], - "Malawi": [34.288911351438394, -13.200363393826267], - "Malaysia": [114.69201508943004, 3.57724156754415], - "Namibia": [17.208945346875193, -22.132302890947404], - "Niger": [9.384787308614277, 17.41758190683491], - "Nigeria": [8.074235448092892, 9.58958974174772], - "Nicaragua": [-85.03229930746807, 12.835548864379284], - "Netherlands": [5.646194278986089, 52.27734132368374], - "Norway": [13.994247649210363, 64.32249798565987], - "Nepal": [83.9234099472594, 28.243335814044734], - "New Zealand": [170.54047059084724, -43.955381757717255], - "Oman": [56.08271927344639, 20.573738446088598], - "Pakistan": [69.32988114530586, 29.951585862562073], - "Panama": [-80.05970573973497, 8.521692369504816], - "Peru": [-74.38850244798846, -9.156316252308201], - "Philippines": [121.45754828266669, 15.948824272939182], - "Papua New Guinea": [144.22896759838426, -6.607045399379529], - "Poland": [19.379892383012464, 52.11963086628078], - "United States of America": [-99.14669730710926, 39.52689381707972], - "North Korea": [127.21551783512186, 40.144856985239926], - "Portugal": [-7.977838817691485, 39.6854900148663], - "Paraguay": [-58.39900641582761, -23.223895588708068], - "Qatar": [51.170816022848, 25.32876608728452], - "Romania": [24.971632366248883, 45.84560772065747], - "Russia": [99.05228241954488, 61.677043847105494], - "Rwanda": [29.91765145538139, -1.9953628964377972], - "Western Sahara": [-12.218085234851758, 24.221135708939354], - "Saudi Arabia": [44.5342871199886, 24.122854227726673], - "Sudan": [29.946243665370346, 15.99205876641883], - "South Sudan": [30.253827921202955, 7.307277152400154], - "Senegal": [-14.472411019597182, 14.338613732351318], - "Solomon Islands": [160.156396875585, -9.628589831637283], - "Sierra Leone": [-11.82013204896783, 8.575093438325089], - "El Salvador": [-88.86593554283397, 13.734573052971413], - "Somaliland": [46.25513292885051, 9.729995248781385], - "Somalia": [45.706539856671256, 4.747960517798881], - "Republic of Serbia": [20.766249889622852, 44.19998417744864], - "Suriname": [-55.91029765824739, 4.126766010517478], - "Slovakia": [19.47296461136286, 48.71540683451534], - "Slovenia": [14.771193461021065, 46.10807043333343], - "Sweden": [16.752551082675275, 62.8354879894394], - "Swaziland": [31.47664514492297, -26.563545981108437], - "Syria": [38.50449031631095, 35.01769370592341], - "Chad": [18.645815630757973, 15.32729896930035], - "Togo": [0.949513544830056, 8.576560980195756], - "Thailand": [101.01060253224972, 15.132319216387051], - "Tajikistan": [70.98712700685866, 38.55204366339685], - "Turkmenistan": [59.39292286662992, 39.1098173228857], - "East Timor": [125.78222644041995, -8.858373836074785], - "Trinidad and Tobago": [-61.270458833911896, 10.339930045317969], - "Tunisia": [9.546832905099203, 34.12673069029241], - "Turkey": [35.424986274948736, 38.998407240706534], - "United Republic of Tanzania": [34.79490109621088, -6.276146393386636], - "Uganda": [32.36575488492427, 1.2757695499320103], - "Ukraine": [31.381193375918794, 49.01345298489402], - "Uruguay": [-56.01665573850212, -32.80651677440885], - "Uzbekistan": [63.148826727968626, 41.7502616897204], - "Venezuela": [-66.1882174671549, 7.118299933056809], - "Vietnam": [106.29939096235873, 16.63088189612042], - "Vanuatu": [166.84228659210697, -15.266627310669035], - "Yemen": [47.546351590294876, 15.935825615412996], - "South Africa": [25.160630055943862, -29.008774283210798], - "Zambia": [27.775321721593084, -13.460954386993254], - "Zimbabwe": [29.850564118889274, -19.00677451616593] + "Afghanistan": [ + 65.99254367483304, + 33.83349410470984 + ], + "Albania": [ + 20.035803636476235, + 41.179283471608585 + ], + "Algeria": [ + 2.6175172555729325, + 28.158202786113698 + ], + "Angola": [ + 17.563198329790602, + -12.334557680834592 + ], + "Argentina": [ + -65.15670576062132, + -35.178771590782524 + ], + "Armenia": [ + 44.929379894609674, + 40.29884592895426 + ], + "Australia": [ + 134.361180723562, + -25.574955774991995 + ], + "Austria": [ + 14.10165807418182, + 47.57042831528493 + ], + "Azerbaijan": [ + 47.636777782137415, + 40.3311508093757 + ], + "Bangladesh": [ + 90.21009840315206, + 23.88793565572049 + ], + "Belarus": [ + 28.04895281233843, + 53.53432933090482 + ], + "Belgium": [ + 4.628129604331132, + 50.646494813466056 + ], + "Belize": [ + -88.72096138346826, + 17.17073148225863 + ], + "Benin": [ + 2.323507643298733, + 9.63048313950481 + ], + "Bhutan": [ + 90.40562361681495, + 27.40133623508629 + ], + "Bolivia": [ + -64.69104972918655, + -16.70141507507877 + ], + "Bosnia and Herzegovina": [ + 17.762461846176542, + 44.16398853722456 + ], + "Botswana": [ + 23.791788508036337, + -22.185333985163894 + ], + "Brazil": [ + -53.113858151998855, + -10.827995867833263 + ], + "Brunei": [ + 114.54229268997476, + 4.451218476864121 + ], + "Bulgaria": [ + 25.225364036830744, + 42.77785706066581 + ], + "Burkina Faso": [ + -1.7757430610210276, + 12.260370131848955 + ], + "Burundi": [ + 29.873065896828848, + -3.3802825292327188 + ], + "Cambodia": [ + 104.90702345739547, + 12.717932969523966 + ], + "Cameroon": [ + 12.739868035578002, + 5.692692453534944 + ], + "Canada": [ + -102.31777616484295, + 57.94457487676815 + ], + "Central African Republic": [ + 20.490781591297914, + 6.563625165826992 + ], + "Chad": [ + 18.645815630757973, + 15.32729896930035 + ], + "Chile": [ + -71.34891661948937, + -35.98028631773855 + ], + "China": [ + 103.79804331240364, + 36.61094167680319 + ], + "Colombia": [ + -73.07794094917405, + 3.9235618261252663 + ], + "Costa Rica": [ + -84.21742467558424, + 9.986463158070535 + ], + "Croatia": [ + 16.458685366615978, + 45.18567759026696 + ], + "Cuba": [ + -78.8954025482625, + 21.62136808001903 + ], + "Cyprus": [ + 33.02409208254226, + 34.91304424540028 + ], + "Czech Republic": [ + 15.330767057694615, + 49.70160772219921 + ], + "Democratic Republic of the Congo": [ + 23.64811688254194, + -2.8775533309965056 + ], + "Denmark": [ + -41.29088868109839, + 74.72535220460091 + ], + "Djibouti": [ + 42.56788631653962, + 11.745988995518626 + ], + "Dominican Republic": [ + -70.48595892120278, + 18.896879062003393 + ], + "East Timor": [ + 125.78222644041995, + -8.858373836074785 + ], + "Ecuador": [ + -78.38384779532852, + -1.4454571869341688 + ], + "Egypt": [ + 29.86739912685152, + 26.49286512797635 + ], + "El Salvador": [ + -88.86593554283397, + 13.734573052971413 + ], + "Equatorial Guinea": [ + 10.481670786028316, + 1.5660796013647418 + ], + "Eritrea": [ + 38.835037148217566, + 15.359809600209143 + ], + "Estonia": [ + 25.811350172874032, + 58.69303019372469 + ], + "Ethiopia": [ + 39.60372599651433, + 8.621595995236198 + ], + "Fiji": [ + 177.98415179869738, + -17.827004078184217 + ], + "Finland": [ + 26.28958351526606, + 64.52279699210293 + ], + "France": [ + 165.43817082439585, + -21.285375782391018 + ], + "Gabon": [ + 11.774048593462979, + -0.5859798536474902 + ], + "Gambia": [ + -16.21304964555284, + 13.37062695465985 + ], + "Georgia": [ + 43.48650319000057, + 42.175027555818694 + ], + "Germany": [ + 10.380496796525602, + 51.083853487429664 + ], + "Ghana": [ + -1.2150159067556041, + 7.94078880601944 + ], + "Greece": [ + 22.53435219348475, + 39.517734832602365 + ], + "Guatemala": [ + -90.35344030476544, + 15.679044168855697 + ], + "Guinea": [ + -10.943568403941383, + 10.44078010915303 + ], + "Guinea Bissau": [ + -14.929646023453557, + 12.05088889829685 + ], + "Guyana": [ + -58.978019347627985, + 4.800329726037504 + ], + "Haiti": [ + -72.67866559866681, + 18.916195586860297 + ], + "Honduras": [ + -86.65651796671759, + 14.821029518594349 + ], + "Hong Kong": [ + 114.1747, + 22.2783 + ], + "Hungary": [ + 19.410867145831855, + 47.168542742918525 + ], + "Iceland": [ + -18.509670948264166, + 65.03034972428229 + ], + "India": [ + 79.58636900833257, + 22.901586798523514 + ], + "Indonesia": [ + 101.52237404492608, + -0.44681277438152994 + ], + "Iran": [ + 54.266246557433305, + 32.57616445788996 + ], + "Iraq": [ + 43.74006501790808, + 33.0341456153028 + ], + "Ireland": [ + -8.117695195030898, + 53.2341315203433 + ], + "Israel": [ + 35.241573878810335, + 31.94758544099519 + ], + "Italy": [ + 12.16233842748749, + 43.51281131035235 + ], + "Ivory Coast": [ + -5.569771898429842, + 7.626172775954684 + ], + "Jamaica": [ + -77.32850498837172, + 18.172957893241634 + ], + "Japan": [ + 137.97352453982398, + 36.589925009528365 + ], + "Jordan": [ + 36.76131486689134, + 31.237145277490367 + ], + "Kashmir": [ + 77.08733723957188, + 35.415738932286466 + ], + "Kazakhstan": [ + 67.27815427190085, + 48.155989088140196 + ], + "Kenya": [ + 37.795078751163835, + 0.5967194222965451 + ], + "Kosovo": [ + 20.851519165302378, + 42.51783231278167 + ], + "Kuwait": [ + 47.566177395781736, + 29.316145203902064 + ], + "Kyrgyzstan": [ + 74.58224715420873, + 41.48363475100716 + ], + "Laos": [ + 103.75263811609112, + 18.494354885305256 + ], + "Latvia": [ + 24.89496154477673, + 56.853143698564296 + ], + "Lebanon": [ + 35.88502277707876, + 33.91528991779158 + ], + "Lesotho": [ + 28.24303757633595, + -29.57351232727891 + ], + "Liberia": [ + -9.325867879201954, + 6.453996218817175 + ], + "Libya": [ + 18.008785486000946, + 27.031457363755713 + ], + "Lithuania": [ + 23.872793668340726, + 55.3142460584835 + ], + "Luxembourg": [ + 6.070340274408408, + 49.76746140228473 + ], + "Macao": [ + 113.5439, + 22.1987 + ], + "Macau": [ + 113.5439, + 22.1987 + ], + "Macedonia": [ + 21.704642152886493, + 41.60373573782414 + ], + "Madagascar": [ + 46.70172536870331, + -19.374776628372288 + ], + "Malawi": [ + 34.288911351438394, + -13.200363393826267 + ], + "Malaysia": [ + 114.69201508943004, + 3.57724156754415 + ], + "Mali": [ + -3.5321833143642736, + 17.347810147640345 + ], + "Mauritania": [ + -10.34307896458181, + 20.259793585678146 + ], + "Mexico": [ + -102.51849775988345, + 23.943713432682014 + ], + "Moldova": [ + 28.446472517363826, + 47.2017924696845 + ], + "Mongolia": [ + 103.06423533091326, + 46.82560864032323 + ], + "Montenegro": [ + 19.233365413523355, + 42.78395456212118 + ], + "Morocco": [ + -8.459192831832421, + 29.83932361976915 + ], + "Mozambique": [ + 35.53173663088568, + -17.27297477254694 + ], + "Myanmar": [ + 96.49588816533908, + 21.22201469728619 + ], + "Namibia": [ + 17.208945346875193, + -22.132302890947404 + ], + "Nepal": [ + 83.9234099472594, + 28.243335814044734 + ], + "Netherlands": [ + 5.646194278986089, + 52.27734132368374 + ], + "New Zealand": [ + 170.54047059084724, + -43.955381757717255 + ], + "Nicaragua": [ + -85.03229930746807, + 12.835548864379284 + ], + "Niger": [ + 9.384787308614277, + 17.41758190683491 + ], + "Nigeria": [ + 8.074235448092892, + 9.58958974174772 + ], + "North Korea": [ + 127.21551783512186, + 40.144856985239926 + ], + "Northern Cyprus": [ + 33.39079188058263, + 35.225753269439686 + ], + "Norway": [ + 13.994247649210363, + 64.32249798565987 + ], + "Oman": [ + 56.08271927344639, + 20.573738446088598 + ], + "Pakistan": [ + 69.32988114530586, + 29.951585862562073 + ], + "Panama": [ + -80.05970573973497, + 8.521692369504816 + ], + "Papua New Guinea": [ + 144.22896759838426, + -6.607045399379529 + ], + "Paraguay": [ + -58.39900641582761, + -23.223895588708068 + ], + "Peru": [ + -74.38850244798846, + -9.156316252308201 + ], + "Philippines": [ + 121.45754828266669, + 15.948824272939182 + ], + "Poland": [ + 19.379892383012464, + 52.11963086628078 + ], + "Portugal": [ + -7.977838817691485, + 39.6854900148663 + ], + "Qatar": [ + 51.170816022848, + 25.32876608728452 + ], + "Republic of Serbia": [ + 20.766249889622852, + 44.19998417744864 + ], + "Republic of the Congo": [ + 15.21207418503586, + -0.8564004333096924 + ], + "Romania": [ + 24.971632366248883, + 45.84560772065747 + ], + "Russia": [ + 99.05228241954488, + 61.677043847105494 + ], + "Rwanda": [ + 29.91765145538139, + -1.9953628964377972 + ], + "Saudi Arabia": [ + 44.5342871199886, + 24.122854227726673 + ], + "Senegal": [ + -14.472411019597182, + 14.338613732351318 + ], + "Sierra Leone": [ + -11.82013204896783, + 8.575093438325089 + ], + "Singapore": [ + 103.8198, + 1.3521 + ], + "Slovakia": [ + 19.47296461136286, + 48.71540683451534 + ], + "Slovenia": [ + 14.771193461021065, + 46.10807043333343 + ], + "Solomon Islands": [ + 160.156396875585, + -9.628589831637283 + ], + "Somalia": [ + 45.706539856671256, + 4.747960517798881 + ], + "Somaliland": [ + 46.25513292885051, + 9.729995248781385 + ], + "South Africa": [ + 25.160630055943862, + -29.008774283210798 + ], + "South Korea": [ + 127.87280447602005, + 36.475157799464604 + ], + "South Sudan": [ + 30.253827921202955, + 7.307277152400154 + ], + "Spain": [ + -3.5708365129134876, + 40.391564705240064 + ], + "Sri Lanka": [ + 80.70055059693914, + 7.649883097905021 + ], + "Sudan": [ + 29.946243665370346, + 15.99205876641883 + ], + "Suriname": [ + -55.91029765824739, + 4.126766010517478 + ], + "Swaziland": [ + 31.47664514492297, + -26.563545981108437 + ], + "Sweden": [ + 16.752551082675275, + 62.8354879894394 + ], + "Switzerland": [ + 8.205812860319684, + 46.805544047201984 + ], + "Syria": [ + 38.50449031631095, + 35.01769370592341 + ], + "Taiwan": [ + 120.9605, + 23.6978 + ], + "Tajikistan": [ + 70.98712700685866, + 38.55204366339685 + ], + "Thailand": [ + 101.01060253224972, + 15.132319216387051 + ], + "The Bahamas": [ + -78.02733865351972, + 24.719920319716515 + ], + "Togo": [ + 0.949513544830056, + 8.576560980195756 + ], + "Trinidad and Tobago": [ + -61.270458833911896, + 10.339930045317969 + ], + "Tunisia": [ + 9.546832905099203, + 34.12673069029241 + ], + "Turkey": [ + 35.424986274948736, + 38.998407240706534 + ], + "Turkmenistan": [ + 59.39292286662992, + 39.1098173228857 + ], + "Uganda": [ + 32.36575488492427, + 1.2757695499320103 + ], + "Ukraine": [ + 31.381193375918794, + 49.01345298489402 + ], + "United Arab Emirates": [ + 54.30345828396012, + 23.905698042805522 + ], + "United Kingdom": [ + -36.367082569942795, + -54.468348288665524 + ], + "United Republic of Tanzania": [ + 34.79490109621088, + -6.276146393386636 + ], + "United States of America": [ + -99.14669730710926, + 39.52689381707972 + ], + "Uruguay": [ + -56.01665573850212, + -32.80651677440885 + ], + "Uzbekistan": [ + 63.148826727968626, + 41.7502616897204 + ], + "Vanuatu": [ + 166.84228659210697, + -15.266627310669035 + ], + "Venezuela": [ + -66.1882174671549, + 7.118299933056809 + ], + "Vietnam": [ + 106.29939096235873, + 16.63088189612042 + ], + "Western Sahara": [ + -12.218085234851758, + 24.221135708939354 + ], + "Yemen": [ + 47.546351590294876, + 15.935825615412996 + ], + "Zambia": [ + 27.775321721593084, + -13.460954386993254 + ], + "Zimbabwe": [ + 29.850564118889274, + -19.00677451616593 + ] } diff --git a/frontend/app/(main)/components/dashboard/world-stage-map.tsx b/frontend/app/(main)/components/dashboard/world-stage-map.tsx index 70bb7565..8ae16bc2 100644 --- a/frontend/app/(main)/components/dashboard/world-stage-map.tsx +++ b/frontend/app/(main)/components/dashboard/world-stage-map.tsx @@ -153,17 +153,50 @@ function resolveCountryCentroid(geoName: string): CountryCentroid | null { if (!trimmed) { return null; } - const direct = toCountryCentroid(countryCentroids[trimmed]); - if (direct) { - return direct; - } - const lower = trimmed.toLowerCase(); - for (const [name, coordinates] of Object.entries(countryCentroids)) { - if (name.toLowerCase() === lower) { - return toCountryCentroid(coordinates); + const candidates = new Set([trimmed]); + // ipinfo-style names: "Hong Kong, Hong Kong, HK" + for (const part of trimmed.split(',').map((item) => item.trim())) { + if (part) { + candidates.add(part); } } - return null; + // trailing ISO2 often present after city/region + const isoMatch = trimmed.match(/\b([A-Z]{2})\b/g); + if (isoMatch) { + for (const code of isoMatch) { + candidates.add(code); + } + } + + for (const candidate of candidates) { + const direct = toCountryCentroid(countryCentroids[candidate]); + if (direct) { + return direct; + } + const lower = candidate.toLowerCase(); + for (const [name, coordinates] of Object.entries(countryCentroids)) { + if (name.toLowerCase() === lower) { + return toCountryCentroid(coordinates); + } + } + } + + // Soft contains match for longer composite labels (prefer longer country names). + const lowerFull = trimmed.toLowerCase(); + let best: { length: number; coords: CountryCentroid } | null = null; + for (const [name, coordinates] of Object.entries(countryCentroids)) { + const lowerName = name.toLowerCase(); + if (lowerFull.includes(lowerName) && lowerName.length >= 4) { + const coords = toCountryCentroid(coordinates); + if (!coords) { + continue; + } + if (!best || lowerName.length > best.length) { + best = { length: lowerName.length, coords }; + } + } + } + return best?.coords ?? null; } function getNodeCoordinates(node: DashboardNodeHealth, index: number) { diff --git a/pkg/geoip/country_centroid.go b/pkg/geoip/country_centroid.go index 5e0b86ae..3697ff34 100644 --- a/pkg/geoip/country_centroid.go +++ b/pkg/geoip/country_centroid.go @@ -71,6 +71,7 @@ var countryCentroidsByName = map[string]countryCentroid{ "Guyana": {lat: 4.800330, lon: -58.978019}, "Haiti": {lat: 18.916196, lon: -72.678666}, "Honduras": {lat: 14.821030, lon: -86.656518}, + "Hong Kong": {lat: 22.278300, lon: 114.174700}, "Hungary": {lat: 47.168543, lon: 19.410867}, "Iceland": {lat: 65.030350, lon: -18.509671}, "India": {lat: 22.901587, lon: 79.586369}, @@ -139,6 +140,7 @@ var countryCentroidsByName = map[string]countryCentroid{ "Saudi Arabia": {lat: 24.122854, lon: 44.534287}, "Senegal": {lat: 14.338614, lon: -14.472411}, "Sierra Leone": {lat: 8.575093, lon: -11.820132}, + "Singapore": {lat: 1.352100, lon: 103.819800}, "Slovakia": {lat: 48.715407, lon: 19.472965}, "Slovenia": {lat: 46.108070, lon: 14.771193}, "Solomon Islands": {lat: -9.628590, lon: 160.156397}, @@ -155,6 +157,7 @@ var countryCentroidsByName = map[string]countryCentroid{ "Sweden": {lat: 62.835488, lon: 16.752551}, "Switzerland": {lat: 46.805544, lon: 8.205813}, "Syria": {lat: 35.017694, lon: 38.504490}, + "Taiwan": {lat: 23.697800, lon: 120.960500}, "Tajikistan": {lat: 38.552044, lon: 70.987127}, "Thailand": {lat: 15.132319, lon: 101.010603}, "The Bahamas": {lat: 24.719920, lon: -78.027339}, @@ -181,14 +184,28 @@ var countryCentroidsByName = map[string]countryCentroid{ } // CountryCentroidByName returns latitude and longitude for a country name, if found. +// Accepts composite labels such as "Hong Kong, Hong Kong, HK" from GeoIP providers. func CountryCentroidByName(name string) (lat float64, lon float64, ok bool) { name = strings.TrimSpace(name) if name == "" { return 0, 0, false } - if v, ok := countryCentroidsByName[name]; ok { + if v, found := countryCentroidsByName[name]; found { return v.lat, v.lon, true } + // Try comma-separated parts (city / region / country / ISO). + for _, part := range strings.Split(name, ",") { + part = strings.TrimSpace(part) + if part == "" { + continue + } + if v, found := countryCentroidsByName[part]; found { + return v.lat, v.lon, true + } + if lat, lon, ok = CountryCentroidByISO(part); ok { + return lat, lon, true + } + } return 0, 0, false } diff --git a/pkg/geoip/country_centroid_test.go b/pkg/geoip/country_centroid_test.go index 6f3484f9..9b7c955f 100644 --- a/pkg/geoip/country_centroid_test.go +++ b/pkg/geoip/country_centroid_test.go @@ -11,3 +11,34 @@ func TestCountryCentroidGermany(t *testing.T) { t.Fatalf("unexpected Germany centroid: %f,%f", lat, lon) } } + +func TestCountryCentroidHongKongSingaporeTaiwan(t *testing.T) { + cases := []struct { + iso string + name string + minLat float64 + maxLat float64 + minLon float64 + maxLon float64 + }{ + {iso: "HK", name: "Hong Kong", minLat: 22, maxLat: 23, minLon: 113, maxLon: 115}, + {iso: "SG", name: "Singapore", minLat: 1, maxLat: 2, minLon: 103, maxLon: 104}, + {iso: "TW", name: "Taiwan", minLat: 22, maxLat: 26, minLon: 119, maxLon: 122}, + } + for _, tc := range cases { + lat, lon, ok := CountryCentroidByISO(tc.iso) + if !ok { + t.Fatalf("expected %s centroid by ISO", tc.iso) + } + if lat < tc.minLat || lat > tc.maxLat || lon < tc.minLon || lon > tc.maxLon { + t.Fatalf("%s ISO centroid out of range: %f,%f", tc.iso, lat, lon) + } + lat, lon, ok = CountryCentroidByName(tc.name) + if !ok { + t.Fatalf("expected %s centroid by name", tc.name) + } + if lat < tc.minLat || lat > tc.maxLat || lon < tc.minLon || lon > tc.maxLon { + t.Fatalf("%s name centroid out of range: %f,%f", tc.name, lat, lon) + } + } +}