Skip to content

Commit

Permalink
🐛 여기서 다시 검색 시 이전 어노테이션이 삭제되도록 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
SwiftyJunnos committed Jan 10, 2024
1 parent 8f04848 commit b34a101
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public final class MapViewController: UIViewController {
mapView.userTrackingMode = .follow
mapView.showsCompass = false

mapView.register(CustomAnnotationView.self,
forAnnotationViewWithReuseIdentifier: CustomAnnotationView.identifier)
mapView.register(SpotAnnotationView.self,
forAnnotationViewWithReuseIdentifier: SpotAnnotationView.identifier)
mapView.register(ClusterAnnotationView.self,
forAnnotationViewWithReuseIdentifier: MKMapViewDefaultClusterAnnotationViewReuseIdentifier)

Expand Down Expand Up @@ -153,6 +153,7 @@ public final class MapViewController: UIViewController {
.receive(on: DispatchQueue.main)
.sink { [weak self] journeys in
self?.clearOverlays()
self?.clearAnnotations()
self?.addAnnotations(with: journeys)
self?.drawJourneyListPolylines(with: journeys)
}
Expand Down Expand Up @@ -180,9 +181,9 @@ public final class MapViewController: UIViewController {
// MARK: - Functions: Annotation

/// 식별자를 갖고 Annotation view 생성
func addAnnotationView(using annotation: CustomAnnotation,
func addAnnotationView(using annotation: SpotAnnotation,
on mapView: MKMapView) -> MKAnnotationView {
return mapView.dequeueReusableAnnotationView(withIdentifier: CustomAnnotationView.identifier,
return mapView.dequeueReusableAnnotationView(withIdentifier: SpotAnnotationView.identifier,
for: annotation)
}

Expand Down Expand Up @@ -216,7 +217,7 @@ public final class MapViewController: UIViewController {
private func addAnnotation(title: String,
coordinate: CLLocationCoordinate2D,
photoData: Data) {
let annotation = CustomAnnotation(title: title,
let annotation = SpotAnnotation(title: title,
coordinate: coordinate,
photoData: photoData)
self.mapView.addAnnotation(annotation)
Expand Down Expand Up @@ -385,7 +386,7 @@ extension MapViewController: MKMapViewDelegate {
reuseIdentifier: MKMapViewDefaultClusterAnnotationViewReuseIdentifier)
}

let annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: CustomAnnotationView.identifier,
let annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: SpotAnnotationView.identifier,
for: annotation)
return annotationView
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@

import MapKit

import MSDesignSystem

final class ClusterAnnotationView: MKAnnotationView {

// MARK: - Constants

private enum Metric {

static let markerWidth: CGFloat = 43.0
static let markerHeight: CGFloat = 53.0
static let markerWidth: CGFloat = 60.0
static let markerHeight: CGFloat = 60.0
static let inset: CGFloat = 4
static let thumbnailImageViewSize: CGFloat = Metric.markerWidth - Metric.inset * 2

Expand Down Expand Up @@ -62,7 +64,7 @@ final class ClusterAnnotationView: MKAnnotationView {

override func layoutSubviews() {
super.layoutSubviews()
bounds.size = self.markerImageView.bounds.size
self.bounds.size = self.markerImageView.bounds.size
}

// MARK: - UI Configuration
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// CustomAnnotation.swift
// SpotAnnotation.swift
// Home
//
// Created by 이창준 on 2023.12.06.
Expand All @@ -8,7 +8,7 @@
import Foundation
import MapKit

final class CustomAnnotation: NSObject, MKAnnotation {
final class SpotAnnotation: NSObject, MKAnnotation {

// MARK: - Properties

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// CustomAnnotationView.swift
// SpotAnnotationView.swift
// Home
//
// Created by 윤동주 on 11/23/23.
Expand All @@ -11,16 +11,16 @@ import UIKit

import MSDesignSystem

final class CustomAnnotationView: MKAnnotationView {
final class SpotAnnotationView: MKAnnotationView {

// MARK: - Constants

public static let identifier = "CustomAnnotationView"
public static let identifier = "SpotAnnotationView"

private enum Metric {

static let markerWidth: CGFloat = 43.0
static let markerHeight: CGFloat = 53.0
static let markerWidth: CGFloat = 60.0
static let markerHeight: CGFloat = 60.0
static let inset: CGFloat = 4.0
static let thumbnailImageViewSize: CGFloat = Metric.markerWidth - Metric.inset * 2

Expand All @@ -42,9 +42,7 @@ final class CustomAnnotationView: MKAnnotationView {
// MARK: - Properties

override var annotation: MKAnnotation? {
didSet {
self.clusteringIdentifier = "spotIdentifier"
}
didSet { self.clusteringIdentifier = "spotIdentifier" }
}

// MARK: - Initializer
Expand Down Expand Up @@ -103,7 +101,7 @@ final class CustomAnnotationView: MKAnnotationView {
// MARK: - Functions

func updateThumbnailImage() {
guard let annotation = self.annotation as? CustomAnnotation else { return }
guard let annotation = self.annotation as? SpotAnnotation else { return }
self.thumbnailImageView.image = UIImage(data: annotation.photoData)
}

Expand Down

0 comments on commit b34a101

Please sign in to comment.