Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ export const Location = ({ location }: Props) => {
<Column className={'gap-1.5'}>
<Text>위치</Text>
<Container className={'h-[150px] overflow-hidden rounded-xl'}>
<NaverMap ref={setMap} defaultCenter={setLocation}>
<NaverMap
defaultZoom={18}
minZoom={15}
ref={setMap}
defaultCenter={setLocation}
>
<Marker position={setLocation} icon={'logo'} />
</NaverMap>
</Container>
Expand Down
12 changes: 12 additions & 0 deletions apps/web/app/_store/prevMapCenter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { create } from 'zustand'
import { Coord } from '@/map/_utils/toLatLng'

type LastMapCenter = {
lastMapCenter: Coord | null
setLastMapCenter: (mapCenter: Coord) => void
}

export const useLastMapCenterStore = create<LastMapCenter>((set) => ({
lastMapCenter: null,
setLastMapCenter: (mapCenter: Coord) => set({ lastMapCenter: mapCenter }),
}))
15 changes: 14 additions & 1 deletion apps/web/app/map/MapComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Container, NaverMap } from 'react-naver-maps'

import { CAMPUS_LOCATION } from '@/_constants/campus'
import { useCampusStore } from '@/_store/campus'
import { useLastMapCenterStore } from '@/_store/prevMapCenter'
import { usePlaceQueries } from '@/_apis/queries/place'
import type { MapBounds } from '@/_apis/schemas/place'

Expand All @@ -27,9 +28,11 @@ const MapComponent = () => {
const [showUpdateButton, setShowUpdateButton] = useState(false)

const { campus } = useCampusStore()
const { lastMapCenter, setLastMapCenter } = useLastMapCenterStore()
const { userLocation } = useWatchLocation()
const { data = [] } = useQuery(usePlaceQueries.byMap(currentBounds))

const defaultCenter = toLatLng(lastMapCenter || CAMPUS_LOCATION[campus])
const previewPlace = previewPlaceId
? data.find((place) => place.placeId === previewPlaceId)!
: null
Expand Down Expand Up @@ -77,6 +80,14 @@ const MapComponent = () => {
}

useEffect(refreshMapBounds, [refreshMapBounds])
useEffect(() => {
return () => {
if (!map) return
const { x: longitude, y: latitude } = map.getCenter()

setLastMapCenter({ longitude, latitude })
}
}, [map, setLastMapCenter])

return (
<>
Expand All @@ -96,8 +107,10 @@ const MapComponent = () => {
onMouseUp={onCenterChanged}
>
<NaverMap
defaultZoom={15}
minZoom={12}
ref={setMap}
defaultCenter={toLatLng(CAMPUS_LOCATION[campus])}
defaultCenter={defaultCenter}
onZoomChanged={onCenterChanged}
>
{userLocation && <UserMarker position={userLocation} />}
Expand Down
2 changes: 1 addition & 1 deletion apps/web/app/map/_components/PreviewPlace/PreviewPlace.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const PreviewPlace = ({ place }: { place: PlaceByMap }) => {
{address}
</Text>
<Flex className='mt-1 gap-2'>
{photos.map((photo) => (
{photos.slice(0, 5).map((photo) => (
<Flex
key={photo.photoId || photo.displayOrder}
className={
Expand Down
7 changes: 6 additions & 1 deletion apps/web/app/places/[id]/_components/Location/Location.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ export const Location = ({ location }: { location: Coord }) => {
<Column className={'gap-1.5'}>
<SubTitle icon={'pin'} title={'위치'} />
<Container className={'h-[150px] overflow-hidden rounded-xl'}>
<NaverMap ref={setMap} defaultCenter={toLatLng(location)}>
<NaverMap
defaultZoom={18}
minZoom={15}
ref={setMap}
defaultCenter={toLatLng(location)}
>
<PlaceMarker position={location} icon={'logo'} />
</NaverMap>
</Container>
Expand Down