From 14bf2f2008ca5db63be91a2f00dcb951cc1778d9 Mon Sep 17 00:00:00 2001 From: AnCha Date: Wed, 4 Dec 2024 15:05:28 +0900 Subject: [PATCH] =?UTF-8?q?feat=20#50=20-=20=EA=B1=B0=EC=A0=90=20=EB=A7=88?= =?UTF-8?q?=EC=BB=A4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../assets/images/foothold/locationMarker.svg | 5 + src/app/foothold/page.tsx | 7 +- src/components/map/KakoMap.tsx | 95 +++++++++++++++++-- 3 files changed, 93 insertions(+), 14 deletions(-) create mode 100644 public/assets/images/foothold/locationMarker.svg diff --git a/public/assets/images/foothold/locationMarker.svg b/public/assets/images/foothold/locationMarker.svg new file mode 100644 index 0000000..d190b44 --- /dev/null +++ b/public/assets/images/foothold/locationMarker.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/src/app/foothold/page.tsx b/src/app/foothold/page.tsx index 54dbd86..facd75e 100644 --- a/src/app/foothold/page.tsx +++ b/src/app/foothold/page.tsx @@ -12,11 +12,6 @@ export default function FootHoldPage() { const mapRef = useRef<{ handleLevel: (type: string) => void } | null>(null); const [selectedChips, setSelectedChips] = useState([]); - const onChipSelection = (chips: string[]) => { - setSelectedChips(chips); - console.log("chips:", selectedChips); - }; - return (
{/* 상단바 */} @@ -34,7 +29,7 @@ export default function FootHoldPage() {
- +
diff --git a/src/components/map/KakoMap.tsx b/src/components/map/KakoMap.tsx index 688b364..5d293df 100644 --- a/src/components/map/KakoMap.tsx +++ b/src/components/map/KakoMap.tsx @@ -4,13 +4,45 @@ import React, { useState, useEffect, } from "react"; -import { Map } from "react-kakao-maps-sdk"; +import { Map, MapMarker } from "react-kakao-maps-sdk"; +import { ChipHeart, ChipPlace, ChipBalloon, ChipCoffee, ChipFood } from "."; +import MapChip from "../buttons/MapChip"; -const KakaoMap = forwardRef(function KakaoMap( - { onChipSelection }: { onChipSelection: (chips: string[]) => void }, - ref -) { +interface Center { + lat: number; + lng: number; +} + +const KakaoMap = forwardRef(function KakaoMap(_, ref) { + const ChipList = [ + { + icon: ChipHeart, + type: "나의 찜", + }, + { + icon: ChipPlace, + type: "관광명소", + }, + { + icon: ChipBalloon, + type: "문화시설", + }, + { + icon: ChipCoffee, + type: "카페", + }, + { + icon: ChipFood, + type: "음식점", + }, + ]; + + const [center, setCenter] = useState
({ + lat: 37.764246, + lng: 128.90026, + }); const [mapInstance, setMapInstance] = useState(null); + const [selectedChips, setSelectedChips] = useState([]); // 확대/축소 메서드 const handleLevel = (type: string) => { @@ -31,14 +63,61 @@ const KakaoMap = forwardRef(function KakaoMap( handleLevel, })); + // 지도 중심 업데이트 + const handleDragEnd = () => { + if (!mapInstance) return; + + const newCenter = mapInstance.getCenter(); + setCenter({ + lat: newCenter.getLat(), + lng: newCenter.getLng(), + }); + }; + const toggleChip = (type: string): void => { + const newSelectedChips = selectedChips.includes(type) + ? selectedChips.filter((item) => item !== type) + : [...selectedChips, type]; + + setSelectedChips(newSelectedChips); + }; + return ( -
+
setMapInstance(map)} - center={{ lat: 37.764246, lng: 128.90026 }} + onDragEnd={handleDragEnd} + draggable={true} className="w-full h-full" - /> + > + + + {/* Chip 리스트 */} +
+ {ChipList.map((chip, index) => ( + toggleChip(chip.type)} + /> + ))} +
); });