-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FE][Refactor] QA : 마커에 따른 줌 공통 함수로 분리
- Loading branch information
1 parent
b42f644
commit 7e64d5f
Showing
2 changed files
with
47 additions
and
34 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { IPoint } from '@/types/channel.types'; | ||
|
||
const calculateZoomLevel = (latDiff: number, lngDiff: number) => { | ||
const maxDiff = Math.max(latDiff, lngDiff); | ||
if (maxDiff < 0.0005) return 19; | ||
if (maxDiff < 0.001) return 18; | ||
if (maxDiff < 0.004) return 17; | ||
if (maxDiff < 0.01) return 15; | ||
if (maxDiff < 0.03) return 14; | ||
if (maxDiff < 0.05) return 13; | ||
if (maxDiff < 0.1) return 12; | ||
if (maxDiff < 0.2) return 11; | ||
if (maxDiff < 0.5) return 10; | ||
if (maxDiff < 1) return 9; | ||
if (maxDiff < 2) return 8; | ||
if (maxDiff < 5) return 7; | ||
if (maxDiff < 10) return 6; | ||
return 5; | ||
}; | ||
|
||
export const zoomMapView = (map: any, markers: IPoint[]) => { | ||
if (markers.length === 0) return; | ||
|
||
const latitudes = markers.map(marker => marker.lat); | ||
const longitudes = markers.map(marker => marker.lng); | ||
|
||
const maxLat = Math.max(...latitudes); | ||
const minLat = Math.min(...latitudes); | ||
const maxLng = Math.max(...longitudes); | ||
const minLng = Math.min(...longitudes); | ||
|
||
const centerLat = (maxLat + minLat) / 2; | ||
const centerLng = (maxLng + minLng) / 2; | ||
|
||
const latDiff = maxLat - minLat; | ||
const lngDiff = maxLng - minLng; | ||
const zoomLevel = calculateZoomLevel(latDiff, lngDiff); | ||
|
||
// 지도 중심과 줌 레벨 설정 | ||
map?.setCenter(new window.naver.maps.LatLng(centerLat, centerLng)); | ||
map?.setZoom(zoomLevel); | ||
}; |