fix(map): 클러스터 expansion 후 마커 클릭 시 재묶임 방지

- selected 시 무조건 zoom 16 → 줌 18에서 마커 클릭하면 다시 16으로 줄어 클러스터링
- 현재 zoom ≥ 16이면 유지, 미만이면 16으로 (Naver/Google 둘 다)
- page.tsx의 setRegionFlyTo 호출 제거 — selected useEffect로 일원화

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

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
joungmin
2026-06-17 10:09:22 +09:00
parent 14384b0c71
commit 2eb16ce861
4 changed files with 15 additions and 8 deletions

View File

@@ -385,10 +385,8 @@ export default function Home() {
const handleSelectRestaurant = useCallback((r: Restaurant) => {
setSelected(r);
setShowDetail(true);
// 지도가 선택 식당으로 이동/줌인 — 객체 새로 만들어 flyTo effect 매번 트리거
if (r.latitude != null && r.longitude != null) {
setRegionFlyTo({ lat: r.latitude, lng: r.longitude, zoom: 16 });
}
// selected 변경 자체가 MapView 내부의 useEffect에서 중앙 이동을 처리.
// (flyTo를 같이 set하면 줌 16으로 강제되어 클러스터 expansion 후 마커 클릭 시 다시 묶임)
}, []);
const handleCloseDetail = useCallback(() => {

View File

@@ -163,11 +163,12 @@ function MapContent({ restaurants, selected, onSelectRestaurant, flyTo, activeCh
if (flyTo.zoom) map.setZoom(flyTo.zoom);
}, [map, flyTo]);
// Pan and zoom to selected restaurant
// Pan and zoom to selected restaurant — 현재 줌이 16 이상이면 유지(클러스터 expansion 후 재묶임 방지)
useEffect(() => {
if (!map || !selected) return;
map.panTo({ lat: selected.latitude, lng: selected.longitude });
map.setZoom(16);
const currentZoom = map.getZoom() ?? 13;
if (currentZoom < 16) map.setZoom(16);
setInfoTarget(selected);
}, [map, selected]);

View File

@@ -241,12 +241,15 @@ export default function NaverMapView({
else m.panTo(latlng);
}, [flyTo]);
// selected 변경 시 자동 중앙 + zoom
// selected 변경 시 자동 중앙 — 현재 줌이 16 이상이면 그대로, 미만이면 16으로 확대
// (클러스터 expansion으로 18까지 들어간 상태에서 마커 클릭 시 다시 16으로 줄어 클러스터링되는 것 방지)
useEffect(() => {
const m = mapRef.current;
if (!m || !selected || !window.naver?.maps) return;
if (selected.latitude == null || selected.longitude == null) return;
m.morph(new window.naver.maps.LatLng(selected.latitude, selected.longitude), 16);
const latlng = new window.naver.maps.LatLng(selected.latitude, selected.longitude);
const targetZoom = Math.max(m.getZoom(), 16);
m.morph(latlng, targetZoom);
}, [selected]);
// 클러스터 계산 (bounds/zoom 변경 시)