Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 01-26-2012, 02:35 PM   #1 (permalink)
Registered Member
 
Join Date: Feb 2011
Posts: 84
BrendanF is on a distinguished road
Default Custom Annotation View with Web Images

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?
BrendanF is offline   Reply With Quote
Old 01-26-2012, 03:53 PM   #2 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by BrendanF View Post
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.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Old 01-27-2012, 10:55 AM   #3 (permalink)
Registered Member
 
Join Date: Feb 2011
Posts: 84
BrendanF is on a distinguished road
Default

Quote:
Originally Posted by Duncan C View Post
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.
I was trying the removeAnnotation and addAnnotation at first and it was not working. I instead removed all the annotations currently on the map and re-added them each time an image was downloaded and this worked. It did however take away from the user experience as the would annotations blink a couple times. I then tried to fix this by doing it individually and it appears to be working. For anyone interested, I used JMImageCache with this code in the callback:

Code:
- (void) cache:(JMImageCache *)c didDownloadImage:(UIImage *)i forURL:(NSString *)url
{
    if ([url isEqualToString:image_url]) {
        [self setImage:i];
       
        [self setNeedsLayout];
        [self setNeedsDisplay];
        
        //Get the map from the appropriate ViewController
        
        if (self != nil && [self customAnnotation] != nil) {
            [yourMap removeAnnotation:[self customAnnotation]];
            [yourMap addAnnotation:[self customAnnotation]];
        }
    }
}

Last edited by BrendanF; 01-27-2012 at 11:00 AM.
BrendanF is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 401
9 members and 392 guests
Atatator, condor304, FrankWeller, MAMN84, mraalex, n00b, PowerGoofy, tim0504, VinceYuan
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,674
Threads: 94,123
Posts: 402,908
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Atatator
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 05:56 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0