...
|
...
|
@@ -31,11 +31,16 @@ |
|
|
|
|
|
@implementation RMAbstractWebMapSource
|
|
|
|
|
|
@synthesize retryCount, waitSeconds;
|
|
|
|
|
|
- (id)init
|
|
|
{
|
|
|
if (!(self = [super init]))
|
|
|
return nil;
|
|
|
|
|
|
self.retryCount = RMAbstractWebMapSourceDefaultRetryCount;
|
|
|
self.waitSeconds = RMAbstractWebMapSourceDefaultWaitSeconds;
|
|
|
|
|
|
return self;
|
|
|
}
|
|
|
|
...
|
...
|
@@ -74,12 +79,12 @@ |
|
|
//
|
|
|
NSMutableArray *tilesData = [NSMutableArray arrayWithCapacity:[URLs count]];
|
|
|
|
|
|
for (int p = 0; p < [URLs count]; p++)
|
|
|
for (int p = 0; p < [URLs count]; ++p)
|
|
|
[tilesData addObject:[NSNull null]];
|
|
|
|
|
|
dispatch_group_t fetchGroup = dispatch_group_create();
|
|
|
|
|
|
for (int u = 0; u < [URLs count]; u++)
|
|
|
for (int u = 0; u < [URLs count]; ++u)
|
|
|
{
|
|
|
NSURL *currentURL = [URLs objectAtIndex:u];
|
|
|
|
...
|
...
|
@@ -87,11 +92,11 @@ |
|
|
{
|
|
|
NSData *tileData = nil;
|
|
|
|
|
|
for (int try = 0; try < RMAbstractWebMapSourceRetryCount; try++)
|
|
|
for (int try = 0; tileData == nil && try < self.retryCount; ++try)
|
|
|
{
|
|
|
if ( ! tileData)
|
|
|
// Beware: dataWithContentsOfURL is leaking like hell. Better use AFNetwork or ASIHTTPRequest
|
|
|
tileData = [NSData dataWithContentsOfURL:currentURL options:NSDataReadingUncached error:NULL];
|
|
|
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:currentURL];
|
|
|
[request setTimeoutInterval:(self.waitSeconds / (CGFloat)self.retryCount)];
|
|
|
tileData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
|
|
|
}
|
|
|
|
|
|
if (tileData)
|
...
|
...
|
@@ -108,7 +113,7 @@ |
|
|
|
|
|
// wait for whole group of fetches (with retries) to finish, then clean up
|
|
|
//
|
|
|
dispatch_group_wait(fetchGroup, dispatch_time(DISPATCH_TIME_NOW, NSEC_PER_SEC * RMAbstractWebMapSourceWaitSeconds));
|
|
|
dispatch_group_wait(fetchGroup, dispatch_time(DISPATCH_TIME_NOW, NSEC_PER_SEC * self.waitSeconds));
|
|
|
dispatch_release(fetchGroup);
|
|
|
|
|
|
// composite the collected images together
|
...
|
...
|
|