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

[iOS] MapBox delegates not working properly since update. #5755

Closed

Description

@peterlendvay

iOS
3.3.1

Hello!

Steps to trigger behavior

  1. Since updating to version 3.3.1, various bugs appeared in my project. We had to update, because setting mapbox's style to darkStyle-v9 crashed the app. According to our investigation the library allocated over 800 MB of memory, then the system killed the application. Only setting the dark style caused this, it was working fine with other styles.
  2. First I've realized, when tapping anywhere on the map, where there is no annotation, the didDeselectAnnotation: delegate method doesn't seem to get called. It was working before the update, so I'm guessing it's caused by the version.
  3. Secondly, when selecting annotation "A", then selecting annotation "B", both the didDeselectAnnotation: and the didSelectAnnotation: are messaging the same "B" annotation as the parameter. This is no good, since in the didDeselectAnnotation: method first I want to work with annotation "A", then after the deselection I can work the annotation "B" in the didSelectAnnotation: method. It's important to mention, that I'm using subclasses of MGLPointAnnotation called PoiAnnotation. After further investigation we've realized that didSelectAnnotation is getting called before didDeselectAnnotation. This is probably the cause of the problem. See the attached screenshot please. This was also working before the update, so I'm guessing it's also caused by the version.
    kepernyofoto 2016-07-22 - 13 21 54

Expected behavior

Delegates to work properly.

Actual behavior

Delegates not working properly.

If I'm doing anything wrong, please let me know, and I'll try to fix it.
Thanks!

Peter

