-
-
Save impul/70cfb707143f95c0080115d54682c6ee to your computer and use it in GitHub Desktop.
Refactor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// MARK: - IBActions | |
@IBAction func zoomInButtonTaped(_ sender: UIButton) { | |
Zoom.In.at(self.mapView) | |
} | |
@IBAction func zoomOutButtonTaped(_ sender: UIButton) { | |
Zoom.Out.at(self.mapView) | |
} | |
fileprivate enum Zoom: Double { | |
case In = 0.5 | |
case Out = 2 | |
func at(_ mapView:MKMapView) { | |
let span = mapView.region.span | |
let degrees = [span.longitudeDelta,span.longitudeDelta].map { $0 * rawValue } | |
let newSpan = MKCoordinateSpan(latitudeDelta: minDegree(degrees[0]), | |
longitudeDelta: minDegree(degrees[1])) | |
mapView.setRegion(MKCoordinateRegion(center: mapView.region.center, span: newSpan), animated: true) | |
} | |
//To drop hight values | |
fileprivate func minDegree(_ value:CLLocationDegrees ) -> CLLocationDegrees { | |
return min(value , Constants.Map.MaxSpan) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment