feat: Add circles in map detail
This commit is contained in:
+44
-1
@@ -60,6 +60,8 @@ class SeismicNetworksMapDetailViewController: EQNBaseMapViewController {
|
||||
|
||||
private let seismic: EQNSisma
|
||||
private var allSeismics: [EQNSisma]
|
||||
/// Contains circles drawed on the map
|
||||
private var mapCircles = [MKCircle]()
|
||||
|
||||
// MARK: - Init
|
||||
|
||||
@@ -88,6 +90,15 @@ class SeismicNetworksMapDetailViewController: EQNBaseMapViewController {
|
||||
let annotations = allSeismics.map { EQNMapAnnotationSeismic(seismic: $0) }
|
||||
|
||||
updateMap(with: annotations)
|
||||
|
||||
// if the given seismic is still in the data source, show circles
|
||||
// otherwise just remove any other circles already on the map
|
||||
if allSeismics.contains(seismic) {
|
||||
addCircles(for: seismic.coordinate)
|
||||
} else {
|
||||
addCircles(for: nil)
|
||||
}
|
||||
|
||||
loadFiltersRecap()
|
||||
}
|
||||
|
||||
@@ -125,7 +136,28 @@ class SeismicNetworksMapDetailViewController: EQNBaseMapViewController {
|
||||
seismicsFilterLabel.text = recap
|
||||
}
|
||||
|
||||
|
||||
private func addCircles(for location: CLLocation?) {
|
||||
// remove any previous circles
|
||||
mapView.removeOverlays(mapCircles)
|
||||
mapCircles.removeAll()
|
||||
|
||||
// aggiungiamo 3 cerchi concentrici per il punto specificato (se disponibile)
|
||||
// li inseriamo a a 50, 100 e 200 km.
|
||||
guard let location = location else { return }
|
||||
|
||||
let circles = [
|
||||
MKCircle(center: location.coordinate, radius: 25_000),
|
||||
MKCircle(center: location.coordinate, radius: 100_000),
|
||||
MKCircle(center: location.coordinate, radius: 200_000)
|
||||
]
|
||||
|
||||
// !!note: is important to assign here the circles
|
||||
// otherwise `addOverlays` will not work
|
||||
mapCircles = circles
|
||||
|
||||
// creo nuovi cerchi
|
||||
mapView.addOverlays(circles)
|
||||
}
|
||||
|
||||
// MARK: - Actions
|
||||
|
||||
@@ -154,6 +186,17 @@ class SeismicNetworksMapDetailViewController: EQNBaseMapViewController {
|
||||
|
||||
return annotationView
|
||||
}
|
||||
|
||||
func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer {
|
||||
guard let circleOverlay = overlay as? MKCircle else {
|
||||
return MKOverlayRenderer(overlay: overlay)
|
||||
}
|
||||
|
||||
let circle = MKCircleRenderer(overlay: circleOverlay)
|
||||
circle.strokeColor = AppTheme.Colors.darkGray
|
||||
circle.lineWidth = 1.0
|
||||
return circle
|
||||
}
|
||||
}
|
||||
|
||||
extension SeismicNetworksMapDetailViewController: SeismicFiltersViewControllerDelegate {
|
||||
|
||||
@@ -115,5 +115,21 @@
|
||||
return self;
|
||||
}
|
||||
|
||||
#pragma mark - Equatable
|
||||
|
||||
- (BOOL)isEqual:(id)other
|
||||
{
|
||||
if ([other isKindOfClass:[EQNSisma class]]) {
|
||||
EQNSisma *otherSisma = (EQNSisma *)other;
|
||||
return [otherSisma.coordinate isEqual:self.coordinate] && otherSisma.intensity.doubleValue == self.intensity.doubleValue;
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (NSUInteger)hash
|
||||
{
|
||||
return [self.coordinate hash];
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user