-
Notifications
You must be signed in to change notification settings - Fork 0
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 #176 from boostcampwm-2022/develop
v0.2
- Loading branch information
Showing
17 changed files
with
93 additions
and
23 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
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
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
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
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,59 @@ | ||
import { LatLng } from "#types/LatLng"; | ||
import { MapProps } from "#types/MapProps"; | ||
import { getBounds, getMiddlePoint } from "#utils/pathUtils"; | ||
import { useCallback, useEffect, useRef, useState } from "react"; | ||
|
||
const useCardMap = ({ runningPath }: Pick<MapProps, "runningPath">) => { | ||
const container = useRef<HTMLDivElement>(null); | ||
const map = useRef<kakao.maps.Map>(); | ||
const polyLineRef = useRef<kakao.maps.Polyline>(); | ||
const [path] = useState<kakao.maps.LatLng[]>([]); | ||
|
||
useEffect(() => { | ||
if (!container.current || !runningPath) return; | ||
const { lat, lng } = getMiddlePoint(runningPath); | ||
map.current = new kakao.maps.Map(container.current, { | ||
center: new kakao.maps.LatLng(lat, lng), | ||
}); | ||
|
||
polyLineRef.current = new kakao.maps.Polyline({ | ||
map: map.current, | ||
path, | ||
}); | ||
map.current.setZoomable(false); | ||
map.current.setDraggable(false); | ||
drawPath(runningPath); | ||
const pathBounds = getBounds(runningPath || []); | ||
const sw = new kakao.maps.LatLng(pathBounds.minLat, pathBounds.minLng); | ||
const ne = new kakao.maps.LatLng(pathBounds.maxLat, pathBounds.maxLng); | ||
const mapBounds = new kakao.maps.LatLngBounds(sw, ne); | ||
map.current.setBounds(mapBounds); | ||
}, [runningPath, map]); | ||
|
||
const getLaMaByLatLng = (point: LatLng): kakao.maps.LatLng => { | ||
return new kakao.maps.LatLng(point.lat, point.lng); | ||
}; | ||
|
||
const drawPath = useCallback( | ||
async (path: LatLng[] | undefined) => { | ||
if (!path) { | ||
return; | ||
} | ||
if (!polyLineRef.current) return; | ||
polyLineRef.current.setPath(path.map((point) => getLaMaByLatLng(point))); | ||
}, | ||
[polyLineRef], | ||
); | ||
|
||
return { | ||
map: map.current, | ||
path, | ||
renderMap: () => ( | ||
<div style={{ position: "relative" }}> | ||
<div ref={container} style={{ width: "100%", aspectRatio: `16 / 9` }} /> | ||
</div> | ||
), | ||
}; | ||
}; | ||
|
||
export default useCardMap; |
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
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
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
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