-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: 지도 조회 시 핀 바운더리 경계면에 맞게 줌인 되지 않던 오류 수정 * design: 풀핀 여백이 보이는 오류 수정
- Loading branch information
1 parent
a8f64a4
commit da2c754
Showing
3 changed files
with
17 additions
and
25 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,31 @@ | ||
import { useEffect, useRef } from 'react'; | ||
import { useLocation, useParams } from 'react-router-dom'; | ||
import { useEffect, useRef, useState } from 'react'; | ||
|
||
const useFocusToMarker = (map: TMap | null, markers: Marker[]) => { | ||
const { Tmapv3 } = window; | ||
const bounds = useRef(new Tmapv3.LatLngBounds()); | ||
const params = useLocation(); | ||
const queryParams = new URLSearchParams(window.location.search); | ||
const pinDetail = queryParams.get('pinDetail'); | ||
const [markersLength, setMarkersLength] = useState<Number>(0); | ||
|
||
useEffect(() => { | ||
if (map && markers && markers.length === 1) { | ||
map.panTo(markers[0].getPosition()); | ||
} | ||
if (map && pinDetail) { | ||
const marker = markers.find((marker: Marker) => marker.id === pinDetail); | ||
if (marker) { | ||
map.setCenter(marker.getPosition()); | ||
map.setZoom(17); | ||
} | ||
} | ||
if ( | ||
map && | ||
markers && | ||
markers.length > 1 && | ||
params.pathname.includes('see-together') && | ||
!pinDetail | ||
) { | ||
if (map && markers && markers.length > 1) { | ||
bounds.current = new Tmapv3.LatLngBounds(); | ||
markers.forEach((marker: Marker) => { | ||
bounds.current.extend(marker.getPosition()); | ||
}); | ||
|
||
map.fitBounds(bounds.current); | ||
if (markersLength === 0) { | ||
setMarkersLength(markers.length); | ||
map.fitBounds(bounds.current); | ||
return; | ||
} | ||
|
||
if (markersLength !== markers.length) map.fitBounds(bounds.current); | ||
} | ||
return () => { | ||
setMarkersLength(0); | ||
}; | ||
}, [markers]); | ||
}; | ||
|
||
export default useFocusToMarker; |