refactor: Move map center to superclass
This commit is contained in:
@@ -55,13 +55,10 @@ class PasquakesMapViewController: EQNBaseMapViewController {
|
||||
}
|
||||
}
|
||||
|
||||
override func centerMap() {
|
||||
override func elaborateMapCenter() {
|
||||
guard let centerLocation = centerLocation else { return }
|
||||
|
||||
let span = MKCoordinateSpan(latitudeDelta: 8, longitudeDelta: 8)
|
||||
let region = MKCoordinateRegion(center: centerLocation.coordinate, span: span)
|
||||
mapView.setCenter(centerLocation.coordinate, animated: false)
|
||||
mapView.setRegion(region, animated: true)
|
||||
setMapCenter(for: centerLocation)
|
||||
}
|
||||
|
||||
override func didTapAnnotation(_ annotation: MKAnnotation) {
|
||||
|
||||
@@ -51,7 +51,7 @@ class SegnalazioniMapViewController: EQNBaseMapViewController {
|
||||
updateMap(with: annotations)
|
||||
}
|
||||
|
||||
override func centerMap() {
|
||||
override func elaborateMapCenter() {
|
||||
var centerLocation: CLLocation?
|
||||
|
||||
// Se c'è un cluster distante dall'utente meno del raggio di notifica sulle segnalazioni,
|
||||
@@ -89,10 +89,7 @@ class SegnalazioniMapViewController: EQNBaseMapViewController {
|
||||
}
|
||||
|
||||
if let centerLocation = centerLocation {
|
||||
let span = MKCoordinateSpan(latitudeDelta: 8, longitudeDelta: 8)
|
||||
let region = MKCoordinateRegion(center: centerLocation.coordinate, span: span)
|
||||
mapView.setCenter(centerLocation.coordinate, animated: false)
|
||||
mapView.setRegion(region, animated: true)
|
||||
setMapCenter(for: centerLocation)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-5
@@ -42,12 +42,9 @@ class SeismicNetworksMapDetailViewController: EQNBaseMapViewController {
|
||||
updateMap(with: [annotation])
|
||||
}
|
||||
|
||||
override func centerMap() {
|
||||
// center map
|
||||
override func elaborateMapCenter() {
|
||||
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)
|
||||
setMapCenter(for: seismic.coordinate, span: span)
|
||||
}
|
||||
|
||||
// MARK: - Map
|
||||
|
||||
@@ -167,6 +167,10 @@ class EQNBaseMapViewController: EQNBaseViewController, MKMapViewDelegate {
|
||||
// nope, subclass will implement some logic
|
||||
}
|
||||
|
||||
func elaborateMapCenter() {
|
||||
// nope, subclass will center map with it's own logic
|
||||
}
|
||||
|
||||
/// Update the map with a set of annotations
|
||||
func updateMap(with annotations: [MKAnnotation]) {
|
||||
// remove previous annotations
|
||||
@@ -178,11 +182,14 @@ class EQNBaseMapViewController: EQNBaseViewController, MKMapViewDelegate {
|
||||
mapView.addAnnotations(mapAnnotations)
|
||||
mapView.showAnnotations(mapAnnotations, animated: true)
|
||||
|
||||
centerMap()
|
||||
elaborateMapCenter()
|
||||
}
|
||||
|
||||
func centerMap() {
|
||||
// nope, subclass will center map with it's own logic
|
||||
/// Changes the center coordinate of the map to a given location
|
||||
func setMapCenter(for location: CLLocation, span: MKCoordinateSpan = MKCoordinateSpan(latitudeDelta: 8, longitudeDelta: 8)) {
|
||||
let region = MKCoordinateRegion(center: location.coordinate, span: span)
|
||||
mapView.setCenter(location.coordinate, animated: false)
|
||||
mapView.setRegion(region, animated: true)
|
||||
}
|
||||
|
||||
func didTapAnnotation(_ annotation: MKAnnotation) {
|
||||
|
||||
Reference in New Issue
Block a user