fix: 단풍 지도 점이 빽빽해 보이던 문제 — 절정만 테두리 점으로 띄우고 나머지는 작은 점으로, 지도를 누르면 가장 가까운 명소가 열리게

This commit is contained in:
minaChoi committed 2026-10-23 09:22:23 +09:00
1 parent 9a75b02d1a
commit 446af2e9b5
1 file changed
+41 -16
+41 -16
View File
@@ -14,23 +14,25 @@ const MAP = { lon0: 124.5, lat1: 38.75, k: 0.809017, s: 153.5327, ox: 40, oy: 62
const FIRST_DAYS = 14
const PEAK_DAYS = 3
const PEAK_AFTER = 7
// 점 반지름(테두리 포함, px)과 점 사이 최소 틈
const DOT_R: Record<Stage, number> = { before: 5.5, first: 6.5, peak: 8, gone: 5.5 }
// 점 반지름(테두리 포함, px)과 점 사이 최소 틈, 지도를 눌렀을 때 가장 가까운 명소를 고르는 거리
const DOT_R: Record<Stage, number> = { before: 2.5, first: 3, peak: 7.5, gone: 2.5 }
const GAP = 1.5
const TAP_R = 22
const STAGE: Record<Stage, string> = { before: '단풍 전', first: '첫 단풍', peak: '절정', gone: '' }
const KIND: Record<Kind, string> = { maple: '단풍', ginkgo: '은행' }
// 절정만 테두리·그림자로 띄우고, 나머지는 테두리 없는 작은 점으로 지도 결에 묻는다
const DOT: Record<Stage, string> = {
before: 'size-2 bg-[#b9bcc6]',
first: 'size-2.5 bg-[#f39a3d]',
peak: 'size-[13px] bg-[#e0442e]',
gone: 'size-2 bg-[#b9bcc6]',
before: 'size-[5px] bg-[#8f8a80]/55',
first: 'size-[6px] bg-[#d9772e]/80',
peak: 'size-[13px] border-2 border-white bg-[#e0442e] shadow-[0_1px_3px_rgb(40_48_74/0.35)]',
gone: 'size-[5px] bg-[#8f8a80]/55',
}
const LEGEND = [
{ label: '단풍 전', color: 'bg-[#b9bcc6]' },
{ label: '첫 단풍', color: 'bg-[#f39a3d]' },
{ label: '절정 단풍', color: 'bg-[#e0442e]' },
{ label: '절정 은행', color: 'bg-[#f2c230]' },
{ label: '단풍 전', dot: DOT.before },
{ label: '첫 단풍', dot: DOT.first },
{ label: '절정 단풍', dot: DOT.peak },
{ label: '절정 은행', dot: cx(DOT.peak, 'bg-[#f2c230]') },
]
const xy = (m: Spot) => [(MAP.ox + (m.lon - MAP.lon0) * MAP.k * MAP.s) / MAP.size, (MAP.oy + (MAP.lat1 - m.lat) * MAP.s) / MAP.size]
@@ -145,13 +147,28 @@ export function FoliageCard() {
if (days(peaks[0], today) < -FIRST_DAYS || days(peaks[peaks.length - 1], today) > PEAK_AFTER) return null
const peakNow = spots.filter((m) => m.stage === 'peak').map((m) => m.name)
const sel = spots.find((m) => m.name === picked)
// 작은 점도 손가락으로 고를 수 있게 누른 자리에서 가장 가까운 명소를 연다
const tapNearest = (e: React.MouseEvent<HTMLDivElement>) => {
const r = e.currentTarget.getBoundingClientRect()
const x = e.clientX - r.left
const y = e.clientY - r.top
let best: string | null = null
let bestD = TAP_R
for (const m of spots) {
const [nx, ny] = xy(m)
const p = at[m.name] ?? { x: nx * r.width, y: ny * r.width }
const d = Math.hypot(p.x - x, p.y - y)
if (d < bestD) [best, bestD] = [m.name, d]
}
setPicked(best === picked ? null : best)
}
const order = [...spots].sort((a, b) => Number(a.stage === 'peak') - Number(b.stage === 'peak'))
return (
<PostFrame title="단풍 지도" account="단풍 지도" avatar="maple" caption={peakNow.length ? `지금 절정 ${peakNow.length}곳: ${peakNow.slice(0, 5).join(' · ')}${peakNow.length > 5 ? ' 외' : ''}` : undefined}>
<div className="relative bg-[#fff6ea] 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">{headline(spots)}</p>
<div ref={mapRef} className="relative mx-auto mt-1 aspect-square w-full">
<div ref={mapRef} onClick={tapNearest} className="relative mx-auto mt-1 aspect-square w-full">
<img src="/foliage/korea-map.webp" alt="단풍 지도" className="absolute inset-0 size-full mix-blend-multiply brightness-[1.08] saturate-[.3]" />
{order.map((m) => {
const [x, y] = xy(m)
@@ -160,13 +177,16 @@ export function FoliageCard() {
<button
key={m.name}
type="button"
onClick={() => setPicked(m.name === picked ? null : m.name)}
onClick={(e) => {
e.stopPropagation()
setPicked(m.name === picked ? null : m.name)
}}
aria-label={`${m.name} ${KIND[m.kind]} ${STAGE[m.stage]}, 절정 예상 ${md(m.peak)}`}
className={cx(
'absolute -translate-x-1/2 -translate-y-1/2 cursor-pointer rounded-full border-[1.5px] border-white p-0 shadow-[0_1px_2px_rgb(40_48_74/0.35)]',
'absolute -translate-x-1/2 -translate-y-1/2 cursor-pointer rounded-full border-0 p-0',
DOT[m.stage],
m.stage === 'peak' && m.kind === 'ginkgo' && 'bg-[#f2c230]',
m.name === picked && 'z-[2] scale-150',
m.name === picked && 'z-[2] scale-150 outline-2 outline-offset-1 outline-[#28304a]',
)}
style={p ? { left: p.x, top: p.y } : { left: `${x * 100}%`, top: `${y * 100}%` }}
/>
@@ -179,7 +199,10 @@ export function FoliageCard() {
data-label={m.name}
tabIndex={-1}
aria-hidden="true"
onClick={() => setPicked(m.name === picked ? null : m.name)}
onClick={(e) => {
e.stopPropagation()
setPicked(m.name === picked ? null : m.name)
}}
className={cx(
'absolute cursor-pointer rounded-[7px] border-0 bg-white/92 px-[5px] py-px text-[11.5px] leading-[1.35] font-extrabold whitespace-nowrap text-[#b5321f] shadow-[0_1px_3px_rgb(40_48_74/0.18)]',
!labelAt[m.name] && 'invisible',
@@ -201,7 +224,9 @@ export function FoliageCard() {
<div className="mt-2 flex flex-wrap items-center justify-center gap-x-3 gap-y-1 text-[12.5px] font-bold">
{LEGEND.map((l) => (
<span key={l.label} className="flex items-center gap-1">
<i className={cx('inline-block size-2.5 rounded-full border-[1.5px] border-white shadow-[0_0_0_1px_rgb(40_48_74/0.15)]', l.color)} />
<i className="grid size-[13px] place-items-center">
<i className={cx('block rounded-full', l.dot)} />
</i>
{l.label}
</span>
))}