[MGLAnnotationImage] does not work #1872

Closed
xrayed opened this Issue Jul 10, 2015 · 11 comments

Comments

Projects
None yet
3 participants
@xrayed

xrayed commented Jul 10, 2015

- (MGLAnnotationImage *)mapView:(MGLMapView *)mapView imageForAnnotation:(LocationBasedObjectAnnotation *)annotation {
  .....
    return [MGLAnnotationImage annotationImageWithImage:image reuseIdentifier:reuseIdentifier];
}

After update from 0.4.5 map annotations stopped being displayed if I use new delegate method

@1ec5

This comment has been minimized.

Show comment
Hide comment
@1ec5

1ec5 Jul 10, 2015

Member

What format is the image in? Did you load it from a bundle resource or draw it on the fly?

Member

1ec5 commented Jul 10, 2015

What format is the image in? Did you load it from a bundle resource or draw it on the fly?

@friedbunny

This comment has been minimized.

Show comment
Hide comment
@friedbunny

friedbunny Jul 10, 2015

Member

Hi @xrayed, we're going to need a little bit more info. How and where are you adding your annotation? How is image set and what format is it?

Member

friedbunny commented Jul 10, 2015

Hi @xrayed, we're going to need a little bit more info. How and where are you adding your annotation? How is image set and what format is it?

@xrayed

This comment has been minimized.

Show comment
Hide comment
@xrayed

xrayed Jul 10, 2015

UIImage * image = [UIImage imageNamed:@"portrait_small_background_1"];
During debug I double checked that image object is there (not NULL)
I attached images.

Check if your code works correctly with @2x and @3X images
portrait_small_background_1 3x
portrait_small_background_1 2x

Annotation itself has been added correctly because before I upgraded static library from 0.4.5 to 0.5. it was displayed properly.

xrayed commented Jul 10, 2015

UIImage * image = [UIImage imageNamed:@"portrait_small_background_1"];
During debug I double checked that image object is there (not NULL)
I attached images.

Check if your code works correctly with @2x and @3X images
portrait_small_background_1 3x
portrait_small_background_1 2x

Annotation itself has been added correctly because before I upgraded static library from 0.4.5 to 0.5. it was displayed properly.

@friedbunny

This comment has been minimized.

Show comment
Hide comment
@friedbunny

friedbunny Jul 10, 2015

Member

@xrayed Is there any console output — errors or warnings? Does the app crash?

Member

friedbunny commented Jul 10, 2015

@xrayed Is there any console output — errors or warnings? Does the app crash?

@xrayed

This comment has been minimized.

Show comment
Hide comment
@xrayed

xrayed Jul 10, 2015

I'm out of office, I will provide console logs only tomorrow, there were no app crashes.

xrayed commented Jul 10, 2015

I'm out of office, I will provide console logs only tomorrow, there were no app crashes.

@xrayed

This comment has been minimized.

Show comment
Hide comment
@xrayed

xrayed Jul 13, 2015

No crash and nothing in console, I'll wait for next release and try again

xrayed commented Jul 13, 2015

No crash and nothing in console, I'll wait for next release and try again

@xrayed

This comment has been minimized.

Show comment
Hide comment
@xrayed

xrayed Jul 14, 2015

I got more details when I tried v0.5.1:

Here is delegate method:

- (MGLAnnotationImage *)mapView:(MGLMapView *)mapView imageForAnnotation:(LocationBasedObjectAnnotation *)annotation {
    UIImage * image = [UIImage imageNamed:@"portrait_small_background_1"];
    NSString * reuseIdentifier = NSStringFromClass(annotation.class);
    return [MGLAnnotationImage annotationImageWithImage:image reuseIdentifier:reuseIdentifier];
}

Console log output:

[INFO] {Worker}[Sprite]: Can't find sprite named 'com.mapbox.sprites.CharacterAnnotation'

The thing is that this line is shown different amount of times if I run app again and again, it never corresponds to number of Annotations I have added (currently I added 5 annotations)

If I change number of annotations to 1 and run app again it has permanent crash (see attachment)

screen shot 2015-07-14 at 11 20 42

xrayed commented Jul 14, 2015

