73 lines
2.1 KiB
Swift
73 lines
2.1 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: EQNBaseViewController, MKMapViewDelegate {
|
|
|
|
// MARK: - UI
|
|
|
|
@IBOutlet private weak var mapView: MKMapView!
|
|
|
|
// MARK: - State
|
|
|
|
var seismic: EQNSisma?
|
|
|
|
|
|
// MARK: - View Lifecycle
|
|
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
|
|
setupUI()
|
|
|
|
if let seismic = seismic {
|
|
addMarker(for: seismic)
|
|
}
|
|
}
|
|
|
|
// MARK: - Private
|
|
|
|
private func setupUI() {
|
|
let closeButton = UIBarButtonItem(barButtonSystemItem: .done, target: self, action: #selector(closeTapped(_:)))
|
|
navigationItem.rightBarButtonItem = closeButton
|
|
}
|
|
|
|
private func addMarker(for seismic: EQNSisma) {
|
|
let annotation = EQNMapAnnotationSeismic(title: seismic.place, location: seismic.coordinate.coordinate, intensita: seismic.magnitude.doubleValue)
|
|
mapView.addAnnotation(annotation)
|
|
|
|
let span = MKCoordinateSpan(latitudeDelta: 10.5, longitudeDelta: 10.5)
|
|
let region = MKCoordinateRegion(center: seismic.coordinate.coordinate, span: span)
|
|
mapView.setCenter(seismic.coordinate.coordinate, animated: false)
|
|
mapView.setRegion(region, animated: true)
|
|
}
|
|
|
|
// MARK: - Actions
|
|
|
|
@objc private func closeTapped(_ sender: Any) {
|
|
dismiss(animated: true)
|
|
}
|
|
|
|
// MARK: - MKMapViewDelegate
|
|
|
|
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
|
|
if let sismaAnnotation = annotation as? EQNMapAnnotationSeismic {
|
|
var annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: EQNMapAnnotationSeismicIdentifier)
|
|
if annotationView == nil {
|
|
annotationView = sismaAnnotation.annotationView()
|
|
} else {
|
|
annotationView?.annotation = sismaAnnotation
|
|
}
|
|
return annotationView
|
|
}
|
|
return nil
|
|
}
|
|
}
|