/** * 일정 지도 — OpenStreetMap 타일을 직접 깔고 그 위에 번호 핀을 찍는다. * * ★ 왜 iframe 이 아닌가 * iframe 임베드는 핀을 하나밖에 못 찍고, 순서(1→2→3)를 그릴 수 없다. 일정에서 중요한 건 * "어디"가 아니라 "어떤 순서로 도는가"라 경로가 보여야 한다. * ★ 타일은 회색으로 눌러 깐다(`grayscale opacity .55`). 지도가 선명하면 핀과 경로가 묻힌다. * ★ 핀을 누르면 네이버 길찾기로 간다 — 앞 정거장에서 이 정거장까지. 우리가 경로를 * 계산해 그리지 않는다(지어낸 시간을 그릴 수 없다). */ const TILE = 256; /** 경위도 → Web Mercator 픽셀(줌 z 기준). */ function project(lat: number, lng: number, z: number) { const n = 2 ** z; const x = ((lng + 180) / 360) * n * TILE; const s = Math.sin((lat * Math.PI) / 180); const y = ((0.5 - Math.log((1 + s) / (1 - s)) / (4 * Math.PI)) * n) * TILE; return {x, y}; } export interface TripPoint { name: string; latitude: number; longitude: number; searchQuery?: string; } export function TripMap({points, width = 320, height = 168}: { points: TripPoint[]; width?: number; height?: number; }) { if (points.length === 0) return null; const lats = points.map((p) => p.latitude); const lngs = points.map((p) => p.longitude); const center = {lat: (Math.min(...lats) + Math.max(...lats)) / 2, lng: (Math.min(...lngs) + Math.max(...lngs)) / 2}; // 모든 점이 상자 안에 들어오는 가장 큰 줌. 한 점뿐이면 동네가 보이는 15로 둔다. let zoom = 15; for (let z = 16; z >= 10; z -= 1) { const xs = points.map((p) => project(p.latitude, p.longitude, z).x); const ys = points.map((p) => project(p.latitude, p.longitude, z).y); const w = Math.max(...xs) - Math.min(...xs); const h = Math.max(...ys) - Math.min(...ys); if (w <= width - 56 && h <= height - 56) { zoom = z; break; } } const c = project(center.lat, center.lng, zoom); const originX = c.x - width / 2; const originY = c.y - height / 2; // 화면을 덮는 타일만 깐다. const tiles: {x: number; y: number; left: number; top: number}[] = []; const tx0 = Math.floor(originX / TILE); const ty0 = Math.floor(originY / TILE); const tx1 = Math.floor((originX + width) / TILE); const ty1 = Math.floor((originY + height) / TILE); for (let tx = tx0; tx <= tx1; tx += 1) { for (let ty = ty0; ty <= ty1; ty += 1) { tiles.push({x: tx, y: ty, left: tx * TILE - originX, top: ty * TILE - originY}); } } const naverTo = (from: TripPoint | undefined, to: TripPoint) => { const dest = `${to.longitude},${to.latitude},${encodeURIComponent(to.name)}`; const start = from ? `${from.longitude},${from.latitude},${encodeURIComponent(from.name)}` : '-'; return `https://map.naver.com/p/directions/${start}/${dest}/-/transit`; }; return (
{tiles.map((tile) => ( ))} {points.map((point, index) => { const p = project(point.latitude, point.longitude, zoom); return ( {index + 1} ); })} © OpenStreetMap
); }