0

我正在使用 Route-Me: Alpstein fork 来开发 iOS 应用程序。最初的 Route-Me/Mapbox 代码有一个自定义集群图标和集群计数的选项。我一直在寻找一种使用 Route-Me: Alpstein 前叉的方法。

与此类似的东西:

- (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 前叉获得相同的结果?任何帮助将不胜感激。

4

1 回答 1

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;
}

希望这对你有用!

于 2014-07-27T17:59:36.030 回答