0

我刚刚开始使用最新发布的 iOS 版 Mapbox,并成功设置了带有注释的地图。注释需要基于 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]: Can't find sprite named”。这显然是由异步加载引起的问题(来源:https ://github.com/mapbox/mapbox-gl-native/issues/1877 ),但是,建议的解决方法是实现 imageForAnnotation 无论如何我都会这样做。

我在下面附上了 3 个切换地图类型的屏幕截图:

切换前

切换后

再次回来

如您所见,即使再次切换回原始地图,图像也不会重新出现。肯定会再次添加注释(下面插入到 imageForAnnotation po 的小节):

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

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

任何帮助深表感谢。

4

2 回答 2

0

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

这听起来不对。请开一张票,以便我们可以直接解决这个问题。

于 2015-09-02T00:14:11.047 回答
0

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

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

于 2015-09-03T09:41:28.700 回答