-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Polyline component and sample in README.md (#59)
* feat: polyline component and sample * feat: up version * update package.json * chore: coding convention 통일 --------- Co-authored-by: cloud <[email protected]> Co-authored-by: Seongcheol Jo <[email protected]> Co-authored-by: Seongcheol Jo <[email protected]>
- Loading branch information
1 parent
b2339e2
commit 035d3f7
Showing
4 changed files
with
112 additions
and
13 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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "@r2don/react-naver-map", | ||
"version": "0.0.18", | ||
"version": "0.0.19", | ||
"author": { | ||
"name": "r2don", | ||
"email": "[email protected]" | ||
|
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,53 @@ | ||
import React, { useRef } from "react"; | ||
import { useMapContext } from "../context"; | ||
import { useIsomorphicLayoutEffect } from "../hooks/useIsomorphicLayoutEffect"; | ||
|
||
interface PolylineProps { | ||
path: { latitude: number; longitude: number }[]; | ||
strokeColor?: string; | ||
strokeWeight?: number; | ||
strokeOpacity?: number; | ||
strokeStyle?: naver.maps.strokeStyleType; | ||
} | ||
|
||
/** | ||
* Set polyline into Map obejct without rendering anything in VirtualDOM | ||
* @returns <></> | ||
*/ | ||
const Polyline = ({ | ||
path, | ||
strokeColor = "#FF0000", | ||
strokeWeight = 4, | ||
strokeOpacity = 0.8, | ||
strokeStyle = "solid", | ||
}: PolylineProps) => { | ||
const map = useMapContext(); | ||
const polylineRef = useRef<naver.maps.Polyline | null>(null); | ||
|
||
useIsomorphicLayoutEffect(() => { | ||
if (!map) return; | ||
|
||
const polylinePath = path.map( | ||
(point) => new naver.maps.LatLng(point.latitude, point.longitude), | ||
); | ||
|
||
polylineRef.current = new naver.maps.Polyline({ | ||
map, | ||
path: polylinePath, | ||
strokeColor, | ||
strokeWeight, | ||
strokeOpacity, | ||
strokeStyle: strokeStyle as naver.maps.strokeStyleType, | ||
}); | ||
|
||
return () => { | ||
if (polylineRef.current) { | ||
polylineRef.current.setMap(null); | ||
} | ||
}; | ||
}, [map, path, strokeColor, strokeWeight, strokeOpacity, strokeStyle]); | ||
|
||
return <></>; | ||
}; | ||
|
||
export default Polyline; |
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