diff --git a/src/features/map/marker/Marker.tsx b/src/features/map/marker/Marker.tsx index 3e90f094..e5d9500b 100644 --- a/src/features/map/marker/Marker.tsx +++ b/src/features/map/marker/Marker.tsx @@ -3,14 +3,14 @@ import MarkerImage from '@/assets/icons/marker.svg?react'; import * as S from './Marker.css'; interface PropsType { - number: number; + order: number; } -const Marker = ({ number }: PropsType) => { +const Marker = ({ order }: PropsType) => { return (
-

{number}

+

{order}

); }; diff --git a/src/utils/tmap.tsx b/src/utils/tmap.tsx index c2d98f07..a6b51ad8 100644 --- a/src/utils/tmap.tsx +++ b/src/utils/tmap.tsx @@ -27,12 +27,12 @@ export class TMapModule { #markers: MarkersType[] = []; #polylines: (typeof Tmapv3.Polyline)[] = []; - #isPathVisible: boolean = true; + #isPathVisible = true; - #infoWindows: (typeof window.Tmapv3.InfoWindow)[] = []; + #infoWindow: typeof window.Tmapv3.InfoWindow = null; - #zoomInLevel: number = 17; // TODO: 임시 - #maxMarkerCount: number = 15; + #zoomInLevel = 17; // TODO: 임시 + #maxMarkerCount = 15; constructor({ mapId = 'tmap', @@ -61,8 +61,13 @@ export class TMapModule { zoom, }); - const handleMapClick = async (e: typeof Tmapv3.maps.MouseEvent) => { - const { _lat: lat, _lng: lng } = e._data.lngLat; + const handleMapClick = async (event: typeof Tmapv3.maps.MouseEvent) => { + if (this.#infoWindow) { + this.removeInfoWindow(); + return; + } + + const { _lat: lat, _lng: lng } = event._data.lngLat; const { fullAddress } = await TmapRepository.getAddressFromLatLng({ lat, lng, @@ -159,7 +164,7 @@ export class TMapModule { ({ marker, lat, lng, ...rest }, index) => { marker.setMap(null); const updatedIconHTML = renderToString( - , + , ); const updatedMarker = new Tmapv3.Marker({ position: new Tmapv3.LatLng(lat, lng), @@ -303,7 +308,7 @@ export class TMapModule { address: string; isPinned: boolean; }) { - this.removeInfoWindow(); + if (this.#infoWindow) this.removeInfoWindow(); const infoWindowLatLng = new Tmapv3.LatLng(lat, lng); const content = renderToString( @@ -320,7 +325,7 @@ export class TMapModule { }); infoWindow.setMap(this.#mapInstance); - this.#infoWindows.push(infoWindow); + this.#infoWindow = infoWindow; this.#mapInstance.setCenter(infoWindowLatLng); this.#mapInstance.setZoom(this.#zoomInLevel); @@ -329,7 +334,7 @@ export class TMapModule { if (this.#markers.length >= this.#maxMarkerCount) return; const iconHTML = renderToString( - , + , ); this.createMarker({ @@ -361,7 +366,7 @@ export class TMapModule { document .querySelector('#infoWindow') - ?.addEventListener('click', (e) => e.stopPropagation()); + ?.addEventListener('click', (event) => event.stopPropagation()); document .querySelector('#pinButton') @@ -370,6 +375,7 @@ export class TMapModule { // 인포창 전체 삭제 removeInfoWindow() { - this.#infoWindows.forEach((infoWindow) => infoWindow.setMap(null)); + this.#infoWindow.setMap(null); + this.#infoWindow = null; } }