@@ -71,8 +71,9 @@ class HomeViewController: UIViewController {
7171 animated: true
7272 )
7373 mapView. isRotateEnabled = false
74- mapView. register ( CustomAnnotationView . self, forAnnotationViewWithReuseIdentifier: CustomAnnotationView . identifier)
75- // mapView.register(CustomAnnotationView.self, forAnnotationViewWithReuseIdentifier: "ClusterView")
74+ // mapView.register(CustomAnnotationView.self, forAnnotationViewWithReuseIdentifier: CustomAnnotationView.identifier)
75+ mapView. register ( MKMarkerAnnotationView . self, forAnnotationViewWithReuseIdentifier: " annotation " )
76+ mapView. register ( CustomClusterAnnotationView . self, forAnnotationViewWithReuseIdentifier: CustomClusterAnnotationView . identifier)
7677
7778 loadAnnotations ( )
7879 }
@@ -146,32 +147,23 @@ extension HomeViewController: MKMapViewDelegate {
146147 }
147148
148149 private func createCustomAnnotationView( for annotation: CustomAnnotation , in mapView: MKMapView ) -> MKAnnotationView {
149- let identifier = CustomAnnotationView . identifier
150- var annotationView = mapView. dequeueReusableAnnotationView ( withIdentifier: identifier) as? CustomAnnotationView
151-
152- if annotationView == nil {
153- annotationView = CustomAnnotationView ( annotation: annotation, reuseIdentifier: identifier)
154- } else {
155- annotationView? . annotation = annotation
156- }
157- annotationView? . configure ( with: annotation)
158- return annotationView!
150+ let view = mapView. dequeueReusableAnnotationView ( withIdentifier: " annotation " , for: annotation) as! MKMarkerAnnotationView
151+ view. annotation = annotation
152+ view. clusteringIdentifier = " pinCluster " // 클러스터링 가능하게
153+
154+ return view
159155 }
160156
161157 private func createClusterView( for cluster: MKClusterAnnotation ) -> MKAnnotationView {
162- let identifier = " ClusterView "
163- var clusterView = mapView. dequeueReusableAnnotationView ( withIdentifier: identifier) as? MKMarkerAnnotationView
158+ let identifier = CustomClusterAnnotationView . identifier
159+ var clusterView = mapView. dequeueReusableAnnotationView ( withIdentifier: identifier) as? CustomClusterAnnotationView
164160
165161 if clusterView == nil {
166- clusterView = MKMarkerAnnotationView ( annotation: cluster, reuseIdentifier: identifier)
162+ clusterView = CustomClusterAnnotationView ( annotation: cluster, reuseIdentifier: identifier)
167163 } else {
168164 clusterView? . annotation = cluster
169165 }
170166
171- clusterView? . markerTintColor = . systemBlue
172- clusterView? . glyphText = " \( cluster. memberAnnotations. count) " // 클러스터 내 개수 표시
173- clusterView? . displayPriority = . defaultHigh // 클러스터를 우선적으로 표시
174-
175167 return clusterView!
176168 }
177169
@@ -183,6 +175,7 @@ extension HomeViewController: MKMapViewDelegate {
183175 func mapView( _ mapView: MKMapView , regionDidChangeAnimated animated: Bool ) {
184176 let visibleAnnotations = mapView. annotations ( in: mapView. visibleMapRect)
185177 let visibleMarkers = visibleAnnotations. compactMap { $0 as? CustomAnnotation }
178+ // let visibleClusters = visibleAnnotations.compactMap{ $0 as? MKClusterAnnotation } // 할필요없음
186179 // BottomSheet의 CollectionView 업데이트
187180 adapter? . data = visibleMarkers. map { $0. pinData }
188181 bottomSheet. collectionView. reloadData ( )
0 commit comments