MKMapView 遮擋是否剔除它的註釋? (Does MKMapView occlusion cull it's annotations?)


問題描述

MKMapView 遮擋是否剔除它的註釋? (Does MKMapView occlusion cull it's annotations?)

我正在嘗試在 MKMapView 上向用戶顯示數以千計的潛在圖釘(註釋)。有誰知道地圖是否使用遮擋剔除來僅渲染可見註釋?

這適用於使用 xCode 6.4 的 iOS 7+


參考解法

方法 1:

When talking about managing large number of annotations, we should differentiate between "annotations" and "annotation views". When you add many annotations to a map view, the collection of those light‑weight MKAnnotation objects remain in the annotations array. But the map view offers a mechanism to mitigate the memory issues that can arise from a large number of associated "annotation views".

When you add thousands of annotations to a map view, the only annotation views that are instantiated are those that are visible (and those that near the visible portion of the map. If you properly use dequeueReusableAnnotationViewWithIdentifier in viewForAnnotation, as you scroll and annotations views fall out of view, when it needs new annotation views, it will recycle those that have scrolled out of view:

func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) ‑> MKAnnotationView? {
    var annotationView = mapView.dequeueReusableAnnotationViewWithIdentifier(annotationIdentifier)
    if annotationView == nil {
        annotationView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: annotationIdentifier)
    } else {
        annotationView?.annotation = annotation
    }
    return annotationView
}

Thus, this keeps the number of annotation views to some manageable number, not necessarily instantiating new annotation views until they're absolutely needed (i.e. there don't happen to be any old annotation views that have scrolled out of view, available for reuse).

If, however, the user zooms out on the map so there are an unmanageable number of annotation views visible simultaneously, you have to manage this situation yourself. Back in WWDC 2011, there was a video Visualizing Information Geographically with MapKit that demonstrates interesting model when dealing with tons of annotations. Specifically, they deal with the problem that you zoom out and there are so many annotation views that they start overlapping and become too numerous. This video demonstrates an approach in which you aggregate annotation views together as you scroll out (if necessary). The implementation is fairly rudimentary, but it illustrates the concept.

(by RagingDevRob)

參考文件

  1. Does MKMapView occlusion cull it's annotations? (CC BY‑SA 2.5/3.0/4.0)

#png #printing #svg #Windows






相關問題

Iphone app PNG 序列動畫 - 如何在不崩潰的情況下以最佳方式使用 OPENgle (Iphone app PNG sequence animation - How to use OPENgle optimally without crashing)

相當於PNG的視頻? (Video equivalent of PNG?)

是否有將大型 PDF 圖像存儲為文件(BMP/PNG/等)的工具或技巧? (Is there a tool or trick to store a large PDF image as a file (BMP/PNG/etc)?)

Apakah libpng memungkinkan untuk membaca tidak seluruh gambar ke memori? (Does libpng allow to read not the whole image to the memory)

如何對png文件進行去隔行掃描? (How to de-interlace png files?)

javascript PNG操作 (javascript PNG manipulation)

渲染的 PNG 的 AJAX 加載不起作用 (AJAX load of a rendered PNG not working)

性能緩慢的 WPF 動畫。使用形狀比使用 .png 更好? (Slow performance WPF animations. Better to use shapes than .png?)

Xcode 4 歸檔導致管理器緩慢/無響應,並且 pngcrush 進程佔用 100% cpu (Xcode 4 archive results in slow/unresponsive Organizer & pngcrush process takes up 100% cpu)

如果我有一個包含大量圖像的 iPad 應用程序,那麼 PNG 仍然是最佳選擇嗎? (If I have an iPad app with lots of images, is PNG still the best option?)

MKMapView 遮擋是否剔除它的註釋? (Does MKMapView occlusion cull it's annotations?)

如何在 PHP 中為透明的 PNG 文件著色? (How can I tint transparent PNG files in PHP?)







留言討論