Speed up JMA nearby refresh and link Tokyo to 10-minute data

This commit is contained in:
2569718930@qq.com
2026-04-13 11:02:45 +08:00
parent f7f6ba39f7
commit f0940b9c8b
4 changed files with 49 additions and 6 deletions
+2 -2
View File
@@ -31,8 +31,8 @@ interface UseLeafletMapArgs {
const AUTO_NEARBY_MIN_ZOOM = 8;
const AUTO_NEARBY_MAX_DISTANCE_M = 120000;
const AUTO_NEARBY_IDLE_REFRESH_DELAY_MS = 20_000;
const AUTO_NEARBY_MIN_REFRESH_INTERVAL_MS = 90_000;
const AUTO_NEARBY_IDLE_REFRESH_DELAY_MS = 10_000;
const AUTO_NEARBY_MIN_REFRESH_INTERVAL_MS = 60_000;
const MAP_MAX_ZOOM = 19;
const CITY_MARKER_DISPLAY_OFFSETS: Record<
string,
+31 -3
View File
@@ -6,6 +6,23 @@ export type OfficialSourceLink = {
kind: "agency" | "airport" | "metar";
};
function buildJmaAmedasTenMinuteUrl(
localDate?: string | null,
options?: {
blockNo?: string;
precNo?: string;
},
) {
const blockNo = String(options?.blockNo || "0371").trim() || "0371";
const precNo = String(options?.precNo || "44").trim() || "44";
const match = String(localDate || "").match(/^(\d{4})-(\d{2})-(\d{2})$/);
const now = new Date();
const year = match?.[1] || String(now.getFullYear());
const month = match?.[2] || String(now.getMonth() + 1).padStart(2, "0");
const day = match?.[3] || String(now.getDate()).padStart(2, "0");
return `https://www.data.jma.go.jp/stats/etrn/view/10min_a1.php?prec_no=${encodeURIComponent(precNo)}&block_no=${encodeURIComponent(blockNo)}&year=${encodeURIComponent(year)}&month=${encodeURIComponent(month)}&day=${encodeURIComponent(day)}&view=`;
}
const CITY_SPECIFIC_SOURCES: Record<string, OfficialSourceLink[]> = {
singapore: [
{
@@ -329,8 +346,8 @@ const CITY_SPECIFIC_SOURCES: Record<string, OfficialSourceLink[]> = {
],
tokyo: [
{
label: "JMA",
href: "https://www.jma.go.jp/jma/indexe.html",
label: "JMA 羽田10分钟实况",
href: "",
kind: "agency",
},
{
@@ -681,7 +698,18 @@ const CITY_SPECIFIC_SOURCES: Record<string, OfficialSourceLink[]> = {
export function getOfficialSourceLinks(detail: CityDetail): OfficialSourceLink[] {
const cityKey = String(detail.name || "").trim().toLowerCase();
const links = [...(CITY_SPECIFIC_SOURCES[cityKey] || [])];
const links = [...(CITY_SPECIFIC_SOURCES[cityKey] || [])].map((link) => {
if (cityKey === "tokyo" && link.kind === "agency" && link.label === "JMA 羽田10分钟实况") {
return {
...link,
href: buildJmaAmedasTenMinuteUrl(detail.local_date, {
blockNo: "0371",
precNo: "44",
}),
};
}
return link;
});
const seen = new Set<string>();
return links.filter((link) => {
const key = `${link.label}|${link.href}`;