I got more details when I tried v0.5.1:

Here is delegate method:

- (MGLAnnotationImage *)mapView:(MGLMapView *)mapView imageForAnnotation:(LocationBasedObjectAnnotation *)annotation {
    UIImage * image = [UIImage imageNamed:@"portrait_small_background_1"];
    NSString * reuseIdentifier = NSStringFromClass(annotation.class);
    return [MGLAnnotationImage annotationImageWithImage:image reuseIdentifier:reuseIdentifier];
}

Console log output:

[INFO] {Worker}[Sprite]: Can't find sprite named 'com.mapbox.sprites.CharacterAnnotation'

The thing is that this line is shown different amount of times if I run app again and again, it never corresponds to number of Annotations I have added (currently I added 5 annotations)

If I change number of annotations to 1 and run app again it has permanent crash (see attachment)

screen shot 2015-07-14 at 11 20 42

@friedbunny

This comment has been minimized.

Show comment
Hide comment
@friedbunny

friedbunny Jul 14, 2015

Member

The reuse identifier exists so that each delegate call doesn't need to load a new image. I'd suggest following a pattern that checks if MGLAnnotationImage exists with the desired identifier, like in this example:

- (MGLAnnotationImage *)mapView:(MGLMapView *)mapView imageForAnnotation:(id <MGLAnnotation>)annotation
{
    MGLAnnotationImage *annotationImage = [mapView dequeueReusableAnnotationImageWithIdentifier:@"whatever"];

    if ( ! annotationImage)
    {
        UIImage *image = [UIImage imageNamed:@"whatever"];
        annotationImage = [MGLAnnotationImage annotationImageWithImage:image reuseIdentifier:@"whatever"];
    }

    return annotationImage;
}
Member

friedbunny commented Jul 14, 2015

The reuse identifier exists so that each delegate call doesn't need to load a new image. I'd suggest following a pattern that checks if MGLAnnotationImage exists with the desired identifier, like in this example:

- (MGLAnnotationImage *)mapView:(MGLMapView *)mapView imageForAnnotation:(id <MGLAnnotation>)annotation
{
    MGLAnnotationImage *annotationImage = [mapView dequeueReusableAnnotationImageWithIdentifier:@"whatever"];

    if ( ! annotationImage)
    {
        UIImage *image = [UIImage imageNamed:@"whatever"];
        annotationImage = [MGLAnnotationImage annotationImageWithImage:image reuseIdentifier:@"whatever"];
    }

    return annotationImage;
}
@xrayed

This comment has been minimized.

Show comment
Hide comment
@xrayed

xrayed Jul 14, 2015

but then my crash log is still valid since when I try with 1 annotation the delegate method will be called only once so [dequeueReusableAnnotationImageWithIdentifier] call will not help

xrayed commented Jul 14, 2015

but then my crash log is still valid since when I try with 1 annotation the delegate method will be called only once so [dequeueReusableAnnotationImageWithIdentifier] call will not help

@friedbunny

This comment has been minimized.

Show comment
Hide comment
@friedbunny

friedbunny Jul 14, 2015

Member

@xrayed You're right, of course. 😄

It looks like the annotations are being added in viewDidLoad — there was/is a crash (#1874) when annotations are added too quickly after map initialization. Could you please try adding the annotations in viewDidAppear?

Member

friedbunny commented Jul 14, 2015

@xrayed You're right, of course. 😄

It looks like the annotations are being added in viewDidLoad — there was/is a crash (#1874) when annotations are added too quickly after map initialization. Could you please try adding the annotations in viewDidAppear?

@friedbunny

This comment has been minimized.

Show comment
Hide comment
@friedbunny

friedbunny Jul 14, 2015

Member

#1874 fixes this crash and will be included in the next release. In the meantime, please use add annotations in viewDidAppear. Thanks for your help in tracking this down, @xrayed.

Member

friedbunny commented Jul 14, 2015

#1874 fixes this crash and will be included in the next release. In the meantime, please use add annotations in viewDidAppear. Thanks for your help in tracking this down, @xrayed.

@friedbunny friedbunny closed this Jul 14, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment