48 lines
1.3 KiB
Swift
48 lines
1.3 KiB
Swift
//
|
|
// 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?
|
|
|
|
// MARK: - Init
|
|
|
|
convenience init(report: EQNSegnalazione) {
|
|
let coordinate = CLLocationCoordinate2D(latitude: report.coordinate.coordinate.latitude, longitude: report.coordinate.coordinate.longitude)
|
|
let magnitude = report.magnitude
|
|
let title = EQNUtility.formattedTimeDifference(from: report.date)
|
|
|
|
self.init(title: title, coordinate: coordinate, magnitude: magnitude)
|
|
}
|
|
|
|
@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_green")
|
|
case 2: return UIImage(named: "star_yellow")
|
|
case 3: return UIImage(named: "star_red")
|
|
default: return nil
|
|
}
|
|
}
|
|
}
|