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)

#mkmapview #occlusion-culling #XCode #iOS #mkannotation






관련 질문

지도 보기에서 현재 위치 확대 (Zoom on Current Location in Map View)

Is there a way to restrict MKMapView Zoomlevel in iOS6 (Is there a way to restrict MKMapView Zoomlevel in iOS6)

MKMapView가 약 180도 스크롤되지 않습니다. (MKMapView does not scroll around 180 degrees)

mapView에서 길찾기 버튼을 만드는 방법은 무엇입니까? (How to create get direction button in mapView?)

MKMapview를 사용하는 동안 MB의 메모리 사용량이 발생하고 ARC를 사용하는 동안 View가 사라질 때 메모리가 해제되지 않습니다. (While using MKMapview causing MBs of memory usage and using ARC it not releasing memory when View Disappears)

UITextFieldShouldChange가 두 번 호출됨 (UITextFieldShouldChange being called twice)

Mapview Xcode에서 위치 업데이트 (Update Location in Mapview Xcode)

MKMapView 폐색이 주석을 제거합니까? (Does MKMapView occlusion cull it's annotations?)

값이 없는 경우 HTML5 로컬 저장소 개체는 무엇을 반환합니까? (What does the HTML5 Local Storage object return if there is no value?)

MKMapView에서 사용자 위치를 찾는 데 문제가 있음 (Problems Trying to Find User Location in MKMapView)

MKMapView에 주석을 추가할 때 백그라운드에서 앱 충돌 (Crashes app in background when adding annotation on MKMapView)

모든 프로젝트 Swift 5에서 1개의 MapView를 공유하는 방법 (How to Share 1 MapView in all Project Swift 5)







코멘트