iOS MapKit - Detect when map is fully zoomed in?
因此,我正在使用集群库对注释进行分组,并且存在一个小错误,即当地图完全放大时,一些非常靠近的注释会显示为分组。作为一个框架,我不能做太多的事情它可以直接使用,但是如果地图被完全放大,则可以禁用所有分组。问题是我无法找到一种可靠的方法。
这是我的
1 2 3 4 5 6 7 | func mapView(mapView: MKMapView, regionDidChangeAnimated animated: Bool) { NSOperationQueue().addOperationWithBlock { let scale: Double = Double(self.map.bounds.size.width) / self.map.visibleMapRect.size.width let annotations = self.clusteringManager?.clusteredAnnotationsWithinMapRect(self.map.visibleMapRect, withZoomScale: scale) self.clusteringManager?.displayAnnotations(annotations, onMapView: self.map) } } |
我尝试检查
有什么建议吗?预先感谢。
您需要扩展您的MKMapView:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | class YourMapView : MKMapView { // function returns current zoom level of the map func getCurrentZoom() -> Double { var angleCamera = self.camera.heading if angleCamera > 270 { angleCamera = 360 - angleCamera } else if angleCamera > 90 { angleCamera = fabs(angleCamera - 180) } let angleRad = M_PI * angleCamera / 180 let width = Double(self.frame.size.width) let height = Double(self.frame.size.height) let offset : Double = 20 // offset of Windows (StatusBar) let spanStraight = width * self.region.span.longitudeDelta / (width * cos(angleRad) + (height - offset) * sin(angleRad)) return log2(360 * ((width / 256) / spanStraight)) + 1; } } |
现在您可以通过以下委托方法读出当前的"缩放级别":
1 | regionDidChangeAnimated |
和
1 | regionWillChangeAnimated |