更改地图样式时,MGLMapView隐藏/无法加载注释(Mapbox)

时间:2015-08-28 11:03:04

标签: ios xcode mapbox mapbox-gl

我刚刚开始使用最新发布的Mapbox for iOS版本,并已成功设置了带注释的地图。注释需要基于API传递的优先级值的自定义图像。为此,我使用imageForAnnotation如下:

- (MGLAnnotationImage *)mapView:(MGLMapView *)mapView imageForAnnotation:(id <MGLAnnotation>)annotation
{
    CustomAnnotation *custom = (CustomAnnotation *)annotation;

    NSString *name = nil;
    if (custom.priority == 1 || custom.priority == 2)
        name = @"dot_red";
    else if (custom.priority == 3)
        name = @"dot_orange";
    else if (custom.priority > 3)
        name = @"dot_yellow";
    else if (custom.priority == -11)
        name = @"dot_purple";

    MGLAnnotationImage *annotationImage = [mapView dequeueReusableAnnotationImageWithIdentifier:name];

    if ( ! annotationImage)
    {
        UIImage *annoImage = [UIImage imageNamed:name];
        annotationImage = [MGLAnnotationImage annotationImageWithImage:annoImage reuseIdentifier:name];
    }

    return annotationImage;
}

但是,当我更改地图样式时,所有注释都会消失,地图更改代码如下:

[_mapView setStyleURL:kMapSatelliteStyleURL];
            [button setTitle:@"Regular" forState:UIControlStateNormal];
            button.tag = 1;

现在当我在地图上平移时,我注意到调试窗口中出现以下内容'{Worker} [Sprite]:找不到名为'的精灵。这显然是由异步加载引起的问题(来源:https://github.com/mapbox/mapbox-gl-native/issues/1877),但是,建议的解决方法是实现我做的imageForAnnotation。

我附上了3张截图,切换了地图类型:

Before Toggle

After Toggle

Back Again

正如您所看到的,即使再次切换回原始地图,图像也不会重新出现。注释肯定会再次添加(在下面的imageForAnnotation po中打破的子部分):

po mapView.annotations
<__NSArrayI 0x7fc1b8dec650>(
<CustomAnnotation: 0x7fc1b8b4b450>,
<CustomAnnotation: 0x7fc1b3df6780>
)

有没有其他人遇到此问题并知道如何修复它?我想知道地图样式的更改是否重新排序地图图层,因此注释是在地图图块下方绘制的?

非常感谢任何帮助。

2 个答案:

答案 0 :(得分:0)

  

我想知道地图样式的更改是否重新排序地图图层,因此在地图图块下方绘制了注释?

这听起来不对。请open a ticket以便我们直接解决此问题。

答案 1 :(得分:0)

这是一个已知问题,这里有一张票:

https://github.com/mapbox/mapbox-gl-native/issues/1488