Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Client] 찾아오는길 infoWindow 제작 #211

Merged
merged 33 commits into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
a43e0bb
Add svg
yebin0310 Aug 22, 2023
f601301
Update infoWindow
yebin0310 Aug 23, 2023
61b8e6a
Update style
yebin0310 Aug 25, 2023
a78b336
Update img, svg, overlay
yebin0310 Aug 26, 2023
06d5745
Update pr -> rem
yebin0310 Aug 26, 2023
a9bf66f
Delete useRef
yebin0310 Aug 26, 2023
54da7a9
Update useEffect -> Script
yebin0310 Aug 26, 2023
6ffd9bc
Delete useCallback, offset
yebin0310 Aug 26, 2023
c25bc1b
Add svg
yebin0310 Aug 27, 2023
e12b7c7
Update svg -> img
yebin0310 Aug 27, 2023
4947490
Add triangle
yebin0310 Aug 27, 2023
c1e6224
Update px -> rem
yebin0310 Aug 27, 2023
a4a7efc
Update isVisible
yebin0310 Aug 30, 2023
8feca89
Add react-kakao-maps-sdk
hyeongrok7874 Aug 30, 2023
bd318c7
Add react-kakao-maps-sdk
hyeongrok7874 Aug 30, 2023
e39e587
Merge branch 'feature/infoWindow' of https://github.com/themoment-tea…
yebin0310 Aug 30, 2023
6a3643f
Update marker
yebin0310 Aug 30, 2023
6b088ee
Update overlay close
yebin0310 Aug 30, 2023
3f0eb53
Update onClick -> onMouseOver
yebin0310 Aug 30, 2023
cbe20b2
Update map height
yebin0310 Aug 30, 2023
774277b
Update Script
yebin0310 Aug 31, 2023
f3da4d1
Update infowindow
yebin0310 Aug 31, 2023
ed181d3
Delete unusing svg
yebin0310 Sep 4, 2023
77dea4b
Update style
yebin0310 Sep 4, 2023
615a4b6
Update img -> Image
yebin0310 Sep 5, 2023
d884a36
Merge branch 'develop' of https://github.com/themoment-team/official-…
yebin0310 Sep 5, 2023
2a0ff2b
Add svg
yebin0310 Sep 5, 2023
3ea739f
Add kakao.maps.d.ts
hyeongrok7874 Sep 5, 2023
199ee2c
Update onclick -> a tag
yebin0310 Sep 5, 2023
efa5134
Update coords variable
yebin0310 Sep 5, 2023
677306e
Update markerCoords
yebin0310 Sep 5, 2023
0a632c7
Add width,height
yebin0310 Sep 5, 2023
d85b6e7
Update style, infowindow visible
yebin0310 Sep 5, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions apps/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@
"eslint": "8.40.0",
"eslint-config-next": "13.4.2",
"react-dom": "18.2.0",
"react-kakao-maps-sdk": "^1.1.12",
"types": "workspace:^",
"typescript": "5.0.4",
"ui": "workspace:^"
},
"devDependencies": {
"@storybook/react": "^7.0.6",
"eslint-config-custom": "workspace:^",
"kakao.maps.d.ts": "^0.1.38",
"tsconfig": "workspace:^"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions apps/client/public/images/about/Location/svg/ChevronIcon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions apps/client/public/images/about/Location/svg/CloseIcon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions apps/client/public/images/about/Location/svg/CopyLinkIcon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions apps/client/public/images/about/Location/svg/MarkerIcon.svg
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.
5 changes: 5 additions & 0 deletions apps/client/src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ export default function RootLayout({
`,
}}
/>
<Script
src={`//dapi.kakao.com/v2/maps/sdk.js?appkey=${process.env.NEXT_PUBLIC_KAKAOMAP_APPKEY}&autoload=false&libraries=services,clusterer`}
type='text/javascript'
strategy='beforeInteractive'
/>
</head>

<body>
Expand Down
81 changes: 81 additions & 0 deletions apps/client/src/components/About/Location/Map/InfoWindow.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import Image from 'next/image';

import * as S from './style';
interface InfoWindowProps {
latitude: number;
longitude: number;
onClose: () => void;
}

const InfoWindow: React.FC<InfoWindowProps> = ({
latitude,
longitude,
onClose,
}) => {
const CloseButtonClick = () => {
onClose();
};

const copyLinkButtonClick = () => {
const linkToCopy = 'http://kko.to/CtKpnV33Dj';
navigator.clipboard.writeText(linkToCopy).then(() => {
alert('링크가 복사되었습니다');
});
};

return (
<S.Next>
<S.Box>
<S.Close>
<Image
alt='closeIcon'
width={20}
height={20}
src='/images/about/location/svg/CloseIcon.svg'
onClick={CloseButtonClick}
/>
</S.Close>
<S.ContentBox>
<S.Title>광주소프트웨어마이스터고등학교</S.Title>
<S.Address>광주 광산구 상무대로 312 </S.Address>
<div> (우) 62423&nbsp;&nbsp;(지번) 송정동 710-3</div>
<S.Number>062-949-6800</S.Number>
</S.ContentBox>
<S.BottomBox>
<S.IconBox>
<a
href={`https://map.kakao.com/link/roadview/${latitude},${longitude}`}
target='_blank'
>
<S.Icon>
<Image
width={16}
height={16}
alt='smallMarker'
src='/images/about/location/svg/SmallMarkerIcon.svg'
/>
</S.Icon>
</a>
<S.Icon onClick={copyLinkButtonClick}>
<Image
width={16}
height={16}
alt='CopyLinkIcon'
src='/images/about/location/svg/CopyLinkIcon.svg'
/>
</S.Icon>
</S.IconBox>
<a
href={`https://map.kakao.com/link/to/광주소프트웨어마이스터고등학교,${latitude},${longitude}`}
target='_blank'
>
<S.LocationBtn>길찾기</S.LocationBtn>
</a>
</S.BottomBox>
</S.Box>
<S.Triangle2 />
</S.Next>
);
};

export default InfoWindow;
64 changes: 64 additions & 0 deletions apps/client/src/components/About/Location/Map/Overlay.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import React, { useState } from 'react';

import Image from 'next/image';

import InfoWindow from './InfoWindow';
import * as S from './style';

interface OverlayProps {
latitude: number;
longitude: number;
}

const Overlay: React.FC<OverlayProps> = ({ latitude, longitude }) => {
const [isInfoWindowVisible, setIsInfoWindowVisible] = useState(false);
const [isCustomOverlayVisible, setIsCustomOverlayVisible] = useState(true);

const isOverlay = () => {
setIsInfoWindowVisible(!isInfoWindowVisible);
setIsCustomOverlayVisible(!isCustomOverlayVisible);
};

const onCloseInfoWindow = () => {
setIsInfoWindowVisible(false);
setIsCustomOverlayVisible(true);
};

return (
<div>
{isCustomOverlayVisible && (
<S.CustomOverlay>
<S.Default onClick={isOverlay}>
<S.MarkerIcon>
<Image
width={20}
height={20}
alt='markerIcon'
src='/images/about/location/svg/MarkerIcon.svg'
/>
</S.MarkerIcon>
<S.Title>광주소프트웨어마이스터고등학교</S.Title>
<S.Chevron>
<Image
width={20}
height={20}
alt='chevronIcon'
src='/images/about/location/svg/ChevronIcon.svg'
/>
</S.Chevron>
</S.Default>
<S.Triangle />
</S.CustomOverlay>
)}
{isInfoWindowVisible && (
<InfoWindow
latitude={latitude}
longitude={longitude}
onClose={onCloseInfoWindow}
/>
)}
</div>
);
};

export default Overlay;
70 changes: 19 additions & 51 deletions apps/client/src/components/About/Location/Map/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { useRef } from 'react';
'use client';

import Script from 'next/script';
import { CustomOverlayMap, Map, MapMarker } from 'react-kakao-maps-sdk';

import styled from '@emotion/styled';
import Overlay from './Overlay';

interface MapProps {
latitude: number;
Expand All @@ -15,57 +15,25 @@ declare global {
}
}

function Map({ latitude, longitude }: MapProps) {
const containerRef = useRef<HTMLDivElement>(null);

const onLoadKakaoMap = () => {
window.kakao.maps.load(() => {
const options = {
center: new window.kakao.maps.LatLng(latitude, longitude),
};

const map = new window.kakao.maps.Map(containerRef.current, options);

const markerPosition = new window.kakao.maps.LatLng(latitude, longitude);

const marker = new window.kakao.maps.Marker({
position: markerPosition,
});

const infoWindow = new window.kakao.maps.InfoWindow({
content:
'<div style="width: 250px; padding: 10px;">광주소프트웨어마이스터고등학교</div>',
removable: true,
});

window.kakao.maps.event.addListener(marker, 'click', function () {
infoWindow.open(map, marker);
});

marker.setMap(map);
});
};

function SchoolMap({ latitude, longitude }: MapProps) {
const imageSrc = '/images/about/Location/Marker.png';
const markerCoords = { lat: latitude, lng: longitude };
return (
<>
<Script
src={`//dapi.kakao.com/v2/maps/sdk.js?appkey=${process.env.NEXT_PUBLIC_KAKAOMAP_APPKEY}&autoload=false`}
onLoad={onLoadKakaoMap}
/>
<MapContainer id='map' ref={containerRef} />
<Map center={markerCoords} style={{ width: '100%', height: '100%' }}>
<MapMarker
position={markerCoords}
image={{
src: imageSrc,
size: { width: 60, height: 60 },
}}
/>
<CustomOverlayMap position={markerCoords}>
<Overlay latitude={latitude} longitude={longitude} />
</CustomOverlayMap>
</Map>
</>
);
}

const MapContainer = styled.div`
width: 77.5rem;
height: 25rem;
@media ${({ theme }) => theme.breakPoint['1440']} {
width: calc(100vw - 12.5rem);
}
@media ${({ theme }) => theme.breakPoint['1024']} {
width: calc(100vw - 7.5rem);
}
`;

export default Map;
export default SchoolMap;
Loading