-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #201 from Kernel360/feature-kakao-map-marker
페이지 기능: 지도 페이지 마커 추가
- Loading branch information
Showing
9 changed files
with
147 additions
and
6 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
1 change: 1 addition & 0 deletions
1
...red/map/CurrentLocationButton.module.scss → ...kao-map/CurrentLocationButton.module.scss
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
File renamed without changes.
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,67 @@ | ||
/* eslint-disable array-callback-return */ | ||
/* eslint-disable max-len */ | ||
/* eslint-disable @typescript-eslint/no-unsafe-assignment */ | ||
/* eslint-disable @typescript-eslint/no-unsafe-call */ | ||
/* eslint-disable @typescript-eslint/no-unsafe-member-access */ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
|
||
import { useCallback, useEffect } from 'react'; | ||
|
||
import { MarkersType } from '@remote/api/types/map'; | ||
|
||
interface MarkerProps { | ||
map: any | ||
carwashs: MarkersType | ||
} | ||
|
||
declare global { | ||
interface Window { | ||
kakao: any | ||
} | ||
} | ||
|
||
function Markers({ map, carwashs }: MarkerProps) { | ||
const loadKakoMarkers = useCallback(() => { | ||
if (map) { | ||
// 식당 데이터 마커 띄우기 | ||
carwashs?.value.map((carwash) => { | ||
const imageSrc = '/assets/marker.png'; | ||
const imageSize = new window.kakao.maps.Size(40, 40); // 마커이미지의 크기입니다 | ||
const imageOption = { offset: new window.kakao.maps.Point(27, 69) }; // 마커이미지의 옵션입니다. 마커의 좌표와 일치시킬 이미지 안에서의 좌표를 설정합니다. | ||
|
||
// 마커의 이미지정보를 가지고 있는 마커이미지를 생성합니다 | ||
const markerImage = new window.kakao.maps.MarkerImage( | ||
imageSrc, | ||
imageSize, | ||
imageOption, | ||
); | ||
|
||
// 마커가 표시될 위치입니다 | ||
const markerPosition = new window.kakao.maps.LatLng( | ||
carwash.latitude, | ||
carwash.longitude, | ||
); | ||
|
||
// 마커를 생성합니다 | ||
const marker = new window.kakao.maps.Marker({ | ||
position: markerPosition, | ||
image: markerImage, // 마커이미지 설정 | ||
}); | ||
|
||
// 마커가 지도 위에 표시되도록 설정합니다 | ||
marker.setMap(map); | ||
}); | ||
} | ||
}, [map, carwashs]); | ||
|
||
useEffect(() => { | ||
loadKakoMarkers(); | ||
}, [loadKakoMarkers, map]); | ||
|
||
return ( | ||
// eslint-disable-next-line react/jsx-no-useless-fragment | ||
<></> | ||
); | ||
} | ||
|
||
export default Markers; |
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,12 @@ | ||
import { IMarkersParameter, MarkersType } from '../../types/map'; | ||
import { getRequest } from '../requests.api'; | ||
|
||
// 세차장 위치 마커 | ||
|
||
export const getMarkers = async ({ | ||
minX, maxX, minY, maxY, level, | ||
}: IMarkersParameter) => { | ||
const response = await getRequest<MarkersType>(`/washzones?minX=${minX}&maxX=${maxX}&minY=${minY}&maxY=${maxY}&&level=${level}`); | ||
|
||
return response; | ||
}; |
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,20 @@ | ||
import { ICommon } from './common'; | ||
|
||
export interface IMarkersParameter { | ||
minX: number | ||
maxX: number | ||
minY: number | ||
maxY: number | ||
level: number | ||
} | ||
|
||
export interface IMarkers { | ||
name: string | ||
address: string | ||
latitude: number | ||
longitude: number | ||
type: '실내' | '개러지' | null | ||
remarks: null | ||
} | ||
|
||
export type MarkersType = ICommon<IMarkers[]>; |
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,19 @@ | ||
import { useQuery } from '@tanstack/react-query'; | ||
|
||
import { getMarkers } from '@/remote/api/requests/map/map.get.api'; | ||
import { IMarkersParameter, MarkersType } from '@/remote/api/types/map'; | ||
|
||
function useMarkers({ | ||
minX, maxX, minY, maxY, level, | ||
}: IMarkersParameter) { | ||
return useQuery<MarkersType>({ | ||
queryKey: ['MarkerType', minX, minY, maxX, maxY, level], | ||
queryFn: () => { | ||
return getMarkers({ | ||
minX, maxX, minY, maxY, level, | ||
}); | ||
}, | ||
}); | ||
} | ||
|
||
export default useMarkers; |