Skip to content

Commit d96e89f

Browse files
committed
feat: SKSY-73 모바일 유저는 마커를 클릭했을때 인포를 확인하고, 인포를 클릭하면 네이버 검색창으로 이동한다
1 parent 8e54108 commit d96e89f

File tree

3 files changed

+30
-9
lines changed

3 files changed

+30
-9
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
"jest": "^29.7.0",
5050
"jsdom": "^22.1.0",
5151
"lodash": "^4.17.21",
52-
"msw": "latest",
52+
"msw": "2.3.1",
5353
"prettier": "^2.7.1",
5454
"stylelint": "^13.8.0",
5555
"stylelint-config-prettier": "^8.0.2",

src/utils/handleMapMarkers.ts

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import { infoWindowGenerator, mapInfoWindowGenerator } from '@/utils/infoGenerat
22
import { MarkerType, PlaceType } from '@/pages/Home/types';
33
import { PositionType } from './hooks/useCurrentPosition';
44
import { OTHER_MARKER_IMAGE } from '@/utils/constant';
5+
import { detectDevice } from '@/utils/detectDevice';
6+
7+
const device = detectDevice();
58

69
export 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

1821
export 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;

src/utils/infoGenerator.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
import { detectDevice } from '@/utils/detectDevice';
12
import styles from './infoGenerator.module.scss';
23

34
export const infoWindowGenerator = (content: string) => {
45
return `<div class=${styles.info_window}>${content}</div>`;
56
};
67

8+
const device = detectDevice();
9+
710
export const mapInfoWindowGenerator = (title: string, img: string) => {
811
return `<div class=${styles.info_wrapper}>
912
<div class=${styles.info}>
@@ -12,10 +15,10 @@ export const mapInfoWindowGenerator = (title: string, img: string) => {
1215
1316
</div>
1417
<div class="body">
15-
<div class="img">
18+
<div class="img" onclick="window.open('https://search.naver.com/search.naver?where=nexearch&sm=top_hty&fbm=0&ie=utf8&query=${title}')">
1619
<img width='200' height='150' src=${img} alt=${title}>
1720
</div>
18-
<span>노란색 마커를 클릭하면 네이버 검색창으로 이동합니다.</span>
21+
<span>${`${device === 'PC' ? '노란색 마커를' : '사진을'} 클릭하면 네이버 검색창으로 이동합니다.`}</span>
1922
</div>
2023
</div>
2124
</div>`;

0 commit comments

Comments
 (0)