@@ -2,6 +2,9 @@ import { infoWindowGenerator, mapInfoWindowGenerator } from '@/utils/infoGenerat
22import { MarkerType , PlaceType } from '@/pages/Home/types' ;
33import { PositionType } from './hooks/useCurrentPosition' ;
44import { OTHER_MARKER_IMAGE } from '@/utils/constant' ;
5+ import { detectDevice } from '@/utils/detectDevice' ;
6+
7+ const device = detectDevice ( ) ;
58
69export const openInfoWindow = ( map : any , marker : any ) => {
710 const infowindow = new window . kakao . maps . InfoWindow ( {
@@ -16,6 +19,8 @@ export const addZoomControler = (map: any) => {
1619} ;
1720
1821export const makeMarkers = ( map : any , places : PlaceType [ ] ) : MarkerType [ ] => {
22+ let openedInfoWindow : any = null ;
23+
1924 const markers = places
2025 . map ( ( { title, mapy, mapx, firstimage, contentid } ) => ( {
2126 hoverBox : mapInfoWindowGenerator ( title , firstimage || '/images/no-image.png' ) ,
@@ -38,12 +43,25 @@ export const makeMarkers = (map: any, places: PlaceType[]): MarkerType[] => {
3843
3944 new window . kakao . maps . event . addListener ( marker , 'mouseover' , ( ) => infowindow . open ( map , marker ) ) ;
4045 new window . kakao . maps . event . addListener ( marker , 'mouseout' , ( ) => infowindow . close ( ) ) ;
41- new window . kakao . maps . event . addListener ( map , 'bounds_changed' , ( ) => infowindow . close ( ) ) ;
42- new window . kakao . maps . event . addListener ( marker , 'click' , ( ) =>
43- window . open (
44- `https://search.naver.com/search.naver?where=nexearch&sm=top_hty&fbm=0&ie=utf8&query=${ place . title } `
45- )
46- ) ;
46+ new window . kakao . maps . event . addListener ( map , 'bounds_changed' , ( ) => device === 'PC' && infowindow . close ( ) ) ;
47+ new window . kakao . maps . event . addListener ( marker , 'click' , ( ) => {
48+ if ( device === 'PC' ) {
49+ window . open (
50+ `https://search.naver.com/search.naver?where=nexearch&sm=top_hty&fbm=0&ie=utf8&query=${ place . title } `
51+ ) ;
52+ } else {
53+ // 이전에 열려있던 infowindow가 있다면 닫기
54+ if ( openedInfoWindow ) {
55+ openedInfoWindow . close ( ) ;
56+ }
57+
58+ // 현재 infowindow 열기
59+ infowindow . open ( map , marker ) ;
60+
61+ // 열려 있는 infowindow 업데이트
62+ openedInfoWindow = infowindow ;
63+ }
64+ } ) ;
4765 return marker ;
4866 } ) ;
4967 return markers ;
0 commit comments