-
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 #54 from CarrotAuction/feat/KAN-13/kakao-map-api
feat: 게시글 상세페이지 판매자와 구매자 카카오 map api를 활용해 길찾기 시각화
- Loading branch information
Showing
18 changed files
with
377 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
NEXT_PUBLIC_KAKAO_MAP_REST_API=179a8c907891026029fb59adbc860843 | ||
NEXT_PUBLIC_KAKAO_MAP_CLIENT=4948158107c883c7ba08e9ca9ea1fbb7 |
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 |
---|---|---|
|
@@ -27,6 +27,7 @@ yarn-error.log* | |
# local env files | ||
.env*.local | ||
|
||
.env | ||
# vercel | ||
.vercel | ||
|
||
|
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { atom } from 'recoil'; | ||
import { LocationType } from '../types/map'; | ||
|
||
const DEFAULT_LAT = '37.497625203'; | ||
const DEFAULT_LNG = '127.03088379'; | ||
const DEFAULT_ZOOM = 8; | ||
|
||
export const mapState = atom({ | ||
key: 'map', | ||
default: null, | ||
dangerouslyAllowMutability: true, | ||
}); | ||
|
||
export const locationState = atom<LocationType>({ | ||
key: 'location', | ||
default: { | ||
lat: DEFAULT_LAT, | ||
lng: DEFAULT_LNG, | ||
zoom: DEFAULT_ZOOM, | ||
}, | ||
}); | ||
|
||
export const currentLocationState = atom<LocationType>({ | ||
key: 'currentLocation', | ||
default: { | ||
lat: '', | ||
lng: '', | ||
zoom: DEFAULT_ZOOM, | ||
}, | ||
}); | ||
|
||
export const arriveLocationState = atom<LocationType>({ | ||
key: 'arriveLocation', | ||
default: { | ||
lat: '', | ||
lng: '', | ||
zoom: DEFAULT_ZOOM, | ||
}, | ||
}); |
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 react/jsx-no-useless-fragment */ | ||
import { mapState } from '@/src/atom'; | ||
import { useRecoilValue } from 'recoil'; | ||
import React, { useEffect } from 'react'; | ||
import { LocationType } from '@/src/types/map'; | ||
import arrive from '../../assets/auction/arrive.png'; | ||
|
||
const Makers = ({ | ||
location, | ||
info, | ||
title, | ||
}: { | ||
location: LocationType; | ||
info?: boolean; | ||
title?: string; | ||
}) => { | ||
const map = useRecoilValue(mapState); | ||
|
||
const loadKakaoMarker = () => { | ||
if (map) { | ||
const imageSrc = arrive.src; | ||
|
||
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( | ||
location.lat, | ||
location.lng, | ||
); | ||
|
||
const marker = new window.kakao.maps.Marker({ | ||
position: markerPosition, | ||
image: markerImage, | ||
}); | ||
marker.setMap(map); | ||
|
||
if (info) { | ||
const iwContent = `<div style="padding:5px;">${title}<br><a href="https://map.kakao.com/link/map/나의 위치,${location.lat},${location.lng}" style="color:blue" target="_blank">길찾기</a></div>`; | ||
|
||
const iwPosition = new window.kakao.maps.LatLng( | ||
location.lat, | ||
location.lng, | ||
); | ||
|
||
const infowindow = new window.kakao.maps.InfoWindow({ | ||
position: iwPosition, | ||
content: iwContent, | ||
}); | ||
|
||
infowindow.open(map, marker); | ||
} | ||
} | ||
}; | ||
useEffect(() => { | ||
loadKakaoMarker(); | ||
}, [map]); | ||
|
||
return <></>; | ||
}; | ||
|
||
export default Makers; |
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,6 @@ | ||
.map { | ||
width: 100%; | ||
height: 500px; | ||
z-index: 99; | ||
border: 1px solid black; | ||
} |
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,52 @@ | ||
'use client'; | ||
|
||
import Script from 'next/script'; | ||
import classNamees from 'classnames/bind'; | ||
import { useRecoilValue, useSetRecoilState } from 'recoil'; | ||
import { locationState, mapState } from '@/src/atom'; | ||
import styles from './index.module.scss'; | ||
|
||
declare global { | ||
interface Window { | ||
kakao: any; | ||
} | ||
} | ||
|
||
type MapProps = { | ||
lat?: string | null; | ||
lng?: string | null; | ||
zoom?: number; | ||
}; | ||
|
||
export default function Map({ lat, lng, zoom }: MapProps) { | ||
const cx = classNamees.bind(styles); | ||
|
||
const setMap = useSetRecoilState(mapState); | ||
const location = useRecoilValue(locationState); | ||
|
||
const loadKakaoMap = () => { | ||
window.kakao.maps.load(() => { | ||
const mapContainer = document.getElementById('map'); | ||
const mapOption = { | ||
center: new window.kakao.maps.LatLng(lat, lng), | ||
level: zoom ?? location.zoom, | ||
}; | ||
|
||
const map = new window.kakao.maps.Map(mapContainer, mapOption); | ||
|
||
setMap(map); | ||
}); | ||
}; | ||
|
||
return ( | ||
<> | ||
<div id="map" className={cx('map')} /> | ||
<Script | ||
strategy="afterInteractive" | ||
type="text/javascript" | ||
src={`//dapi.kakao.com/v2/maps/sdk.js?appkey=${process.env.NEXT_PUBLIC_KAKAO_MAP_CLIENT}&autoload=false`} | ||
onReady={loadKakaoMap} | ||
/> | ||
</> | ||
); | ||
} |
Empty file.
Oops, something went wrong.