Skip to content

Instantly share code, notes, and snippets.

@impul
Last active July 27, 2017 06:07
Show Gist options
  • Save impul/70cfb707143f95c0080115d54682c6ee to your computer and use it in GitHub Desktop.
Save impul/70cfb707143f95c0080115d54682c6ee to your computer and use it in GitHub Desktop.
Refactor
// 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