Custom MKAnnotation image rendering problem after zooms in/out
Closed this issue · 4 comments
Hi,
I have a little problem after multiple zooms in and/or out.
My application has a search view which allows to see a ride between two locations.
After a few zooms in/out and a refocusing on the ride to be in the same view than previously, I have this result.
As you can see, departure marker (initially gray) is replaced by a station marker and third station marker is replaced by arrival marker.
I do not have this problem with a basic MKMapView.
Thanks for help.
Once again, this is a very vague bug report, and there is very little we can do to fix this as is. It is possible that this results from a bug in your app.
What would help would be to provide us with a minimal test case that exhibits the issue. For example something based off our sample code.
I am not sure if this is related, but I am having problems with annotation images being wrong also. They usually load up and display correctly (initially) but after scrolling around, they display the wrong image.
I have written it up here: http://stackoverflow.com/questions/19132570/ios-mapview-custom-annotation-images-are-being-randomly-selected
I just tested with a basic MKMapView, and so far, have not seen the problem.
And pointers on what to do, or where to look would be appreciated.
If it is unrelated, please let me know, and I'll file it as a new issue.
So after digging through the code a little bit, I've come to the conclusion that the wrong images are being displayed because the ADMapPointAnnotations are being reused and animated to the right spot.
my guess is that the MKMapView calls 'viewforannotation' when the annotation is first added, but since we're not adding it again, it simply reuses the view.
My fix is simply removing the annotation from the MKMapView and adding it again (causing an image reload)... it's a bit of a hack, but I don't understand the ADClusterMapView code well enough to do anything more spiffy.
Change is in ADClusterMapView.m
- (void)_clusterInMapRect:(MKMapRect)rect {
...
[UIView beginAnimations:@"ADClusterMapViewAnimation" context:NULL];
[UIView setAnimationBeginsFromCurrentState:NO];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:0.5f];
for (ADClusterAnnotation * annotation in self.annotations) {
if (![annotation isKindOfClass:[MKUserLocation class]] && annotation.cluster) {
NSAssert(!ADClusterCoordinate2DIsOffscreen(annotation.coordinate), @"annotation.coordinate not valid! Can't animate from an invalid coordinate (inconsistent result)!");
// HACK TO FIX WRONG IMAGES
[self removeAnnotation:annotation];
[super addAnnotation:annotation];
// END HACK
annotation.coordinate = annotation.cluster.clusterCoordinate;
}
}
[UIView commitAnimations];
...
Hope this helps. If somebody else has a cleaner fix, please let me know :)
Fix with the version update to 1.2