5
5
// Created by JIWOONG CHOI on 1/28/25.
6
6
//
7
7
8
- import UIKit
9
-
10
8
import EATSSUDesign
11
-
12
9
import NMapsMap
10
+ import UIKit
13
11
12
+ /// `MapViewController`는 네이버 지도를 표시하고, 마커를 추가하는 역할을 합니다.
14
13
final class MapViewController : BaseViewController , NMFMapViewTouchDelegate {
14
+ /// 네이버 지도 뷰
15
15
private var mapView : NMFMapView !
16
16
17
+ /// 숭실대학교 위치 (위도, 경도)
18
+ private let soongsilUniversityLocation = NMGLatLng ( lat: 37.496389 , lng: 126.957222 )
19
+
20
+ // MARK: - Life Cycle
21
+
17
22
override func viewDidLoad( ) {
18
23
super. viewDidLoad ( )
19
- setNavigationBar ( )
20
-
21
- mapView = NMFMapView ( frame : view . frame )
22
- view . addSubview ( mapView )
24
+ setupUI ( )
25
+ configureMapView ( )
26
+ addSoongsilMarker ( )
27
+ }
23
28
24
- // Sample marker at NAVER 1984 location
25
- let sampleMarker = ESMarker (
26
- position: NMGLatLng ( lat: 37.3595704 , lng: 127.105399 ) ,
27
- data: " Sample Data " ,
28
- leftText: " NAVER " ,
29
- rightText: " 1984 "
30
- )
31
- sampleMarker. marker. mapView = mapView
29
+ // MARK: - UI 설정
32
30
33
- mapView. touchDelegate = self
31
+ /// UI를 초기화하고 네비게이션 바를 설정합니다.
32
+ private func setupUI( ) {
33
+ setNavigationBar ( )
34
34
}
35
35
36
+ /// 네비게이션 바 스타일을 설정합니다.
36
37
private func setNavigationBar( ) {
37
38
navigationItem. title = ESTextLiteral . Map. mapNavTitle
38
39
navigationController? . isNavigationBarHidden = false
@@ -47,26 +48,81 @@ final class MapViewController: BaseViewController, NMFMapViewTouchDelegate {
47
48
navigationController? . navigationBar. standardAppearance = appearance
48
49
navigationController? . navigationBar. scrollEdgeAppearance = appearance
49
50
}
51
+
52
+ // MARK: - 지도 설정
53
+
54
+ /// 네이버 지도 뷰를 초기화하고 화면에 추가합니다.
55
+ private func configureMapView( ) {
56
+ mapView = NMFMapView ( frame: view. frame)
57
+ view. addSubview ( mapView)
58
+ mapView. touchDelegate = self
59
+
60
+ moveCamera ( to: soongsilUniversityLocation, zoomLevel: 16.0 )
61
+ }
62
+
63
+ /// 카메라를 특정 위치로 이동합니다.
64
+ /// - Parameters:
65
+ /// - location: 이동할 위치의 위도 및 경도 (`NMGLatLng`)
66
+ /// - zoomLevel: 줌 레벨 (`Double`)
67
+ private func moveCamera( to location: NMGLatLng , zoomLevel: Double ) {
68
+ let cameraUpdate = NMFCameraUpdate (
69
+ position: NMFCameraPosition ( location, zoom: zoomLevel)
70
+ )
71
+ mapView. moveCamera ( cameraUpdate)
72
+ }
73
+
74
+ // MARK: - 마커 설정
75
+
76
+ /// 숭실대학교 위치에 마커를 추가합니다.
77
+ private func addSoongsilMarker( ) {
78
+ let soongsilMarker = ESMarker (
79
+ position: soongsilUniversityLocation,
80
+ data: " Soongsil Univ " ,
81
+ leftText: " 숭실대학교 " ,
82
+ rightText: " Soongsil Univ "
83
+ )
84
+ soongsilMarker. marker. mapView = mapView
85
+ }
50
86
}
51
87
88
+ // MARK: - NMFMapViewTouchDelegate (지도 터치 이벤트)
89
+
52
90
extension MapViewController {
91
+ /// 사용자가 지도에서 단일 탭을 했을 때 호출됩니다.
92
+ /// - Parameters:
93
+ /// - latlng: 사용자가 탭한 위치 (`NMGLatLng`)
94
+ /// - point: 터치된 화면 좌표 (`CGPoint`)
53
95
func mapView( _: NMFMapView , didTapMap latlng: NMGLatLng , point _: CGPoint ) {
54
96
#if DEBUG
55
97
print ( " 탭: \( latlng. lat) , \( latlng. lng) " )
56
98
#endif
57
99
58
- let marker = ESMarker (
59
- position: NMGLatLng ( lat: latlng. lat, lng: latlng. lng) ,
60
- data: " Tapped Location " ,
61
- leftText: " Tapped Marker " ,
62
- rightText: " Here is the location "
63
- )
64
- marker. marker. mapView = mapView
100
+ addMarker ( at: latlng, title: " Tapped Location " , leftText: " Tapped Marker " , rightText: " Here is the location " )
65
101
}
66
102
103
+ /// 사용자가 지도에서 길게 눌렀을 때 호출됩니다.
104
+ /// - Parameters:
105
+ /// - latlng: 사용자가 길게 누른 위치 (`NMGLatLng`)
106
+ /// - point: 터치된 화면 좌표 (`CGPoint`)
67
107
func mapView( _: NMFMapView , didLongTapMap latlng: NMGLatLng , point _: CGPoint ) {
68
108
#if DEBUG
69
109
print ( " 롱 탭: \( latlng. lat) , \( latlng. lng) " )
70
110
#endif
71
111
}
112
+
113
+ /// 특정 위치에 마커를 추가합니다.
114
+ /// - Parameters:
115
+ /// - location: 마커를 추가할 위치 (`NMGLatLng`)
116
+ /// - title: 마커의 데이터 (`String`)
117
+ /// - leftText: 마커 왼쪽 텍스트 (`String`)
118
+ /// - rightText: 마커 오른쪽 텍스트 (`String`)
119
+ private func addMarker( at location: NMGLatLng , title: String , leftText: String , rightText: String ) {
120
+ let marker = ESMarker (
121
+ position: location,
122
+ data: title,
123
+ leftText: leftText,
124
+ rightText: rightText
125
+ )
126
+ marker. marker. mapView = mapView
127
+ }
72
128
}
0 commit comments