// // EQNMapAnnotationSeismic.swift // Earthquake Network // // Created by Andrea Busi on 07/03/21. // Copyright © 2021 Earthquake Network. All rights reserved. // import Foundation import MapKit class EQNMapAnnotationSeismic: NSObject, MKAnnotation { var coordinate: CLLocationCoordinate2D var title: String? var image: UIImage? let seismic: EQNSisma // MARK: - Init init(seismic: EQNSisma) { self.seismic = seismic self.coordinate = CLLocationCoordinate2D(latitude: seismic.coordinate.coordinate.latitude, longitude: seismic.coordinate.coordinate.longitude) self.image = Self.image(for: seismic) if let date = seismic.date { self.title = EQNUtility.formattedTimeDifference(from: date) } super.init() } // MARK: - Private private class func image(for seismic: EQNSisma) -> UIImage? { let magnitude = seismic.magnitude.doubleValue let color: String if magnitude < 2.0 { color = "white" } else if magnitude < 3.5 { color = "green" } else if magnitude < 4.5 { color = "yellow" } else if magnitude < 5.5 { color = "red" } else { color = "purple" } let icon: String switch seismic.provider.uppercased() { case "USGS": icon = "star" case "SGC": icon = "star3" case "CSN": icon = "star3f" case "SSN": icon = "star4" case "INPRES": icon = "star4r" case "FUNVISIS": icon = "star6" case "Ineter": icon = "triangle" case "RSN": icon = "triangle2" case "PHIVOLCS": icon = "triround_inner" case "IGEPN": icon = "triround" case "INGV": icon = "circle" case "EMSC": icon = "dyamond" case "IGP": icon = "dyamond_round" case "JMA": icon = "esa" case "GEONET": icon = "oct" case "CSI": icon = "penta" case "IGN": icon = "square" case "UASD", "BDTIM", "NCS": icon = "thick_star" case "RSPR": icon = "star6f" default: icon = "" } return UIImage(named: "\(icon)_\(color)") } }