You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
Repository navigation
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
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.
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.
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.
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!
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)?
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)
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:
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?
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.
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.
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?
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.
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.
#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.
Activity
1ec5 commentedon Jul 22, 2016
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)?
peterlendvay commentedon Jul 25, 2016
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 anMGLAnnotationImage, and then it's image property is changed based on the fireddidDeselectAnnotation:&didSelectAnnotation:.Should we use the new
MGLAnnotationView? Will it be the solution for our problem? What do you suggest?Thanks!
Peter
EDIT:
MGLAnnotationViewdoesn'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)1ec5 commentedon Jul 25, 2016
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:
Here’s the output from selecting three annotations in turn. The behavior appears to be correct, based on the pointer values:
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?
peterlendvay commentedon Jul 26, 2016
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!
1ec5 commentedon Jul 26, 2016
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.
peterlendvay commentedon Jul 27, 2016
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'simage property seems to change to a different UIImage, yet it's not visible on the map. Any recommendation on this?1ec5 commentedon Jul 27, 2016
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.
peterlendvay commentedon Jul 28, 2016
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 thedidSelectAnnotation:anddidDeselectAnnotation:delegates. I can pretty much confirm, that the image property is always changed properly, yet it doesn't reflect on the map.1ec5 commentedon Aug 1, 2016
#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.
1ec5 commentedon Aug 1, 2016
Let's track these issues in #5720, since we've kind of outgrown the original issues described here.