Files
eqn.ios/Sources/Earthquake Network/Models/Map annotation/EQNMapAnnotationSeismic.swift
T

49 lines
1.1 KiB
Swift

//
// 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
private let magnitute: Double
private let date: Date?
// MARK: - Init
init(seismic: EQNSisma) {
self.coordinate = CLLocationCoordinate2D(latitude: seismic.coordinate.coordinate.latitude, longitude: seismic.coordinate.coordinate.longitude)
self.magnitute = seismic.magnitude.doubleValue
self.date = seismic.date
super.init()
}
// MARK: - Public
var image: UIImage? {
if magnitute > 4.0 {
return UIImage(named: "dyamond_red")
} else if magnitute < 3.0 {
return UIImage(named: "dyamond_green")
} else {
return UIImage(named: "dyamond_yellow")
}
}
var title: String? {
if let date = date {
return EQNUtility.formattedTimeDifference(from: date)
}
return ""
}
}