fix: 단풍 지도 — 어린이대공원 추가, 지도 가운데 맞춤, +/− 연타 시 반대로 확대되던 문제
This commit is contained in:
1 parent
1bfa224c62
commit
f4cb2217ed
4 files changed
+23
-6
No files matched your search
@@ -1,7 +1,7 @@
|
||||
import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react'
|
||||
import { useNavigate, useSearchParams } from 'react-router'
|
||||
import { cx } from '../lib/utils'
|
||||
import { ICON_R, LABEL, LABEL_INK, LEAF_SHADOW, MAP_IMG, MAP_SRC, PROVINCE, PROVINCES, labelBoxes, placeProvinces, rankNow, STAGE, headline, md, placeLabels, spread, useFoliage, useLabelSize, type Box, type Kind, type Pt, type Spot, type Stage } from './foliage'
|
||||
import { ICON_R, LABEL, LABEL_INK, LAND_CX, LEAF_SHADOW, MAP_IMG, MAP_SRC, PROVINCE, PROVINCES, labelBoxes, placeProvinces, rankNow, STAGE, headline, md, placeLabels, spread, useFoliage, useLabelSize, type Box, type Kind, type Pt, type Spot, type Stage } from './foliage'
|
||||
import { useSheet } from './sheetContext'
|
||||
import { FoliageMapShare, FoliageSpotShare } from './shareCards'
|
||||
import { SendIcon } from './svg'
|
||||
@@ -52,7 +52,7 @@ function Marker({ p, sel }: { p: Pt; sel: boolean }) {
|
||||
)
|
||||
}
|
||||
|
||||
/** 단풍 지도 페이지: 명소 65곳을 지도에서 확대해 보고 목록으로 고른다. 한 손가락은 확대 전엔 페이지 스크롤, 확대 뒤엔 지도 이동 */
|
||||
/** 단풍 지도 페이지: 명소 66곳을 지도에서 확대해 보고 목록으로 고른다. 한 손가락은 확대 전엔 페이지 스크롤, 확대 뒤엔 지도 이동 */
|
||||
export function FoliagePage() {
|
||||
const navigate = useNavigate()
|
||||
const [params] = useSearchParams()
|
||||
@@ -85,8 +85,10 @@ export function FoliagePage() {
|
||||
const [x0, x1, y0, y1] = [Math.min(...xs), Math.max(...xs), Math.min(...ys), Math.max(...ys)]
|
||||
// 위쪽은 맨 북쪽 이름표가 잘리지 않게 FIT_TOP 만큼 띄우고, 아래는 제주까지만
|
||||
const h = H - FIT_TOP - FIT_BOTTOM
|
||||
const s = Math.min(W / ((x1 - x0 + 0.14) * W), h / ((y1 - y0) * W))
|
||||
return { s, tx: W / 2 - ((x0 + x1) / 2) * W * s, ty: FIT_TOP + h / 2 - ((y0 + y1) / 2) * W * s }
|
||||
// 가로는 땅 가운데(LAND_CX)에 맞추되 동·서 끝 명소가 다 들어오게
|
||||
const half = Math.max(LAND_CX - x0, x1 - LAND_CX) + 0.07
|
||||
const s = Math.min(W / (2 * half * W), h / ((y1 - y0) * W))
|
||||
return { s, tx: W / 2 - LAND_CX * W * s, ty: FIT_TOP + h / 2 - ((y0 + y1) / 2) * W * s }
|
||||
}, [box, spots])
|
||||
|
||||
const clamp = useCallback(
|
||||
@@ -289,6 +291,8 @@ export function FoliagePage() {
|
||||
drag = null
|
||||
}
|
||||
const onDbl = (e: MouseEvent) => {
|
||||
// +/− 를 빨리 두 번 누른 건 확대로 치지 않는다
|
||||
if ((e.target as HTMLElement).closest('button')) return
|
||||
const p = local(e)
|
||||
zoomAt(2, p.x, p.y, true)
|
||||
}
|
||||
|
||||
@@ -30,6 +30,8 @@ function stage(peak: string, today: string): Stage {
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
// 지도 위 시·도 이름 자리(위경도). 서울·경기는 겹치지 않게 경기를 북쪽으로 조금 올림
|
||||
export const PROVINCES = (
|
||||
@@ -50,7 +52,7 @@ export const PROVINCES = (
|
||||
export const md = (iso: string) => `${Number(iso.slice(5, 7))}/${Number(iso.slice(8, 10))}`
|
||||
const province = (m: Spot) => m.region.split(' ')[0].split('·')
|
||||
|
||||
/** 오늘(한국 시각) 기준 명소 65곳과 단계. 단풍철이 아니면 inSeason 이 false */
|
||||
/** 오늘(한국 시각) 기준 명소 66곳과 단계. 단풍철이 아니면 inSeason 이 false */
|
||||
export function useFoliage() {
|
||||
const [today] = useState(() => {
|
||||
const t = kst(new Date())
|
||||
|
||||
@@ -67,7 +67,8 @@ export function FoliageCard({ post }: { post?: PostReaction | null }) {
|
||||
<div ref={sliderRef} className="overflow-hidden" role="region" aria-label="슬라이드 2장, 옆으로 넘겨 보세요">
|
||||
<div className="flex">
|
||||
<div className="min-w-0 shrink-0 grow-0 basis-full">
|
||||
<div ref={mapRef} onClick={tapMap} className="b-keep-bg relative mx-auto aspect-square w-full bg-[#fff6ea]">
|
||||
{/* 지도 그림은 땅이 왼쪽에 치우쳐 있어 오른쪽(빈 바다)으로 밀어 가운데에 맞춘다 */}
|
||||
<div ref={mapRef} onClick={tapMap} className="b-keep-bg relative mx-auto aspect-square w-full translate-x-[7%] bg-[#fff6ea]">
|
||||
<img src={MAP_SRC} alt="" className={MAP_IMG} />
|
||||
{provs.map((v) => (
|
||||
<span key={v.name} aria-hidden="true" className={PROVINCE} style={{ left: v.x, top: v.y }}>
|
||||
|
||||
Reference in new issue
Block a user