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:
1 parent
4e69c4ac44
commit
d7dfc1ba82
30 files changed
+1973
-255
No files matched your search
@@ -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) {
|
||||
|
||||
Reference in new issue
Block a user