// // EQNMapAnnotationUserReport.swift // Earthquake Network // // Created by Andrea Busi on 06/03/21. // Copyright © 2021 Earthquake Network. All rights reserved. // import Foundation import MapKit @objc class EQNMapAnnotationUserReport: NSObject, MKAnnotation { @objc var coordinate: CLLocationCoordinate2D @objc var title: String? @objc var image: UIImage? var report: EQNSegnalazione? // MARK: - Init convenience init(report: EQNSegnalazione) { let coordinate = CLLocationCoordinate2D(latitude: report.coordinate.coordinate.latitude, longitude: report.coordinate.coordinate.longitude) let magnitude = report.intensity.rawValue let title = EQNUtility.formattedTimeDifference(from: report.date) self.init(title: title, coordinate: coordinate, magnitude: magnitude) self.report = report } @objc init(title: String, coordinate: CLLocationCoordinate2D, magnitude: Int) { self.title = title self.image = Self.image(for: magnitude) self.coordinate = coordinate super.init() } // MARK: - Public private static func image(for magnitute: Int) -> UIImage? { switch magnitute { case 1: return UIImage(named: "star_report_green") case 2: return UIImage(named: "star_report_yellow") case 3: return UIImage(named: "star_report_red") default: return nil } } }