91 lines
2.8 KiB
Swift
91 lines
2.8 KiB
Swift
//
|
|
// SeismicNetworksMapDetailViewController.swift
|
|
// Earthquake Network
|
|
//
|
|
// Created by Andrea Busi on 21/02/21.
|
|
// Copyright © 2021 Earthquake Network. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
import MapKit
|
|
|
|
|
|
class SeismicNetworksMapDetailViewController: EQNBaseMapViewController {
|
|
|
|
// MARK: - State
|
|
|
|
override var availableFilters: [EQNFiltroMappa] {
|
|
// filters are not available for this map
|
|
[]
|
|
}
|
|
|
|
// MARK: - Internal
|
|
|
|
private let seismic: EQNSisma
|
|
private let allSeismics: [EQNSisma]
|
|
|
|
// MARK: - Init
|
|
|
|
init(seismic: EQNSisma, allSeismics: [EQNSisma]) {
|
|
self.seismic = seismic
|
|
self.allSeismics = allSeismics
|
|
super.init()
|
|
}
|
|
|
|
required init?(coder: NSCoder) {
|
|
fatalError("init(coder:) has not been implemented")
|
|
}
|
|
|
|
// MARK: - Public
|
|
|
|
override func registerMapAnnotationViews() {
|
|
mapView.register(EQNCustomAnnotationView.self, forAnnotationViewWithReuseIdentifier: EQNCustomAnnotationView.DoubleLineIdentifier)
|
|
}
|
|
|
|
override func loadDataSource() {
|
|
let annotations = allSeismics.map { EQNMapAnnotationSeismic(seismic: $0) }
|
|
|
|
updateMap(with: annotations)
|
|
}
|
|
|
|
override func elaborateMapCenter() {
|
|
setMapCenter(for: seismic.coordinate)
|
|
}
|
|
|
|
override func didTapAnnotation(_ annotation: MKAnnotation) {
|
|
guard let annotation = annotation as? EQNMapAnnotationSeismic else { return }
|
|
|
|
let viewModel = SeismicNetworkViewModel(seismic: annotation.seismic)
|
|
|
|
let title = "\(viewModel.magnitude) - \(viewModel.place) - \(viewModel.network)"
|
|
let message = ""
|
|
+ "📏 \(viewModel.depth)"
|
|
+ "\n⏱ \(viewModel.time)"
|
|
+ "\n📐 \(viewModel.distance)"
|
|
+ "\n🌍 \(viewModel.coordinate)"
|
|
+ "\n👨👩👦 \(viewModel.population)"
|
|
|
|
let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
|
|
alert.addAction(UIAlertAction(title: NSLocalizedString("official_close", comment: ""), style: .cancel))
|
|
present(alert, animated: true)
|
|
}
|
|
|
|
// MARK: - Map
|
|
|
|
override func setupAnnotationView(for annotation: MKAnnotation, on mapView: MKMapView) -> MKAnnotationView? {
|
|
guard let annotation = annotation as? EQNMapAnnotationSeismic else {
|
|
return nil
|
|
}
|
|
|
|
let viewModel = SeismicNetworkViewModel(seismic: annotation.seismic)
|
|
|
|
let annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: EQNCustomAnnotationView.DoubleLineIdentifier, for: annotation) as! EQNCustomAnnotationView
|
|
|
|
annotationView.image = annotation.image
|
|
annotationView.title = annotation.title
|
|
annotationView.subtitle = viewModel.magnitude
|
|
|
|
return annotationView
|
|
}
|
|
}
|