-
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.
- Loading branch information
Showing
16 changed files
with
523 additions
and
3 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
34 changes: 34 additions & 0 deletions
34
src/app/(playground)/playground/map/_components/AddressSearchButton/index.tsx
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,34 @@ | ||
"use client"; | ||
|
||
import { useKakaoAddress } from "~/app/(playground)/playground/map/_components/KakaoAddressContext"; | ||
|
||
export default function AddressSearchButton() { | ||
const { setCoordinate } = useKakaoAddress(); | ||
|
||
const handleClickButton = () => { | ||
new window.daum.Postcode({ | ||
oncomplete: (addressData: any) => { | ||
const geocoder = new window.kakao.maps.services.Geocoder(); | ||
geocoder.addressSearch( | ||
addressData.address, | ||
(result: any, status: any) => { | ||
const currentPositions = new window.kakao.maps.LatLng( | ||
result[0].y, | ||
result[0].x, | ||
); | ||
setCoordinate(currentPositions.Ma, currentPositions.La); | ||
}, | ||
); | ||
}, | ||
}).open(); | ||
}; | ||
|
||
return ( | ||
<button | ||
onClick={handleClickButton} | ||
className={"bold rounded-xl border bg-blue-300 p-2 text-white"} | ||
> | ||
내 주소 찾기 | ||
</button> | ||
); | ||
} |
45 changes: 45 additions & 0 deletions
45
src/app/(playground)/playground/map/_components/KakaoAddressContext/index.tsx
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,45 @@ | ||
"use client"; | ||
|
||
import type { ReactNode } from "react"; | ||
import { createContext, useContext, useState } from "react"; | ||
|
||
export interface Coordinate { | ||
latitude: number; | ||
longitude: number; | ||
} | ||
|
||
interface KakaoAddressContextType { | ||
coordinate: Coordinate; | ||
setCoordinate: (latitude: number, longitude: number) => void; | ||
} | ||
|
||
const KakaoAddressContext = createContext<KakaoAddressContextType | undefined>( | ||
undefined, | ||
); | ||
|
||
export function KakaoAddressProvider({ children }: { children: ReactNode }) { | ||
const [coordinate, setCoordinateState] = useState<Coordinate>({ | ||
latitude: 37.566828, | ||
longitude: 126.9786567, | ||
}); | ||
|
||
const setCoordinate = (latitude: number, longitude: number) => { | ||
setCoordinateState({ latitude, longitude }); | ||
}; | ||
|
||
return ( | ||
<KakaoAddressContext.Provider value={{ coordinate, setCoordinate }}> | ||
{children} | ||
</KakaoAddressContext.Provider> | ||
); | ||
} | ||
|
||
export function useKakaoAddress() { | ||
const context = useContext(KakaoAddressContext); | ||
if (context === undefined) { | ||
throw new Error( | ||
"useKakaoAddress must be used within a KakaoAddressProvider", | ||
); | ||
} | ||
return context; | ||
} |
78 changes: 78 additions & 0 deletions
78
src/app/(playground)/playground/map/_components/KakaoMap/index.tsx
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,78 @@ | ||
"use client"; | ||
|
||
import { useEffect, useRef } from "react"; | ||
import { useKakaoAddress } from "~/app/(playground)/playground/map/_components/KakaoAddressContext"; | ||
|
||
interface KakaoMapProps { | ||
width: string; | ||
height: string; | ||
level?: number; | ||
addCenterPin?: boolean; | ||
latitude?: number; | ||
longitude?: number; | ||
} | ||
|
||
export default function KakaoMap({ | ||
width, | ||
height, | ||
level = 3, | ||
addCenterPin = false, | ||
latitude, | ||
longitude, | ||
}: KakaoMapProps) { | ||
const { coordinate } = useKakaoAddress(); | ||
const mapRef = useRef<HTMLDivElement | null>(null); | ||
const mapInstanceRef = useRef<any>(null); | ||
const markerRef = useRef<any>(null); | ||
|
||
useEffect(() => { | ||
if (!mapRef.current) return; | ||
|
||
const initializeMap = () => { | ||
const center = new window.kakao.maps.LatLng( | ||
latitude ?? coordinate.latitude, | ||
longitude ?? coordinate.longitude, | ||
); | ||
|
||
const mapInstance = new window.kakao.maps.Map( | ||
mapRef.current as HTMLElement, | ||
{ | ||
center, | ||
level, | ||
}, | ||
); | ||
|
||
mapInstanceRef.current = mapInstance; | ||
|
||
if (addCenterPin) { | ||
const marker = new window.kakao.maps.Marker({ position: center }); | ||
marker.setMap(mapInstance); | ||
markerRef.current = marker; | ||
} | ||
}; | ||
|
||
if (window.kakao && window.kakao.maps) { | ||
window.kakao.maps.load(initializeMap); | ||
} | ||
}, []); | ||
|
||
useEffect(() => { | ||
if (mapInstanceRef.current) { | ||
const newCenter = new window.kakao.maps.LatLng( | ||
latitude ?? coordinate.latitude, | ||
longitude ?? coordinate.longitude, | ||
); | ||
mapInstanceRef.current.setCenter(newCenter); | ||
|
||
if (addCenterPin && markerRef.current) { | ||
markerRef.current.setPosition(newCenter); | ||
} | ||
} | ||
}, [coordinate]); | ||
|
||
return ( | ||
<div style={{ width, height }}> | ||
<div ref={mapRef} style={{ width: "100%", height: "100%" }} /> | ||
</div> | ||
); | ||
} |
1 change: 1 addition & 0 deletions
1
src/app/(playground)/playground/map/_components/MapUtilsButton/UtilsContainer/index.tsx
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 @@ | ||
export default function UtilsContainer() {} |
Empty file.
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,24 @@ | ||
import Script from "next/script"; | ||
import { env } from "~/lib/env"; | ||
|
||
export default function KaKaoMapPageLayout({ | ||
children, | ||
}: { | ||
children: React.ReactNode; | ||
}) { | ||
return ( | ||
<> | ||
<Script | ||
strategy="beforeInteractive" | ||
type="text/javascript" | ||
src={`${env.DAUMCDN_POSTOCDE_URL}`} | ||
/> | ||
<Script | ||
strategy="beforeInteractive" | ||
type="text/javascript" | ||
src={`${env.KAKAO_MAP_BASE_URL}?appkey=${env.KAKAO_MAP_API_KEY}&libraries=services&autoload=false`} | ||
/> | ||
{children} | ||
</> | ||
); | ||
} |
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,37 @@ | ||
import { AMain } from "~/app/(playground)/playground/inner-tools"; | ||
import AddressSearchButton from "~/app/(playground)/playground/map/_components/AddressSearchButton"; | ||
import { KakaoAddressProvider } from "~/app/(playground)/playground/map/_components/KakaoAddressContext"; | ||
import KakaoMap from "~/app/(playground)/playground/map/_components/KakaoMap"; | ||
|
||
export default function KaKaoMapPage() { | ||
return ( | ||
<AMain> | ||
<div> | ||
<p>결과 페이지에서 보여줄 위도 경도 입력한 지도</p> | ||
<KakaoAddressProvider> | ||
<KakaoMap | ||
height={"400px"} | ||
width={"100%"} | ||
addCenterPin={true} | ||
latitude={37} | ||
longitude={126.87} | ||
/> | ||
</KakaoAddressProvider> | ||
</div> | ||
<div> | ||
<p>Provider Test 1</p> | ||
<KakaoAddressProvider> | ||
<KakaoMap height={"400px"} width={"100%"} addCenterPin={true} /> | ||
<AddressSearchButton /> | ||
</KakaoAddressProvider> | ||
</div> | ||
<div> | ||
<p>Provider Test 2</p> | ||
<KakaoAddressProvider> | ||
<KakaoMap height={"400px"} width={"100%"} addCenterPin={true} /> | ||
<AddressSearchButton /> | ||
</KakaoAddressProvider> | ||
</div> | ||
</AMain> | ||
); | ||
} |
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,3 +1,3 @@ | ||
export default function Home() { | ||
return <main className="">인비 🐝</main>; | ||
return <main className="">인비 🐝🐝</main>; | ||
} |
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 @@ | ||
ALTER TABLE "invitation_response" ALTER COLUMN "id" SET DATA TYPE text; |
Oops, something went wrong.