11import { useEffect , useRef , useState } from 'react' ;
2- import type { RepairShop } from './types' ;
2+ import type { KakaoMapInstance , KakaoMaps , KakaoMarker , KakaoOverlay , RepairShop } from './types' ;
33
44const buildOverlayContent = ( shop : RepairShop ) => {
55 const phoneLink = shop . phone ? `<a href="tel:${ shop . phone } ">전화</a>` : '' ;
@@ -24,13 +24,13 @@ const buildOverlayContent = (shop: RepairShop) => {
2424
2525export const useRepairMap = ( ) => {
2626 const mapRef = useRef < HTMLDivElement | null > ( null ) ;
27- const mapInstanceRef = useRef < any > ( null ) ;
28- const markersRef = useRef < any [ ] > ( [ ] ) ;
29- const overlayRef = useRef < any > ( null ) ;
27+ const mapInstanceRef = useRef < KakaoMapInstance | null > ( null ) ;
28+ const markersRef = useRef < KakaoMarker [ ] > ( [ ] ) ;
29+ const overlayRef = useRef < KakaoOverlay | null > ( null ) ;
3030 const [ isMapReady , setIsMapReady ] = useState ( false ) ;
3131
3232 useEffect ( ( ) => {
33- const kakao = ( window as any ) . kakao ;
33+ const kakao = ( window as Window & { kakao ?: { maps ?: KakaoMaps } } ) . kakao ;
3434
3535 if ( ! mapRef . current ) {
3636 return ;
@@ -46,7 +46,7 @@ export const useRepairMap = () => {
4646
4747 const map = new kakao . maps . Map ( mapRef . current , options ) ;
4848 mapInstanceRef . current = map ;
49- overlayRef . current = new kakao . maps . CustomOverlay ( { yAnchor : 1 , zIndex : 10 } ) ;
49+ overlayRef . current = new kakao . maps . CustomOverlay ( { yAnchor : 1 , zIndex : 10 , clickable : true } ) ;
5050 kakao . maps . event . addListener ( map , 'click' , ( ) => {
5151 overlayRef . current ?. setMap ( null ) ;
5252 } ) ;
@@ -74,16 +74,20 @@ export const useRepairMap = () => {
7474 } ;
7575
7676 const setCenter = ( lat : number , lng : number ) => {
77- const kakao = ( window as any ) . kakao ;
77+ const kakao = ( window as Window & { kakao ?: { maps ?: KakaoMaps } } ) . kakao ;
7878 const map = mapInstanceRef . current ;
79- if ( ! kakao ?. maps || ! map ) { return ; }
79+ if ( ! kakao ?. maps || ! map ) {
80+ return ;
81+ }
8082 map . setCenter ( new kakao . maps . LatLng ( lat , lng ) ) ;
8183 } ;
8284
8385 const openOverlayForShop = ( shop : RepairShop ) => {
84- const kakao = ( window as any ) . kakao ;
86+ const kakao = ( window as Window & { kakao ?: { maps ?: KakaoMaps } } ) . kakao ;
8587 const map = mapInstanceRef . current ;
86- if ( ! kakao ?. maps || ! map ) { return ; }
88+ if ( ! kakao ?. maps || ! map ) {
89+ return ;
90+ }
8791
8892 const position = new kakao . maps . LatLng ( shop . lat , shop . lng ) ;
8993 map . panTo ( position ) ;
@@ -94,25 +98,28 @@ export const useRepairMap = () => {
9498 position,
9599 yAnchor : 1 ,
96100 zIndex : 10 ,
101+ clickable : true ,
97102 } ) ;
98103
99104 overlay . setMap ( map ) ;
100105 overlayRef . current = overlay ;
101106 } ;
102107
103108 const setMarkers = ( shops : RepairShop [ ] ) => {
104- const kakao = ( window as any ) . kakao ;
109+ const kakao = ( window as Window & { kakao ?: { maps ?: KakaoMaps } } ) . kakao ;
105110 const map = mapInstanceRef . current ;
106- if ( ! kakao ?. maps || ! map ) { return ; }
111+ if ( ! kakao ?. maps || ! map ) {
112+ return ;
113+ }
107114
108115 clearMarkers ( ) ;
109- if ( shops . length === 0 ) { return ; }
116+ if ( shops . length === 0 ) {
117+ return ;
118+ }
110119
111- const markerImage = new kakao . maps . MarkerImage (
112- '/repair-marker.svg' ,
113- new kakao . maps . Size ( 36 , 48 ) ,
114- { offset : new kakao . maps . Point ( 18 , 48 ) }
115- ) ;
120+ const markerImage = new kakao . maps . MarkerImage ( '/repair-marker.svg' , new kakao . maps . Size ( 36 , 48 ) , {
121+ offset : new kakao . maps . Point ( 18 , 48 ) ,
122+ } ) ;
116123
117124 const bounds = new kakao . maps . LatLngBounds ( ) ;
118125 shops . forEach ( ( shop ) => {
0 commit comments