我正在使用Route-Me:Alpstein fork开发iOS应用程序。原始的Route-Me / Mapbox代码可以选择自定义群集图标以及群集计数。我一直在寻找一种方法来使用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 fork获得相同的结果?任何帮助将不胜感激。
答案 0 :(得分: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;
}
希望这适合你!