51 lines
1.5 KiB
Swift
51 lines
1.5 KiB
Swift
//
|
|
// EQNMapAnnotationPastquake.swift
|
|
// Earthquake Network
|
|
//
|
|
// Created by Andrea Busi on 10/03/21.
|
|
// Copyright © 2021 Earthquake Network. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
import MapKit
|
|
|
|
|
|
@objc
|
|
class EQNMapAnnotationPastquake: NSObject, MKAnnotation {
|
|
|
|
@objc var coordinate: CLLocationCoordinate2D
|
|
@objc var title: String?
|
|
@objc var image: UIImage?
|
|
|
|
var pastquake: EQNPastquakes?
|
|
|
|
// MARK: - Init
|
|
|
|
convenience init(pastquake: EQNPastquakes) {
|
|
let coordinate = CLLocationCoordinate2D(latitude: pastquake.coordinate.coordinate.latitude, longitude: pastquake.coordinate.coordinate.longitude)
|
|
let intentisy = pastquake.intensity
|
|
let title = EQNUtility.formattedTimeDifference(from: pastquake.date)
|
|
|
|
self.init(title: title, coordinate: coordinate, intensity: intentisy)
|
|
self.pastquake = pastquake
|
|
}
|
|
|
|
@objc init(title: String, coordinate: CLLocationCoordinate2D, intensity: Int) {
|
|
self.title = title
|
|
self.image = Self.image(for: intensity)
|
|
self.coordinate = coordinate
|
|
super.init()
|
|
}
|
|
|
|
// MARK: - Private
|
|
|
|
private static func image(for intensity: Int) -> UIImage? {
|
|
switch intensity {
|
|
case 0: return UIImage(named: "star_realtime_white")
|
|
case 1: return UIImage(named: "star_realtime_lightblue")
|
|
case 2: return UIImage(named: "star_realtime_blue")
|
|
default: return nil
|
|
}
|
|
}
|
|
}
|