Compare commits

...

5 Commits

Author SHA1 Message Date
hamster1963
fc6c367f97 update: v1.4.5 2024-11-21 15:39:08 +08:00
hamster1963
e5e2d2b02d fix(global): remove dev map code 2024-11-21 15:38:41 +08:00
hamster1963
b8d6e83169 chore(deps): caniuse-lite 2024-11-21 15:33:51 +08:00
hamster1963
62cdb7e18c fix(global): the map of Russia not being fully populated 2024-11-21 15:26:14 +08:00
hamster1963
7e1a818dc2 feat: new global map 2024-11-21 15:17:22 +08:00
5 changed files with 222 additions and 4 deletions

View File

@ -29,7 +29,6 @@ export default async function ServerGlobal() {
} }
export async function Global({ countries = [] }: GlobalProps) { export async function Global({ countries = [] }: GlobalProps) {
// const t = useTranslations("Global");
const map = new DottedMap({ map: JSON.parse(mapJsonString) }); const map = new DottedMap({ map: JSON.parse(mapJsonString) });
const countries_alpha3 = countries const countries_alpha3 = countries
@ -44,6 +43,42 @@ export async function Global({ countries = [] }: GlobalProps) {
); );
if (feature) { if (feature) {
if (countryCode === "RUS") {
// 获取俄罗斯的多个边界
const bboxList = feature.geometry.coordinates.map((polygon: any) =>
turf.bbox({ type: "Polygon", coordinates: polygon }),
);
const spacing = 20; // 单位为千米
const options = { units: "kilometers" };
bboxList.forEach((bbox: any) => {
// @ts-expect-error ignore
const pointGrid = turf.pointGrid(bbox, spacing, options);
// 过滤出位于当前多边形内部的点
const pointsWithin = turf.pointsWithinPolygon(pointGrid, feature);
if (pointsWithin.features.length === 0) {
const centroid = turf.centroid(feature);
const [lng, lat] = centroid.geometry.coordinates;
map.addPin({
lat,
lng,
svgOptions: { color: "#FF4500", radius: 0.3 },
});
} else {
pointsWithin.features.forEach((point: any) => {
const [lng, lat] = point.geometry.coordinates;
map.addPin({
lat,
lng,
svgOptions: { color: "#FF4500", radius: 0.3 },
});
});
}
});
}
// 获取国家的边界框 // 获取国家的边界框
const bbox = turf.bbox(feature); const bbox = turf.bbox(feature);

BIN
bun.lockb

Binary file not shown.

183
lib/dev-geo.ts Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,6 @@
{ {
"name": "nezha-dash", "name": "nezha-dash",
"version": "1.4.4-fix", "version": "1.4.5",
"private": true, "private": true,
"scripts": { "scripts": {
"dev": "next dev -p 3040", "dev": "next dev -p 3040",
@ -25,7 +25,7 @@
"@turf/turf": "^7.1.0", "@turf/turf": "^7.1.0",
"@types/luxon": "^3.4.2", "@types/luxon": "^3.4.2",
"@typescript-eslint/eslint-plugin": "^8.15.0", "@typescript-eslint/eslint-plugin": "^8.15.0",
"caniuse-lite": "^1.0.30001680", "caniuse-lite": "^1.0.30001683",
"class-variance-authority": "^0.7.0", "class-variance-authority": "^0.7.0",
"clsx": "^2.1.1", "clsx": "^2.1.1",
"country-flag-icons": "^1.5.13", "country-flag-icons": "^1.5.13",