Reputation: 1237
I have just started using the latest released version of Mapbox for iOS, and have setup a map with annotations successfully. The annotations needed custom images based upon a priority value passed by the API. To do this I am using imageForAnnotation as follows:
- (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;
}
However, when I change the map style all of the annotations disappear, the map change code is below:
[_mapView setStyleURL:kMapSatelliteStyleURL];
[button setTitle:@"Regular" forState:UIControlStateNormal];
button.tag = 1;
Now when I pan around the map, I notice that the following pops up in the debug window '{Worker}[Sprite]: Can't find sprite named'. This is apparently an issue caused by the asynchronous loading (Source: https://github.com/mapbox/mapbox-gl-native/issues/1877), however, the suggested workaround is to implement imageForAnnotation which I do anyway.
I have attached 3 screenshots below of me toggling the map type:
As you can see, even when toggling back to the original map again the images never re-appear. The annotations are definitely being added again (subsection of the broken in to imageForAnnotation po below):
po mapView.annotations
<__NSArrayI 0x7fc1b8dec650>(
<CustomAnnotation: 0x7fc1b8b4b450>,
<CustomAnnotation: 0x7fc1b3df6780>
)
Has anyone else come across this issue and know how to fix it? I am wondering whether the changing of map style re-orders the map layers, therefore annotations are drawn below the map tiles?
Any help is much appreciated.
Upvotes: 0
Views: 984
Reputation: 1237
This is a known issue, there is a ticket here:
https://github.com/mapbox/mapbox-gl-native/issues/1488
Upvotes: 0
Reputation: 5128
I am wondering whether the changing of map style re-orders the map layers, therefore annotations are drawn below the map tiles?
This doesn't sound right. Please open a ticket so that we can address this directly.
Upvotes: 0