-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…-map-and-canvas [FE][Refactor] #224 : 지도 컴포넌트 리팩토링
- Loading branch information
Showing
5 changed files
with
107 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
export type IMapObject = naver.maps.Map; | ||
|
||
export type IMapLatLngBound = naver.maps.LatLngBounds; | ||
|
||
export interface IMapOptions { | ||
lat: number; | ||
lng: number; | ||
zoom?: number; | ||
} | ||
|
||
/** | ||
* Forward Ref 를 통해서, 부모에서 자식 컴포넌트의 Ref에 접근할 때 쓰이는 인터페이스. | ||
* 다음과 같은 목적으로 쓰인다. | ||
* 1. 지도 컨테이너 요소와, 지도 객체를 가져온다. | ||
* 2. 지도 객체의 이벤트 위임을 위해 자신을 컨트롤 할 수 있는 Handler를 부모에게 전달하는 역할을 한다. | ||
* 이렇게 전달받은 핸들러로 부모 컴포넌트에서 자식에 있는 지도 객체를 컨트롤 할 수 있다. | ||
* */ | ||
export interface IMapRefMethods { | ||
getMapObject: () => naver.maps.Map | null; | ||
getMapContainer: () => HTMLElement | null; | ||
onMouseClickHandler: (event?: React.MouseEvent) => void; | ||
} | ||
|
||
// lat: 위도(y), lng: 경도(x) INaverMapVertexPosition | ||
export interface IMapVertexCoordinate { | ||
ne: { | ||
lng: number; | ||
lat: number; | ||
}; | ||
nw: { | ||
lng: number; | ||
lat: number; | ||
}; | ||
se: { | ||
lng: number; | ||
lat: number; | ||
}; | ||
sw: { | ||
lng: number; | ||
lat: number; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { IMapVertexCoordinate, IMapObject, IMapLatLngBound } from '@/component/maps/Map.types.ts'; | ||
|
||
export const getMapVertexCoordinate = (map: IMapObject): IMapVertexCoordinate => { | ||
let bounds: IMapLatLngBound; | ||
|
||
if (map instanceof naver.maps.Map) { | ||
bounds = map.getBounds() as naver.maps.LatLngBounds; | ||
} else { | ||
throw new Error('🚀 꼭지점 좌표 가져오기 오류 : 지도 객체가 없습니다.'); | ||
} | ||
|
||
const sw = bounds.getSW(); | ||
const ne = bounds.getNE(); | ||
return { | ||
se: { | ||
lng: ne.lng(), | ||
lat: sw.lat(), | ||
}, | ||
sw: { | ||
lng: sw.lng(), | ||
lat: sw.lat(), | ||
}, | ||
ne: { | ||
lng: ne.lng(), | ||
lat: ne.lat(), | ||
}, | ||
nw: { | ||
lng: sw.lng(), | ||
lat: ne.lat(), | ||
}, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters