-
Notifications
You must be signed in to change notification settings - Fork 3
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 #39 from youznn/main
feature(Fe) - connect rest api
- Loading branch information
Showing
27 changed files
with
1,814 additions
and
362 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,93 @@ | ||
"use client"; | ||
|
||
import { useRef } from "react"; | ||
import { | ||
Container as MapDiv, | ||
NaverMap, | ||
Marker, | ||
useNavermaps, | ||
} from "react-naver-maps"; | ||
|
||
function MyMap() { | ||
// instead of window.naver.maps | ||
type Category = "K_POP" | "DRAMA" | "MOVIE" | "NOVEL"; | ||
interface Location { | ||
id: number; | ||
title: string; | ||
latitude: number; | ||
longitude: number; | ||
} | ||
|
||
function MyMap({ | ||
locations, | ||
category, | ||
setCurrentLocationId, | ||
}: { | ||
locations: Location[]; | ||
category: Category; | ||
setCurrentLocationId: (id: number) => void; | ||
}) { | ||
const navermaps = useNavermaps(); | ||
|
||
const makerImage = { | ||
K_POP: "/icons/marker-1.png", | ||
DRAMA: "/icons/marker-3.png", | ||
MOVIE: "/icons/marker-4.png", | ||
NOVEL: "/icons/marker-2.png", | ||
}; | ||
|
||
const mapRef = useRef<InstanceType<typeof navermaps.Map> | null>(null); | ||
return ( | ||
<NaverMap | ||
defaultCenter={new navermaps.LatLng(37.3595704, 127.105399)} | ||
defaultZoom={15} | ||
> | ||
<Marker defaultPosition={new navermaps.LatLng(37.3595704, 127.105399)} /> | ||
</NaverMap> | ||
<MapDiv style={{ width: "100%", height: "350px" }}> | ||
<NaverMap | ||
defaultCenter={new navermaps.LatLng(36.4109466, 126.976882)} | ||
defaultZoom={5} | ||
ref={mapRef} | ||
> | ||
<> | ||
{locations.map((location) => ( | ||
<Marker | ||
key={location.id} | ||
position={ | ||
new navermaps.LatLng(location.latitude, location.longitude) | ||
} | ||
icon={{ | ||
url: makerImage[category], | ||
size: new navermaps.Size(25, 30), | ||
scaledSize: new navermaps.Size(25, 30), | ||
origin: new navermaps.Point(0, 0), | ||
anchor: new navermaps.Point(16, 16), | ||
}} | ||
// marker 클릭 시 해당 위치로 이동 | ||
onClick={() => { | ||
mapRef?.current?.setZoom(15); | ||
mapRef?.current?.panTo( | ||
new navermaps.LatLng(location.latitude, location.longitude), | ||
); | ||
setCurrentLocationId(location.id); | ||
}} | ||
/> | ||
))} | ||
</> | ||
</NaverMap> | ||
</MapDiv> | ||
); | ||
} | ||
|
||
export default function SimpleMap() { | ||
export default function MapWithMarker({ | ||
locations, | ||
category, | ||
setCurrentLocationId, | ||
}: { | ||
locations: Location[]; | ||
category: Category; | ||
setCurrentLocationId: (id: number) => void; | ||
}) { | ||
return ( | ||
<MapDiv style={{ width: "100%", height: "300px" }}> | ||
<MyMap /> | ||
<MapDiv style={{ width: "100%", height: "400px" }}> | ||
<MyMap | ||
locations={locations} | ||
category={category} | ||
setCurrentLocationId={setCurrentLocationId} | ||
/> | ||
</MapDiv> | ||
); | ||
} |
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
Oops, something went wrong.