I'm currently looking for sorting all annotations using mapbox.
I know I should use the following process:
//implementing this method and do the sort here (NSComparator)annotationSortingComparatorForMapView:(RMMapView *)mapView // remove current annotation and use the sorted array to redraw them [mapView removeAnnotations:[mapView annotations]]; [mapView addAnnotations:annotationSorted];
The problem here is that I lost information about where I should name this process.
I use mapView:layerForAnnotation: to return shapes that should be drawn, but if I'm not mistaken, this is a callback that is not really called from the code.
Thank you for your help.
EDIT:
Thanks to jszumski, I understood the implementation. For those who need it in the future, this is:
- (NSComparator)annotationSortingComparatorForMapView:(RMMapView *)RmapView { NSComparator sort =^(RMAnnotation *annotation1, RMAnnotation *annotation2) { // Sort user location annotations above all. // if ( annotation1.isUserLocationAnnotation && ! annotation2.isUserLocationAnnotation) return NSOrderedDescending; if ( ! annotation1.isUserLocationAnnotation && annotation2.isUserLocationAnnotation) return NSOrderedAscending; // Amongst user location annotations, sort properly. // if (annotation1.isUserLocationAnnotation && annotation2.isUserLocationAnnotation) { // User dot on top. // if ([annotation1 isKindOfClass:[RMUserLocation class]]) return NSOrderedDescending; if ([annotation2 isKindOfClass:[RMUserLocation class]]) return NSOrderedAscending; // Halo above accuracy circle. // if ([annotation1.annotationType isEqualToString:kRMTrackingHaloAnnotationTypeName]) return NSOrderedDescending; if ([annotation2.annotationType isEqualToString:kRMTrackingHaloAnnotationTypeName]) return NSOrderedAscending; } return NSOrderedSame; }; return sort; }
sorting ios objective-c mapbox
3wic
source share