MapBox.layerForAnnotation未被调用.绘图形状



我正试图用给定的坐标为用户绘制一条从点a到点B的路径。

添加注释后不会调用LayerForAnnotation。我刚开始使用MapBox SDK,并不知道自己做错了什么。我在MapBox文档中查找有关添加形状的说明。我尝试更改为RMPointAnnotation,但没有成功,也不应该这样做:发布GitHub RMAnnotation。

我已经检查了是否有关于此委托的实现的任何信息,但在MapBox文档页面上没有找到很多信息。我从这里下载了说明注释的示例项目:Weekend Picks示例。

这是我正在使用的代码:

 - (void) makeRoutingAnnotations
{
    // Translate updated path with new coordinates.
    NSInteger numberOfSteps = _path.count;
    NSMutableArray *coordinates = [[NSMutableArray alloc] init];
    for (NSInteger index = 0; index < numberOfSteps; ++index) {
        CLLocation *location = [_path objectAtIndex:index];
        [coordinates addObject:location];
    }
    RMAnnotation *startAnnotation = [[RMAnnotation alloc] initWithMapView:mapView coordinate:((CLLocation *)[coordinates objectAtIndex:0]).coordinate andTitle:@"Start"];
    startAnnotation.userInfo = coordinates;
    [startAnnotation setBoundingBoxFromLocations:coordinates];
    [mapView addAnnotation:startAnnotation];
}
   - (RMMapLayer *)mapView:(RMMapView *)mView layerForAnnotation:(RMAnnotation *)annotation
{
    if (annotation.isUserLocationAnnotation)
        return nil;
    RMShape *shape = [[RMShape alloc] initWithView:mView];
    // set line color and width
    shape.lineColor = [UIColor colorWithRed:0.224 green:0.671 blue:0.780 alpha:1.000];
    shape.lineWidth = 8.0;
    for (CLLocation *location in (NSArray *)annotation.userInfo)
        [shape addLineToCoordinate:location.coordinate];
    return shape;
}

我会错过什么?我在layerForAnnotation方法上做了一个滴管,但它没有被调用。

我发现了没有正确实现RMMapViewDelegate的问题。由于它没有正确实现,所以没有调用它。

只需将其添加到头文件中并在代码中分配即可。

mapView.delegate = self;

最新更新