Activity

  1. added
    iOS
    annotations
    on Jul 22, 2016
  2. 1ec5 commented on Jul 22, 2016

    @1ec5
    Contributor

    Since updating to version 3.3.1, various bugs appeared in my project. We had to update, because setting mapbox's style to darkStyle-v9 crashed the app. According to our investigation the library allocated over 800 MB of memory, then the system killed the application. Only setting the dark style caused this, it was working fine with other styles.

    This issue affected users who downloaded (and thus cached) the style for the first time during a particular window in which the server was sending malformed data. There’s more information about who’s affected in #5722 (comment) and this incident report. Indeed, the fix is to upgrade to v3.3.1. Please let us know if you or your users continue to run into this issue after upgrading.

    For the annotation-related issues, are you using the new MGLAnnotationView API (view-backed point annotations) or the older MGLAnnotationImage API (static image point annotations)?

  3. peterlendvay commented on Jul 25, 2016

    @peterlendvay
    Author

    Hello and thanks for the fast answer,

    We are using MGLAnnotationImage, since we use custom images for the annotations, and a unique one for the selected one. Each of them is dequeued with a custom ID, and then based on the selected annotation's ID we are dequeueing an MGLAnnotationImage, and then it's image property is changed based on the fired didDeselectAnnotation: & didSelectAnnotation:.

    Should we use the new MGLAnnotationView? Will it be the solution for our problem? What do you suggest?

    Thanks!

    Peter

    EDIT:
    MGLAnnotationView doesn't seem to have an image property. How do you change it's image? (in our case the annotation image is changed to red when selected, and back to white, when deselected)

  4. 1ec5 commented on Jul 25, 2016

    @1ec5
    Contributor

    I don’t think MGLAnnotationView will behave any differently than MGLAnnotationImage in this case. I just wanted to check in case the issue affects one but not the other.

    In my test application, which uses v3.3.1 and drops a pin when long pressing, I added this code to the MGLMapViewDelegate:

    - (void)mapView:(MGLMapView *)mapView didDeselectAnnotation:(id<MGLAnnotation>)annotation {
        NSLog(@"%s %@", __PRETTY_FUNCTION__, annotation);
    }
    
    - (void)mapView:(MGLMapView *)mapView didSelectAnnotation:(id<MGLAnnotation>)annotation {
        NSLog(@"%s %@", __PRETTY_FUNCTION__, annotation);
    }

    Here’s the output from selecting three annotations in turn. The behavior appears to be correct, based on the pointer values:

    2016-07-25 14:59:19.646 Mapbox GL[34155:958420] -[MBXViewController mapView:didSelectAnnotation:] <MBXDroppedPinAnnotation: 0x60000004f5a0; title = "Dropped Pin"; subtitle = "37°20′4″ north, 122°2′15″ west"; coordinate = 37.334544, -122.037623>
    2016-07-25 14:59:20.738 Mapbox GL[34155:958420] -[MBXViewController mapView:didDeselectAnnotation:] <MBXDroppedPinAnnotation: 0x60000004f5a0; title = "Dropped Pin"; subtitle = "37°20′4″ north, 122°2′15″ west"; coordinate = 37.334544, -122.037623>
    2016-07-25 14:59:20.766 Mapbox GL[34155:958420] -[MBXViewController mapView:didSelectAnnotation:] <MBXDroppedPinAnnotation: 0x60800025d0d0; title = "Dropped Pin"; subtitle = "37°20′4″ north, 122°2′14″ west"; coordinate = 37.334531, -122.037323>
    2016-07-25 14:59:21.759 Mapbox GL[34155:958420] -[MBXViewController mapView:didDeselectAnnotation:] <MBXDroppedPinAnnotation: 0x60800025d0d0; title = "Dropped Pin"; subtitle = "37°20′4″ north, 122°2′14″ west"; coordinate = 37.334531, -122.037323>
    2016-07-25 14:59:21.787 Mapbox GL[34155:958420] -[MBXViewController mapView:didSelectAnnotation:] <MBXDroppedPinAnnotation: 0x600000244d70; title = "Dropped Pin"; subtitle = "37°20′4″ north, 122°2′14″ west"; coordinate = 37.334566, -122.037128>
    2016-07-25 14:59:23.927 Mapbox GL[34155:958420] -[MBXViewController mapView:didDeselectAnnotation:] <MBXDroppedPinAnnotation: 0x600000244d70; title = "Dropped Pin"; subtitle = "37°20′4″ north, 122°2′14″ west"; coordinate = 37.334566, -122.037128>
    

    This looks consistent with the screenshot you provided. However, it seems to be the behavior I’d expect: with A already selected, tapping B causes the delegate to be notified about A being deselected then B being selected. In all cases, -mapView:didDeselectAnnotation: is being called before -mapView:didSelectAnnotation:.

    Could you provide some sample code so we can reproduce the issue you’re describing?

  5. peterlendvay commented on Jul 26, 2016

    @peterlendvay
    Author

    Yeah, it seems to work perfect for you. Not sure what am I doing wrong. Here is a gist containing the relevant part of my code. If you could check it out, that would be a huge help.

    Thanks, appreciate the huge support!

  6. 1ec5 commented on Jul 26, 2016

    @1ec5
    Contributor

    MGLAnnotationView doesn't seem to have an image property. How do you change it's image?

    This is being tracked in #5469, but for now MGLAnnotationImage is the easiest way to use a static image. (If you do need to switch to MGLAnnotationView, you'd embed a UIImageView into the annotation view.)

    Looking at your screenshot again, I take it the problem is that the annotation is being deselected automatically as soon as you attempt to select it, is that the case? If so, the reason is that you're changing the map view's center coordinate when the annotation is selected. We have a known issue that the annotation is deselected (closing the callout view) whenever the viewport changes: #3154.

    For now, your workaround would be to reselect the annotation after setting the center coordinate. Since this method will be called reentrantly, you'll need to guard against infinite recursion.

  7. peterlendvay commented on Jul 27, 2016

    @peterlendvay
    Author

    I take it the problem is that the annotation is being deselected automatically as soon as you attempt to select

    Oh man, that was it. Thanks. It seems to fix the delegates, yet I still have problem with changing the image of the MGLAnnotationImage.

    MGLAnnotationImage *annoImage = [mapView dequeueReusableAnnotationImageWithIdentifier:((PoiAnnotation *)annotation).location.locationId];
    annoImage.image = [UIImage imageNamed:@"icon_pin_red"];
    This piece of a code used to work, but doesn't seem to work now. The MGLAnnotationImage's image property seems to change to a different UIImage, yet it's not visible on the map. Any recommendation on this?

  8. 1ec5 commented on Jul 27, 2016

    @1ec5
    Contributor

    Using breakpoints, can you confirm that the image isn't getting reset back to the same image by some other code, perhaps fast enough that you wouldn't perceive a change? In a test application (iosapp, which is in this repository), I brought back the code deleted in #5263 (cc @incanus) in order to exercise changing the image, and it appears to still work.

  9. peterlendvay commented on Jul 28, 2016

    @peterlendvay
    Author

    Here you can see the 3 methods, where the image on the map is manipulated. After using KVO for the image property of MGLAnnotationImage, I can confirm, that the image is changed only in the didSelectAnnotation: and didDeselectAnnotation: delegates. I can pretty much confirm, that the image property is always changed properly, yet it doesn't reflect on the map.

  10. 1ec5 commented on Aug 1, 2016

    @1ec5
    Contributor

    #5230 (comment) illustrates a similar issue involving updating the coordinate of a point annotation, which uses the same mechanism to update the map. Updating the coordinate and image still work in iosapp, but I wonder if something else happens to be forcing the update there.

  11. 1ec5 commented on Aug 1, 2016

    @1ec5
    Contributor

    Let's track these issues in #5720, since we've kind of outgrown the original issues described here.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    annotationsiOS

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions