feat: 계절 지도 자리에 첫눈 지도·해돋이 지도 — 단풍 지도가 끝나면 첫눈 지도(~12/20, 지점 42곳 평년 첫눈 날짜 + 앞으로 7일 눈 예보, GET /v1/season/first-snow), 12/21부터 해돋이 지도(~2월, 명소 50곳 해 뜨는 시각, 12월엔 새해 첫날 기준). 오늘 탭 아이콘·피드 맨 앞 카드(foliage_post 좋아요·댓글 자리를 이어받음)·/first-snow·/sunrise 페이지·공유 이미지. 지도 확대·이동은 mapView.ts 로 꺼내 단풍 지도와 같이 씀 (GA first_snow_open·first_snow_spot·sunrise_open·sunrise_spot·sunrise_day)

This commit is contained in:
skkim committed 2026-11-20 11:18:54 +09:00
1 parent 4e69c4ac44
commit d7dfc1ba82
30 files changed
+1973 -255

No files matched your search

+10
View File
@@ -41,6 +41,11 @@ export type Events<Sheet extends string = string> = {
shorts_preview: { video_id: string; trigger: 'hover' | 'auto' }
foliage_open: Record<string, never>
foliage_spot: { spot_name: string; from: 'page' | 'card' }
first_snow_open: Record<string, never>
first_snow_spot: { spot_name: string; from: 'page' | 'card' }
sunrise_open: Record<string, never>
sunrise_spot: { spot_name: string; from: 'page' | 'card' }
sunrise_day: { day: 'next' | 'newyear' }
my_gak_save: { gak_name: string }
fortune_draw: { card: string }
day_log: { mood: number; went_out: boolean; card_hit: boolean | null }
@@ -90,6 +95,11 @@ export const GA_NAME: Record<keyof Events, string> = {
shorts_preview: '쇼츠_미리보기',
foliage_open: '단풍지도_열기',
foliage_spot: '단풍명소_보기',
first_snow_open: '첫눈지도_열기',
first_snow_spot: '첫눈지점_보기',
sunrise_open: '해돋이지도_열기',
sunrise_spot: '해돋이명소_보기',
sunrise_day: '해돋이날짜_전환',
my_gak_save: '내각_저장',
fortune_draw: '타로_뽑기',
day_log: '하루_기록',
+56
View File
@@ -0,0 +1,56 @@
// 첫눈 지도 계산 (웹 frontend/src/b/firstSnow.ts 가 쓴다). 지점·평년 날짜·눈 예보는 API(/v1/season/first-snow, backend/services/first_snow.json)에서 받는다.
// 지도 그림·배치 계산은 단풍 지도(shared/lib/foliage.ts)와 같이 쓴다
import type { FirstSnowSpot } from '../api/client/types.gen'
import { foliageInSeason, foliageToday, md, toXY } from './foliage'
/** soon: 앞으로 7일 안에 눈 예보가 있음, before: 평년 첫눈 날짜가 아직 안 옴, passed: 평년 첫눈 날짜가 지남(눈 예보 없음) */
export type SnowStage = 'soon' | 'before' | 'passed'
/** x·y 는 지도 그림 안 위치(0~1), normal 은 평년 첫눈 날짜('YYYY-MM-DD', 이번 겨울 기준), d 는 오늘부터 그날까지 남은 날 수, snowDate 는 눈 예보가 있는 첫 날 */
export type SnowSpot = { name: string; region: string; top: boolean; x: number; y: number; normal: string; d: number; stage: SnowStage; snowDate: string | null; snowCm: number | null }
export const SNOW_STAGE: Record<SnowStage, string> = { soon: '눈 예보', before: '평년 첫눈 전', passed: '평년 첫눈 지남' }
// 첫눈 지도는 단풍 지도가 끝난 다음 날부터(단풍철이 아니면 SEASON_START 부터) SEASON_END 까지 보인다. 그다음 날부터 해돋이 지도(shared/lib/sunrise.ts)
// 평년 첫눈이 가장 이른 대관령이 11/5, 가장 늦은 창원·통영이 12/27 이지만, 해돋이 지도가 새해 전에 충분히 보이도록 12/20 에 끝낸다
const SEASON_START = '11-01'
const SEASON_END = '12-20'
const DAY = 86_400_000
const days = (from: string, to: string) => Math.round((Date.parse(to) - Date.parse(from)) / DAY)
/** 오늘이 첫눈 지도철인지 (오늘 아이콘 줄의 첫눈 지도 칸·피드 첫눈 카드를 보일지) */
export function firstSnowInSeason(today: string = foliageToday()) {
const monthDay = today.slice(5)
return monthDay >= SEASON_START && monthDay <= SEASON_END && !foliageInSeason(today)
}
/** today 기준 지점별 단계, 평년 첫눈이 이른 순(같으면 이름 순). 1~6월에 보면 지난겨울 날짜로 본다 */
export function firstSnowOn(today: string, raw: FirstSnowSpot[]): SnowSpot[] {
const year = Number(today.slice(0, 4)) - (Number(today.slice(5, 7)) <= 6 ? 1 : 0)
return raw
.map((s) => {
const normal = `${year}-${s.normal}`
const d = days(today, normal)
const snowDate = s.snow_date ?? null
const stage: SnowStage = snowDate ? 'soon' : d >= 0 ? 'before' : 'passed'
return { name: s.name, region: s.region, top: !!s.top, ...toXY(s.lat, s.lon), normal, d, stage, snowDate, snowCm: s.snow_cm ?? null }
})
.sort((a, b) => a.normal.localeCompare(b.normal) || a.name.localeCompare(b.name))
}
/** 눈 예보가 있는 곳: 예보 날짜가 가까운 순, 같으면 눈이 많이 오는 순 */
export const snowSoon = (spots: SnowSpot[]) =>
spots.filter((m) => m.stage === 'soon').sort((a, b) => (a.snowDate ?? '').localeCompare(b.snowDate ?? '') || (b.snowCm ?? 0) - (a.snowCm ?? 0) || a.name.localeCompare(b.name))
/** '눈 예보: 전북·충남·강원'(눈 예보가 있는 지점이 많은 시·도 3곳). 없으면 아직 없다고, 예보를 못 받았으면 평년 날짜라고 */
export function firstSnowHeadline(spots: SnowSpot[], forecast: boolean) {
if (!forecast) return '지역별 평년 첫눈 날짜예요'
const soon = spots.filter((m) => m.stage === 'soon')
if (!soon.length) return '이번 주 눈 예보는 아직 없어요'
const count = new Map<string, number>()
for (const m of soon) count.set(m.region, (count.get(m.region) ?? 0) + 1)
return `눈 예보: ${[...count].sort((a, b) => b[1] - a[1]).slice(0, 3).map(([p]) => p).join('·')}`
}
/** 지점 옆에 적는 한 줄: 눈 예보가 있으면 '11/27 눈 예보', 없으면 '평년 11/29' */
export const snowNote = (m: SnowSpot) => (m.snowDate ? `${md(m.snowDate)} 눈 예보` : `평년 ${md(m.normal)}`)
+7 -6
View File
@@ -30,7 +30,8 @@ function stage(peak: string, today: string): Stage {
return d <= FIRST_DAYS ? 'first' : 'before'
}
const toXY = (lat: number, lon: number) => ({ x: (MAP.ox + (lon - MAP.lon0) * MAP.k * MAP.s) / MAP.size, y: (MAP.oy + (MAP.lat1 - lat) * MAP.s) / MAP.size })
/** 위경도 → 지도 그림 안 위치(0~1). 해돋이 지도(shared/lib/sunrise.ts)도 같은 그림을 쓴다 */
export const toXY = (lat: number, lon: number) => ({ x: (MAP.ox + (lon - MAP.lon0) * MAP.k * MAP.s) / MAP.size, y: (MAP.oy + (MAP.lat1 - lat) * MAP.s) / MAP.size })
// 처음 화면 가로 가운데: 명소 가운데(127.9°)로 잡으면 서해 섬까지 든 땅이 왼쪽으로 쏠려 보여 서쪽으로 당김
export const LAND_CX = toXY(36, 127.65).x
@@ -94,14 +95,14 @@ export function headline(spots: Spot[]) {
export const rankNow = (spots: Spot[]) =>
spots.filter((m) => m.stage === 'peak').sort((a, b) => Math.abs(a.d) - Math.abs(b.d) || Number(b.own) - Number(a.own) || a.name.localeCompare(b.name))
export type Pt = { m: Spot; x: number; y: number; r: number }
export type Pt<M extends { name: string } = Spot> = { m: M; x: number; y: number; r: number }
export type Box = { l: number; t: number; r: number; b: number }
export type LabelSize = Record<string, { w: number; h: number }>
const LABEL_GAP = 4
const overlaps = (a: Box, b: Box) => a.l < b.r && b.l < a.r && a.t < b.b && b.t < a.b
/** 시·도 이름 자리(명소 이름표를 먼저 놓은 뒤): 원래 자리가 잎·점·이름표에 덮이면 둘레를 돌며 가장 가까운 빈자리로 옮긴다(최대 반경 R, 바다 쪽도 됨) */
export function placeProvinces(provs: { name: string; x: number; y: number }[], pts: Pt[], labels: Box[] = [], R = 90) {
export function placeProvinces(provs: { name: string; x: number; y: number }[], pts: { x: number; y: number; r: number }[], labels: Box[] = [], R = 90) {
// 앞에서 놓은 시·도 이름도 피한다(서울·경기처럼 붙은 곳)
const placed: Box[] = []
const free = (x: number, y: number) =>
@@ -131,7 +132,7 @@ export const labelBoxes = (at: Record<string, { left: number; top: number }>, si
Object.entries(at).map(([n, a]) => ({ l: a.left, t: a.top, r: a.left + (size[n]?.w ?? 0), b: a.top + (size[n]?.h ?? 0) }))
/** 화면 위 점끼리 겹치면 서로 밀어 떼어 놓는다 (pts 를 고쳐서 돌려줌) */
export function spread(pts: Pt[], gap = 1.5) {
export function spread<P extends { x: number; y: number; r: number }>(pts: P[], gap = 1.5) {
for (let it = 0; it < 60; it++) {
let moved = false
for (let i = 0; i < pts.length; i++)
@@ -157,7 +158,7 @@ export function spread(pts: Pt[], gap = 1.5) {
}
/** 이름표를 점 오른쪽·왼쪽 순으로 놓아 보고(잎과 짝이 헷갈리지 않게 옆 먼저), 점·다른 이름표·막힌 칸과 겹치거나 영역 밖이면 그 이름은 뺀다. 앞 순서가 먼저 자리를 잡는다 */
export function placeLabels(order: Pt[], all: Pt[], size: LabelSize, area: Box, blocked: Box[] = [], vertical: (p: Pt) => boolean = () => false) {
export function placeLabels<M extends { name: string }>(order: Pt<M>[], all: Pt<M>[], size: LabelSize, area: Box, blocked: Box[] = [], vertical: (p: Pt<M>) => boolean = () => false) {
const dots = all.map((p) => ({ name: p.m.name, box: { l: p.x - p.r, t: p.y - p.r, r: p.x + p.r, b: p.y + p.r } }))
const taken = [...blocked.map((box) => ({ name: '', box })), ...dots]
const out: Record<string, { left: number; top: number }> = {}
@@ -190,7 +191,7 @@ export function placeLabels(order: Pt[], all: Pt[], size: LabelSize, area: Box,
}
/** 누른 자리에서 가장 가까운 명소 (잎이 작아 손가락으로 겨냥하기 어려워서). 반경 r 안에 없으면 null */
export function nearest(pts: Pt[], x: number, y: number, r = 24) {
export function nearest(pts: Pt<{ name: string }>[], x: number, y: number, r = 24) {
let best: string | null = null
let bestD = r
for (const p of pts) {
+90
View File
@@ -0,0 +1,90 @@
// 해돋이 지도 데이터·계산 (웹 frontend/src/b/sunrise.ts 가 쓴다). 지도 그림·배치 계산은 단풍 지도(shared/lib/foliage.ts)와 같이 쓴다
import data from '../../frontend/seo/sunrise_spots.json'
import { kst } from '.'
import { firstSnowInSeason } from './firstSnow'
import { foliageToday, toXY } from './foliage'
export type Coast = 'east' | 'south' | 'west' | 'inland'
type Raw = { name: string; coast: Coast; region: string; lat: number; lon: number; top?: boolean }
/** x·y 는 지도 그림 안 위치(0~1), rise·dawn 은 그날 0시부터 센 분(한국 시각), az 는 해 뜨는 방향(북 0° 시계 방향), top 은 대표 명소 */
export type SunSpot = { name: string; coast: Coast; region: string; top: boolean; x: number; y: number; rise: number; dawn: number; az: number }
/** next 는 다가오는 해돋이(아침 9시 전이면 오늘, 지나면 내일), newyear 는 1월 1일 */
export type SunDayKey = 'next' | 'newyear'
export type SunDay = { key: SunDayKey; date: string; label: string }
export const COAST: Record<Coast, string> = { east: '동해', south: '남해·제주', west: '서해', inland: '산·도심' }
// 해 뜨는 시각: 해 윗부분이 수평선에 닿는 때(대기 굴절 포함 -0.833°). 여명: 해 고도 -6°(시민박명), 이때부터 하늘이 밝아진다
const SUN_ALTITUDE = -0.833
const CIVIL_ALTITUDE = -6
const KST_MIN = 540
// 이 시각이 지나면 오늘 해돋이는 끝난 것으로 보고 내일 것을 보여 준다
const NEXT_FROM_HOUR = 9
const SEASON_MONTHS = [12, 1, 2]
const DOKDO = { lat: 37.2426, lon: 131.8672 }
const DIRS = ['북', '북동', '동', '남동', '남', '남서', '서', '북서']
const DAY = 86_400_000
const rad = (d: number) => (d * Math.PI) / 180
const deg = (r: number) => (r * 180) / Math.PI
/** NOAA 근사식(backend/services/calc/sun.py 와 같은 식). 태양 적위(라디안)와 남중 시각(UTC 분) */
function solar(iso: string, lon: number) {
const [y, m, d] = iso.split('-').map(Number)
const g = ((2 * Math.PI) / 365) * Math.round((Date.UTC(y, m - 1, d) - Date.UTC(y, 0, 1)) / DAY)
const eqtime = 229.18 * (0.000075 + 0.001868 * Math.cos(g) - 0.032077 * Math.sin(g) - 0.014615 * Math.cos(2 * g) - 0.040849 * Math.sin(2 * g))
const decl =
0.006918 - 0.399912 * Math.cos(g) + 0.070257 * Math.sin(g) - 0.006758 * Math.cos(2 * g) + 0.000907 * Math.sin(2 * g) - 0.002697 * Math.cos(3 * g) + 0.00148 * Math.sin(3 * g)
return { decl, noon: 720 - 4 * lon - eqtime }
}
/** 해가 그 고도에 있을 때부터 남중까지 걸리는 분 */
function untilNoon(lat: number, decl: number, altitude: number) {
const cosH = (Math.sin(rad(altitude)) - Math.sin(rad(lat)) * Math.sin(decl)) / (Math.cos(rad(lat)) * Math.cos(decl))
return deg(Math.acos(Math.max(-1, Math.min(1, cosH)))) * 4
}
/** 그날 그 자리의 해 뜨는 시각·여명 시작(0시부터 센 분, 한국 시각)과 해 뜨는 방향. 해발 0m 기준 */
export function sunriseAt(iso: string, lat: number, lon: number) {
const { decl, noon } = solar(iso, lon)
return {
rise: noon - untilNoon(lat, decl, SUN_ALTITUDE) + KST_MIN,
dawn: noon - untilNoon(lat, decl, CIVIL_ALTITUDE) + KST_MIN,
az: Math.round(deg(Math.acos(Math.max(-1, Math.min(1, Math.sin(decl) / Math.cos(rad(lat))))))),
}
}
/** 0시부터 센 분 → '7:31' */
export function clock(min: number) {
const m = Math.round(min)
return `${Math.floor(m / 60)}:${String(m % 60).padStart(2, '0')}`
}
/** 118° → '남동' */
export const direction = (az: number) => DIRS[Math.round(az / 45) % 8]
/** 고를 수 있는 날: 12월엔 새해 첫날이 먼저, 그다음 다가오는 해돋이. 다가오는 해돋이가 1월 1일이면 새해 첫날 하나만 */
export function sunriseDays(now: Date = new Date()): SunDay[] {
const t = kst(now)
const today = t.h < NEXT_FROM_HOUR
const date = new Date(Date.UTC(t.y, t.mo - 1, t.d + (today ? 0 : 1))).toISOString().slice(0, 10)
if (date.endsWith('-01-01')) return [{ key: 'newyear', date, label: '새해 첫날' }]
const next: SunDay = { key: 'next', date, label: today ? '오늘' : '내일' }
return t.mo === 12 ? [{ key: 'newyear', date: `${t.y + 1}-01-01`, label: '새해 첫날' }, next] : [next]
}
/** 지금이 해돋이철인지 (오늘 아이콘 줄의 해돋이 지도 칸·피드 해돋이 카드를 보일지). 12~2월 가운데 첫눈 지도가 끝난 다음 날부터: 같은 자리를 첫눈 지도가 먼저 쓴다 */
export const sunriseInSeason = (now: Date = new Date()) => SEASON_MONTHS.includes(kst(now).mo) && !firstSnowInSeason(foliageToday(now))
/** 그날 명소별 해 뜨는 시각, 이른 순(같으면 이름 순) */
export function sunriseOn(date: string): SunSpot[] {
return (data.spots as Raw[])
.map(({ name, coast, region, lat, lon, top }) => ({ name, coast, region, top: !!top, ...toXY(lat, lon), ...sunriseAt(date, lat, lon) }))
.sort((a, b) => Math.round(a.rise) - Math.round(b.rise) || a.name.localeCompare(b.name))
}
/** 우리나라에서 해가 가장 먼저 뜨는 독도의 그날 해 뜨는 시각 (지도 그림 밖이라 명소 목록에는 없다) */
export const dokdoRise = (date: string) => sunriseAt(date, DOKDO.lat, DOKDO.lon).rise
/** '새해 첫 해는 간절곶 7:31부터' — spots 는 이른 순 */
export const sunriseHeadline = (day: SunDay, spots: SunSpot[]) => `${day.key === 'newyear' ? '새해' : day.label} 첫 해는 ${spots[0].name} ${clock(spots[0].rise)}부터`