feat: 단풍 지도 카드 — 산림청 2026 단풍절정 예측 23곳을 한반도 그림 지도(실제 해안선에 맞춘 Codex 그림, 독도 포함) 위에 지금 절정·곧·아직·지남 점으로, 서울 근교 절정일, 9/20~11/25 오늘 피드에
This commit is contained in:
1 parent
74a46dd66a
commit
463978c183
5 files changed
+316
-1
No files matched your search
@@ -5,6 +5,7 @@ import { getFeedOptions, getWeatherTodayOptions } from '../api/client/@tanstack/
|
||||
import { RainType, Sky, type BandArticle, type BandEvent, type Hero as HeroData, type ResWeatherToday, type TalkData, type TopIndex, type WeatherSlot } from '../api/client/types.gen'
|
||||
import { cx } from '../lib/utils'
|
||||
import { cardBg, fall, kindOfHour, kst, type Load, loadOf, MEDALS, type TimeKind, WEEKDAYS } from './lib'
|
||||
import { FoliageCard } from './foliageMap'
|
||||
import { InstallBanner } from './installBanner'
|
||||
import { MyGakRow } from './myGak'
|
||||
import { fromShare } from './myGakState'
|
||||
@@ -411,6 +412,7 @@ export function TodayPage() {
|
||||
{posts.map((p, i) => (
|
||||
<Fragment key={p.post_id}>
|
||||
<PostCard post={p} />
|
||||
{i === 1 && <FoliageCard />}
|
||||
{(i + 1) % 3 === 0 && talks[(i + 1) / 3 - 1] && <TalkCard t={talks[(i + 1) / 3 - 1]} />}
|
||||
{bandAt.find(([at]) => at === i + 1)?.[1]}
|
||||
</Fragment>
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
import { useState } from 'react'
|
||||
import data from '../../seo/foliage_2026.json'
|
||||
import { cx } from '../lib/utils'
|
||||
import { kst } from './lib'
|
||||
import { PostFrame } from './Post'
|
||||
|
||||
type Mountain = { name: string; region: string; lat: number; lon: number; peak: string }
|
||||
type Stage = 'peak' | 'soon' | 'before' | 'after'
|
||||
|
||||
// 지도 그림(public/foliage/korea-map.webp, 1024×1536)의 위경도 → 그림 위 위치. generated-images/foliage-map/korea_outline.json 과 같은 값
|
||||
const MAP = { lon0: 124.0, lon1: 132.2, lat0: 33.0, lat1: 43.1, w: 900, h: 1407, scale: 1.09168, ox: 20.74, cw: 1024, ch: 1536 }
|
||||
const PEAK_DAYS = 3 // 절정일 앞뒤 이만큼은 '지금 절정'
|
||||
const SOON_DAYS = 7
|
||||
const SEASON = { from: '09-20', to: '11-25' }
|
||||
const SEOUL = { lat: 37.566, lon: 126.978 }
|
||||
|
||||
const STAGE: Record<Stage, { label: string; dot: string }> = {
|
||||
peak: { label: '지금 절정', dot: 'bg-[#ff5a36]' },
|
||||
soon: { label: '곧 절정', dot: 'bg-[#ffb02e]' },
|
||||
before: { label: '아직', dot: 'bg-[#7cc47a]' },
|
||||
after: { label: '절정 지남', dot: 'bg-[#b9a69a]' },
|
||||
}
|
||||
|
||||
const pos = (m: Mountain) => ({
|
||||
left: `${((MAP.ox + ((m.lon - MAP.lon0) / (MAP.lon1 - MAP.lon0)) * MAP.w * MAP.scale) / MAP.cw) * 100}%`,
|
||||
top: `${((((MAP.lat1 - m.lat) / (MAP.lat1 - MAP.lat0)) * MAP.h * MAP.scale) / MAP.ch) * 100}%`,
|
||||
})
|
||||
|
||||
const DAY = 86_400_000
|
||||
const days = (from: string, to: string) => Math.round((Date.parse(to) - Date.parse(from)) / DAY)
|
||||
|
||||
function stage(m: Mountain, today: string): Stage {
|
||||
const d = days(today, m.peak)
|
||||
if (Math.abs(d) <= PEAK_DAYS) return 'peak'
|
||||
if (d < 0) return 'after'
|
||||
return d <= SOON_DAYS ? 'soon' : 'before'
|
||||
}
|
||||
|
||||
const md = (iso: string) => `${Number(iso.slice(5, 7))}/${Number(iso.slice(8, 10))}`
|
||||
|
||||
/** 단풍철에만 나오는 단풍 지도 카드. 산마다 절정 예측일로 지금 절정·곧·아직·지남을 점으로 */
|
||||
export function FoliageCard() {
|
||||
const [now] = useState(() => new Date())
|
||||
const t = kst(now)
|
||||
const today = `${t.y}-${String(t.mo).padStart(2, '0')}-${String(t.d).padStart(2, '0')}`
|
||||
const [picked, setPicked] = useState<string | null>(null)
|
||||
const mmdd = today.slice(5)
|
||||
if (mmdd < SEASON.from || mmdd > SEASON.to) return null
|
||||
const mountains = (data.mountains as unknown as Mountain[]).map((m) => ({ ...m, stage: stage(m, today) }))
|
||||
const peakNow = mountains.filter((m) => m.stage === 'peak').map((m) => m.name)
|
||||
// 발표 지도에 서울 안 산은 없어 서울 시청에서 가장 가까운 산으로
|
||||
const seoul = mountains.reduce((a, b) => (Math.hypot(b.lat - SEOUL.lat, b.lon - SEOUL.lon) < Math.hypot(a.lat - SEOUL.lat, a.lon - SEOUL.lon) ? b : a))
|
||||
const sel = mountains.find((m) => m.name === picked)
|
||||
return (
|
||||
<PostFrame title="단풍 지도" account="단풍 지도" avatar="maple" caption={peakNow.length ? `지금 절정: ${peakNow.join(' · ')}` : undefined}>
|
||||
<div className="relative bg-[#e6f2ff] px-4 pt-4 pb-3">
|
||||
<p className="m-0 text-[13px] font-extrabold opacity-75">단풍 지도 · {md(today)}</p>
|
||||
<p className="m-0 mt-1 font-jua text-[24px] leading-tight">서울 근교 {seoul.name} 절정 예상 {md(seoul.peak)}</p>
|
||||
<div className="relative mx-auto mt-2 aspect-[2/3] w-[86%]">
|
||||
<img src="/foliage/korea-map.webp" alt="한반도 지도" className="absolute inset-0 size-full" />
|
||||
{mountains.map((m) => (
|
||||
<button
|
||||
key={m.name}
|
||||
type="button"
|
||||
onClick={() => setPicked(m.name === picked ? null : m.name)}
|
||||
aria-label={`${m.name} ${STAGE[m.stage].label}, 절정 예상 ${md(m.peak)}`}
|
||||
className="absolute -translate-x-1/2 -translate-y-1/2 cursor-pointer p-1.5"
|
||||
style={pos(m)}
|
||||
>
|
||||
<i className={cx('block size-3.5 rounded-full border-2 border-white shadow-[0_1px_4px_rgb(40_48_74/0.35)]', STAGE[m.stage].dot, m.name === picked && 'size-5')} />
|
||||
</button>
|
||||
))}
|
||||
{sel && (
|
||||
<p className="absolute right-0 bottom-0 m-0 rounded-[14px] bg-white/90 px-3 py-2 text-[13px] font-bold shadow-[0_4px_12px_rgb(40_48_74/0.15)]">
|
||||
<b className="font-jua text-[16px] font-normal">{sel.name}</b> {sel.region}
|
||||
<br />
|
||||
{STAGE[sel.stage].label} · 절정 예상 {md(sel.peak)}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
<div className="mt-2 flex flex-wrap justify-center gap-x-3 gap-y-1 text-[12.5px] font-bold">
|
||||
{(Object.keys(STAGE) as Stage[]).map((s) => (
|
||||
<span key={s} className="flex items-center gap-1">
|
||||
<i className={cx('size-2.5 rounded-full', STAGE[s].dot)} />
|
||||
{STAGE[s].label}
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
<p className="m-0 mt-1.5 text-center text-[11px] font-semibold text-(--ink3)">
|
||||
출처: 산림청 2026 단풍절정 예측 · 단풍나무 잎 절반이 물든 때 기준
|
||||
</p>
|
||||
</div>
|
||||
</PostFrame>
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user