Quote:
Originally Posted by BrendanF
I currently have a map with custom annotation views that have their image property set to web images. I have a delegate that calls a function when the image is finished downloading. My question: how can I refresh the map each time an image is finished downloading.
I currently have in the custom annotation view's didDownloadImage function:
Code:
[self setNeedsDisplay];
[self setNeedsLayout];
[[viewController mapView] setNeedsDisplay];
[[viewController mapView] setNeedsLayout];
The images that are downloaded immediately are displayed, but the images that take time to download are only displayed after removing and readding the marker. I am looking for a way to just refresh the map so that each annotation is refreshed. Is there an efficient way to do this?
|
Interesting.
You could always get the array of annotations from the map and copy it, then
1. Pass that array of annotations to removeAnnotations
2. Pass the same array of annotations to addAnnotations.
3. Release the array
Removing the annotations and re-adding them would force the map view to remove the annotations and re-add them to the map.
If you are only changing a few, you could remove and then re-add the individual annotation objects as their artwork finishes downloading. That would probably give a cleaner user experience, because each annotation would update one at a time as it's artwork finishes downloading.
I assume that you have a pointer to an annotation for which you're downloading an image, right? Then you could simply do this:
Code:
- (void) downloadCompleteForAnnotation: (MyAnnotationType*) theAnnotation;
{
[theAnnotation retain];
[theMapView removeAnnotation: theAnnotation];
[theMapView addAnnotation: theAnnotation];
[theAnnotation release];
}
You could skip the retain and release if you're already retaining the annotation object. If you're not, though, then I bet removing the annotation from the map would cause it to get deallocated. Thus, the retain/release code I included above.