3wi*_*wic 7 sorting objective-c ios mapbox
我目前正在寻找使用mapbox对所有注释进行排序.
我知道我应该使用以下过程:
//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];
Run Code Online (Sandbox Code Playgroud)
这里的问题是我迷失了我应该称之为这个过程的地方.
我实际上是mapView:layerForAnnotation:用来返回应该绘制的形状,但如果我没有错,那么它是一个回调,所以不是从代码中调用的.
谢谢你的帮助.
感谢jszumski,我想出了一个实现.对于那些在未来需要它的人来说,它是:
- (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;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
325 次 |
| 最近记录: |