Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

GLMapView hides / fails to load annotations when I change map style #2235

Closed
ejdslayer opened this issue Sep 2, 2015 · 1 comment
Closed

Comments

@ejdslayer
Copy link

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: #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:

ios simulator screen shot 28 aug 2015 11 47 28
ios simulator screen shot 28 aug 2015 11 47 35
ios simulator screen shot 28 aug 2015 11 47 42

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?

@1ec5
Copy link
Contributor

1ec5 commented Sep 2, 2015

Duplicate of #1488.

@1ec5 1ec5 closed this as completed Sep 2, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants