Files
tasteby/frontend/src/components/MapView.tsx
joungmin f17ba9e37a feat(map): #363 메인 지도 SDK 국내(네이버)/해외(구글) 분기
- MapView dispatcher: NAVER 키 + KR bbox 좌표 → NaverMapView
- NaverMapView 신규 (네이버 v3 직접 wrapper, Supercluster 재사용)
- GoogleMapView 신규 (기존 MapView 내용 rename)
- MapView.types.ts 공용 타입 + isKoreaCoord 헬퍼
- Dockerfile/deploy.sh: NEXT_PUBLIC_NAVER_MAP_CLIENT_ID build-arg
- 키 미설정 시 GoogleMap fallback (회귀 0)

Refs: #363

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-16 06:25:47 +09:00

38 lines
1.4 KiB
TypeScript

"use client";
import GoogleMapView from "@/components/GoogleMapView";
import NaverMapView from "@/components/NaverMapView";
import { isKoreaCoord, type MapBounds, type FlyTo, type MapViewProps } from "@/components/MapView.types";
export type { MapBounds, FlyTo };
const NAVER_KEY = process.env.NEXT_PUBLIC_NAVER_MAP_CLIENT_ID || "";
/**
* #363 — 메인 지도 dispatcher.
* - 키 미설정: GoogleMap (회귀 0)
* - flyTo 또는 selected 좌표가 KR bbox: NaverMap
* - 그 외 (해외 + 좌표 추정): GoogleMap
* - 초기 마운트 시 화면 중심을 추정할 수 없으면 식당 평균 좌표로.
*/
export default function MapView(props: MapViewProps) {
if (!NAVER_KEY) return <GoogleMapView {...props} />;
const targetLat = props.flyTo?.lat ?? props.selected?.latitude ?? avgLat(props.restaurants);
const targetLng = props.flyTo?.lng ?? props.selected?.longitude ?? avgLng(props.restaurants);
if (targetLat != null && targetLng != null && isKoreaCoord(targetLat, targetLng)) {
return <NaverMapView {...props} />;
}
return <GoogleMapView {...props} />;
}
function avgLat(rs: MapViewProps["restaurants"]): number | null {
if (!rs.length) return null;
return rs.reduce((s, r) => s + r.latitude, 0) / rs.length;
}
function avgLng(rs: MapViewProps["restaurants"]): number | null {
if (!rs.length) return null;
return rs.reduce((s, r) => s + r.longitude, 0) / rs.length;
}