Skip to content

Commit

Permalink
#5 design: 통계 모달 지도 마크업
Browse files Browse the repository at this point in the history
  • Loading branch information
qwerty00ui88 committed Feb 27, 2024
1 parent d9c453b commit ae6bc47
Show file tree
Hide file tree
Showing 4 changed files with 183 additions and 13 deletions.
20 changes: 12 additions & 8 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@
name="description"
content="Web site created using create-react-app"
/>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=IBM+Plex+Sans+KR:wght@100;200;300;400;500;600;700&family=Yesteryear&display=swap" rel="stylesheet">
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
href="https://fonts.googleapis.com/css2?family=IBM+Plex+Sans+KR:wght@100;200;300;400;500;600;700&family=Yesteryear&display=swap"
rel="stylesheet"
/>
<link rel="apple-touch-icon" href="public/logo192.png" />
<!--
manifest.json provides metadata used when your web app is installed on a
Expand All @@ -27,7 +30,11 @@
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
<script
type="text/javascript"
src="//dapi.kakao.com/v2/maps/sdk.js?appkey=afcf05444fa194bcf40218be92f62bcd"
></script>
<title>cut</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
Expand All @@ -41,8 +48,5 @@
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
--></body>
</html>


94 changes: 94 additions & 0 deletions src/components/Map.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import React, { useEffect } from 'react'
import styled from 'styled-components'
import sido from '../data/sido.json'

declare global {
interface Window {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
kakao: any
}
}

const MapWrapper = styled.div`
width: 100%;
height: 100%;
`

function Map({ mapPosition }: { mapPosition: number[] }) {
useEffect(() => {
const container = document.getElementById('map')
const options = {
center: new window.kakao.maps.LatLng(...mapPosition),
level: 12,
}

const map = new window.kakao.maps.Map(container, options) // 지도 생성

// const content =
// '<div class="overlaybox">' +
// ' <img src="https://image.tmdb.org/t/p/w200/7IiTTgloJzvGI1TAYymCfbfl3vT.jpg">' +
// ' </img>' +
// '</div>'

// const position = new window.kakao.maps.LatLng(...mapPosition) // 지도 초기 렌더링 위치

// const customOverlay = new window.kakao.maps.CustomOverlay({
// position,
// content,
// xAnchor: 0.3,
// yAnchor: 0.91,
// })

// customOverlay.setMap(map)

// sido.features.forEach((el) => {
// // 다각형을 구성하는 좌표 배열입니다. 이 좌표들을 이어서 다각형을 표시합니다
// el.geometry.coordinates.forEach((el2) => {
// const polygonPath = el2.map((el3) => {
// return new window.kakao.maps.LatLng(...el3)
// })
// // eslint-disable-next-line no-console
// console.log(polygonPath, el.properties.SIG_KOR_NM)

// // 지도에 표시할 다각형을 생성합니다
// const polygon = new window.kakao.maps.Polygon({
// path: polygonPath, // 그려질 다각형의 좌표 배열입니다
// strokeWeight: 3, // 선의 두께입니다
// strokeColor: '#ff0000', // 선의 색깔입니다
// strokeOpacity: 0.8, // 선의 불투명도 입니다 1에서 0 사이의 값이며 0에 가까울수록 투명합니다
// strokeStyle: 'longdash', // 선의 스타일입니다
// fillColor: '#A2FF99', // 채우기 색깔입니다
// fillOpacity: 0.7, // 채우기 불투명도 입니다
// })

// // 지도에 다각형을 표시합니다
// polygon.setMap(map)
// })
// })

const addPolygons = () => {
sido.features.forEach((el) => {
el.geometry.coordinates.forEach((el2) => {
const polygonPath = el2.map((el3) => {
return new window.kakao.maps.LatLng(el3[1], el3[0])
})
const polygon = new window.kakao.maps.Polygon({
path: polygonPath,
strokeWeight: 1.5,
strokeColor: 'red',
strokeOpacity: 0.8,
strokeStyle: 'longdash',
fillColor: '#00000080',
fillOpacity: 0.7,
})
polygon.setMap(map)
})
})
}

addPolygons()
}, [])

return <MapWrapper id="map" />
}
export default Map
58 changes: 58 additions & 0 deletions src/components/StatModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import React, { useState } from 'react'
import styled from 'styled-components'
import { ReactComponent as Good } from '../assets/good.svg'
import { ReactComponent as Bad } from '../assets/bad.svg'
import { ReactComponent as Favorite } from '../assets/favorite.svg'
import Map from './Map'
import { TrendingWrapper } from './Trending'

const StatModalWrapper = styled(TrendingWrapper)`
display: flex;
flex-direction: column;
position: fixed;
top: 50%;
right: 50%;
transform: translate(50%, -50%);
background-color: black;
width: 95vw;
height: 95vh;
padding: 2.4vw 3vw;
z-index: 3;
`

declare global {
interface Window {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
kakao: any
}
}

const MapSection = styled.div`
width: 100%;
flex: 1;
.overlaybox {
background-color: black;
}
`

function StatModal({ handleClose }: { handleClose: () => void }) {
const [mapPosition] = useState([37.5172, 127.0473])

return (
<StatModalWrapper>
<div>
<Good fill="#019e74" />
<Bad fill="rgb(229, 9, 20)" />
<Favorite fill="#FFD700" />
<button type="button" onClick={handleClose}>
X
</button>
</div>
<MapSection>
<Map mapPosition={mapPosition} />
</MapSection>
</StatModalWrapper>
)
}
export default StatModal
24 changes: 19 additions & 5 deletions src/pages/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import SearchBar from '../components/SearchBar'
import FloatingBar from '../components/FloatingBar'
import Trending from '../components/Trending'
import RecommendedVideo from '../components/RecommendedVideo'
import StatModal from '../components/StatModal'

const MainWrapper = styled.main``

Expand All @@ -29,6 +30,7 @@ function Main() {

const [isOpen, setIsOpen] = useState(false)
const [isScrolledDown, setIsScrollDown] = useState(false)
const [floatingBarOpen, setFloatingBarOpen] = useState(false)

const handleSetIsOpen = () => {
setIsOpen(!isOpen)
Expand All @@ -41,6 +43,10 @@ function Main() {
})
}

const handleSetFloatingBarOpen = () => {
setFloatingBarOpen(!floatingBarOpen)
}

window.addEventListener('scroll', () => {
const { scrollY } = window
setIsScrollDown(scrollY >= 12)
Expand All @@ -62,13 +68,21 @@ function Main() {
isOpen={isOpen}
handleSetIsOpen={handleSetIsOpen}
/>
<FloatingBar
isOpen={isOpen}
isScrolledDown={isScrolledDown}
/>
{floatingBarOpen ? (
<StatModal handleClose={handleSetFloatingBarOpen} />
) : (
<button
type="button"
onClick={handleSetFloatingBarOpen}
>
<FloatingBar
isOpen={isOpen}
isScrolledDown={isScrolledDown}
/>
</button>
)}
</UtilityBar>
</div>

<Trending />
<RecommendedVideo videoData={data.results} />
</MainWrapper>
Expand Down

0 comments on commit ae6bc47

Please sign in to comment.