2014-02-24 78 views
0

我正在使用Route-Me:Alpstein fork開發iOS應用程序。原始的Route-Me/Mapbox代碼可以選擇自定義羣集圖標以及羣集計數。我一直在尋找一種方法來處理Route-Me:Alpstein叉。Route-Me:Alpstein fork - 自定義羣集圖標和顯示羣集計數

事情與此類似:

- (RMMapLayer *)mapView:(RMMapView *)mapView layerForAnnotation:(RMAnnotation *)annotation 
{ 
    if (annotation.isUserLocationAnnotation) 
     return nil; 

    RMMapLayer *layer = nil; 

    if (annotation.isClusterAnnotation) 
    { 
     layer = [[RMMarker alloc] initWithUIImage:[UIImage imageNamed:@"circle.png"]]; 

     layer.opacity = 0.75; 

     layer.bounds = CGRectMake(0, 0, 75, 75); 

     [(RMMarker *)layer setTextForegroundColor:[UIColor whiteColor]]; 

     [(RMMarker *)layer changeLabelUsingText:[NSString stringWithFormat:@"%i", [annotation.clusteredAnnotations count]]]; 
    } 
    else 
    { 
     layer = [[RMMarker alloc] initWithMapboxMarkerImage]; 
    } 

    return layer; 
} 

我不能看到源代碼任意定義的 'isClusterAnnotation'。如何使用Route-Me:Alpstein分叉獲得相同的結果?任何幫助將不勝感激。

回答

0

在我的項目我用下面,地圖代表的mapView:layerForAnnotation:方法中:

if ([annotation.annotationType isEqualToString:@"RMClusterAnnotation"]) {   
    UIImage *clusterImage = [UIImage imageNamed:@"foo.png"]; 
    RMMarker *newMarker = [[RMMarker alloc] initWithUIImage:clusterImage]; 

    // this is how I managed to count the annotations inside a cluster 
    NSInteger annotationsInCluster = [((RMQuadTreeNode *)annotation.userInfo).annotations count]; 

    // you can add a label to the annotation with the number of clustered annotations 
    [newMarker changeLabelUsingText: [NSString stringWithFormat:@"%i", annotationsInCluster]];   
    return newMarker; 
} 

希望這對你的作品!