Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AUD-39] 인포창 바깥쪽 클릭 시 인포창 사라지는 기능 구현 #26

Merged
merged 5 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/features/map/marker/Marker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<div>
<MarkerImage className={S.marker} />
<p className={S.numberWrapper}>{number}</p>
<p className={S.numberWrapper}>{order}</p>
</div>
);
};
Expand Down
30 changes: 18 additions & 12 deletions src/utils/tmap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -159,7 +164,7 @@ export class TMapModule {
({ marker, lat, lng, ...rest }, index) => {
marker.setMap(null);
const updatedIconHTML = renderToString(
<Marker number={index + 1} />,
<Marker order={index + 1} />,
);
const updatedMarker = new Tmapv3.Marker({
position: new Tmapv3.LatLng(lat, lng),
Expand Down Expand Up @@ -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(
Expand All @@ -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);
Expand All @@ -329,7 +334,7 @@ export class TMapModule {
if (this.#markers.length >= this.#maxMarkerCount) return;

const iconHTML = renderToString(
<Marker number={this.#markers.length + 1} />,
<Marker order={this.#markers.length + 1} />,
);

this.createMarker({
Expand Down Expand Up @@ -361,7 +366,7 @@ export class TMapModule {

document
.querySelector('#infoWindow')
?.addEventListener('click', (e) => e.stopPropagation());
?.addEventListener('click', (event) => event.stopPropagation());

document
.querySelector('#pinButton')
Expand All @@ -370,6 +375,7 @@ export class TMapModule {

// 인포창 전체 삭제
removeInfoWindow() {
this.#infoWindows.forEach((infoWindow) => infoWindow.setMap(null));
this.#infoWindow.setMap(null);
this.#infoWindow = null;
}
}
Loading