Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

RMWebTileImage cleanup #168

Closed
wants to merge 2 commits into from

2 participants

@tracyharton

Had some issues with panning away from unloaded tiles, error conditions ...on servers, and incorrect Request/Retrieve counts, so did some work on RMWebTileImage, etc.

@tracyharton tracyharton Had some issues with panning away from unloaded tiles, error conditio…
…ns on servers, and incorrect Request/Retrieved

counts, so did some work on RMWebTileImage, etc.
5b5f387
@vyskocil
Owner

I tried this pull request in my copy of the sources but had some issues :

  • networkOperations remained to FALSE and no tiles were loading, so I had to initialized it back to TRUE.
  • interactive scrolling become very choppy when tiles were loading
@tracyharton

Thanks vyskocil, I had not intended to check in that change re networkOperations.

I hadn't noticed any change in scrolling, but I'll play some more. Can't see what I would have fundamentally changed in that regard...

/tracy

@tracyharton

So I played with this some more comparing master to this patch, but I'm not seeing what you reported. (ie: very choppy) Could you provide some details on your test device?

I am seeing an odd effect where the updating tiles don't quite scroll with the map immediately, but I see that with or without the patch. It does seem slightly different, but mainly looks like a difference in the speed of tiles downloading?

@vyskocil
Owner

Sorry I miss your updates, I'll check the patch again.
I remember that in my copy of route-me I changed the animation that reveal the tiles from the one in the default tree.

@agolovatuk agolovatuk referenced this pull request from a commit in agolovatuk/route-me
@agolovatuk agolovatuk Merge with route_me/route_me added fixed #168 #169, rotation fix from…
… Computer Ace touch_enhancements
81172ac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 21, 2012
  1. @tracyharton

    Had some issues with panning away from unloaded tiles, error conditio…

    tracyharton authored
    …ns on servers, and incorrect Request/Retrieved
    
    counts, so did some work on RMWebTileImage, etc.
Commits on Mar 23, 2012
  1. @tracyharton
This page is out of date. Refresh to see the latest.
View
10 MapView/Map/RMURLConnectionOperation.m
@@ -26,6 +26,7 @@
// POSSIBILITY OF SUCH DAMAGE.
#import "RMURLConnectionOperation.h"
+#import "RMNotifications.h"
@implementation RMURLConnectionOperation
@@ -33,8 +34,10 @@ -(id)initWithRequest:(NSURLRequest *)request delegate:(id)delegate {
if((self = [super init]))
{
_delegate = delegate;
+ _connection = nil;
_request = [request retain];
_isRunning = YES;
+
}
return self;
}
@@ -44,9 +47,16 @@ -(void)main {
{
return;
}
+ [[NSNotificationCenter defaultCenter] postNotificationName:RMTileRequested object:self];
+
_connection = [[NSURLConnection alloc] initWithRequest:_request delegate:_delegate startImmediately:YES];
+
[_request release];_request = nil;
+
while (_isRunning && ![self isCancelled] && [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]]);
+
+ [[NSNotificationCenter defaultCenter] postNotificationName:RMTileRetrieved object:self];
+
[_connection cancel];
[_connection release];
_connection = nil;
View
5 MapView/Map/RMWebTileImage.h
@@ -32,6 +32,7 @@
static const NSUInteger kWebTileRetries = 30;
static const NSUInteger kMaxConcurrentConnections = 5;
+static const NSTimeInterval kWebTileRetryDelay = 1.0;
extern NSString *RMWebTileImageErrorDomain;
@@ -49,7 +50,6 @@ extern NSString *RMWebTileImageNotificationErrorKey;
/// RMTileImage subclass: a tile image loaded from a URL.
@interface RMWebTileImage : RMTileImage {
NSUInteger retries;
- NSError *lastError;
NSURL *url;
RMURLConnectionOperation *connectionOp;
@@ -59,6 +59,9 @@ extern NSString *RMWebTileImageNotificationErrorKey;
- (id) initWithTile: (RMTile)tile FromURL:(NSString*)url;
- (void) requestTile;
+- (void) retryTile:(NSError *)error;
+- (void) missingTile:(NSError *)error;
+- (void) errorTile:(NSError *)error;
- (void) startLoading:(NSTimer *)timer;
@end
View
207 MapView/Map/RMWebTileImage.m
@@ -50,20 +50,16 @@ - (id) initWithTile: (RMTile)_tile FromURL:(NSString*)urlStr
if (![super initWithTile:_tile])
return nil;
- [super displayProxy:[RMTileProxy loadingTile]];
+ [super displayProxy:[RMTileProxy loadingTile]];
-
url = [[NSURL alloc] initWithString:urlStr];
-
-
- connectionOp = nil;
-
+
+ connectionOp = nil;
+
data =[[NSMutableData alloc] initWithCapacity:0];
-
+
retries = kWebTileRetries;
-
- [[NSNotificationCenter defaultCenter] postNotificationName:RMTileRequested object:self];
-
+
[self requestTile];
return self;
@@ -71,10 +67,9 @@ - (id) initWithTile: (RMTile)_tile FromURL:(NSString*)urlStr
- (void) dealloc
{
- [self cancelLoading];
-
- if ( lastError ) [lastError release]; lastError = nil;
-
+ [connectionOp release];
+ connectionOp = nil;
+
[data release];
data = nil;
@@ -84,64 +79,71 @@ - (void) dealloc
[super dealloc];
}
-- (void) requestTile
+- (void) missingTile: (NSError *) error
{
- //RMLog(@"fetching: %@", url);
- if(connectionOp) // re-request
- {
- //RMLog(@"Refetching: %@: %d", url, retries);
-
- [connectionOp cancel];
- [connectionOp release];
- connectionOp = nil;
-
- if(retries == 0) // No more retries
- {
- [super displayProxy:[RMTileProxy errorTile]];
- [[NSNotificationCenter defaultCenter] postNotificationName:RMTileRetrieved object:self];
+ [self cancelLoading];
+
+ [super displayProxy:[RMTileProxy missingTile]];
+ // [[NSNotificationCenter defaultCenter] postNotificationName:RMTileRetrieved object:self];
+
+ [[NSNotificationCenter defaultCenter] postNotificationName:RMTileError object:self userInfo:[NSDictionary dictionaryWithObject:error forKey:RMWebTileImageNotificationErrorKey]];
+}
- [[NSNotificationCenter defaultCenter] postNotificationName:RMTileError object:self userInfo:[NSDictionary dictionaryWithObject:lastError forKey:RMWebTileImageNotificationErrorKey]];
- [lastError autorelease]; lastError = nil;
+- (void) errorTile: (NSError *) error
+{
+ [self cancelLoading];
+
+ [super displayProxy:[RMTileProxy errorTile]];
+ //[[NSNotificationCenter defaultCenter] postNotificationName:RMTileRetrieved object:self];
+
+ [[NSNotificationCenter defaultCenter] postNotificationName:RMTileError object:self userInfo:[NSDictionary dictionaryWithObject:error forKey:RMWebTileImageNotificationErrorKey]];
+}
- return;
- }
- retries--;
+- (void) retryTile: (NSError *) error
+{
+ [connectionOp stop];
+
+ if(retries == 0) // No more retries
+ {
+ [self errorTile:error];
+ }
+ else
+ {
+ retries--;
+
+ [connectionOp release];
+ [NSTimer scheduledTimerWithTimeInterval:kWebTileRetryDelay target:self selector:@selector(startLoading:) userInfo:nil repeats:NO];
+ }
+}
- [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(startLoading:) userInfo:nil repeats:NO];
- }
- else
- {
- [self startLoading:nil];
- }
+- (void) requestTile
+{
+ [self startLoading:nil];
}
- (void) startLoading:(NSTimer *)timer
{
NSURLRequest *request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:30.0];
-
- connectionOp = [[RMURLConnectionOperation alloc] initWithRequest:request delegate:self];
+ connectionOp = [[RMURLConnectionOperation alloc] initWithRequest:request delegate:self];
+
if (!connectionOp)
{
- [super displayProxy:[RMTileProxy errorTile]];
- [[NSNotificationCenter defaultCenter] postNotificationName:RMTileRetrieved object:self];
- } else {
+ NSError *error = [NSError errorWithDomain:RMWebTileImageErrorDomain
+ code:RMWebTileImageErrorNotFoundResponse
+ userInfo:[NSDictionary dictionaryWithObjectsAndKeys:
+ NSLocalizedString(@"The RMURLConnectionOperation failed", @""), NSLocalizedDescriptionKey, nil]];
+
+ [self errorTile:error];
+ } else
+ {
[_queue addOperation:connectionOp];
}
}
- (void) cancelLoading
-{
- if (!connectionOp)
- return;
-
- [[NSNotificationCenter defaultCenter] postNotificationName:RMTileRetrieved object:self];
-
+{
[connectionOp stop];
- [connectionOp release];
- connectionOp = nil;
-
- if ( lastError ) [lastError release]; lastError = nil;
[super cancelLoading];
}
@@ -169,38 +171,36 @@ - (void)connection:(NSURLConnection *)_connection didReceiveResponse:(NSURLRespo
}
int statusCode = NSURLErrorUnknown; // unknown
-
+
if([response isKindOfClass:[NSHTTPURLResponse class]])
- statusCode = [(NSHTTPURLResponse*)response statusCode];
-
+ statusCode = [(NSHTTPURLResponse*)response statusCode];
+
[data setLength:0];
- /// \bug magic number
+ /// \bug magic number
if(statusCode < 400) // Success
{
}
- /// \bug magic number
+ /// \bug magic number
else if(statusCode == 404) // Not Found
{
- [super displayProxy:[RMTileProxy missingTile]];
NSError *error = [NSError errorWithDomain:RMWebTileImageErrorDomain
code:RMWebTileImageErrorNotFoundResponse
userInfo:[NSDictionary dictionaryWithObjectsAndKeys:
- NSLocalizedString(@"The requested tile was not found on the server", @""), NSLocalizedDescriptionKey, nil]];
-
- [[NSNotificationCenter defaultCenter] postNotificationName:RMTileError object:self userInfo:[NSDictionary dictionaryWithObject:error forKey:RMWebTileImageNotificationErrorKey]];
- [self cancelLoading];
+ NSLocalizedString(@"The requested tile was not found on the server", @""), NSLocalizedDescriptionKey, nil]];
+ [_connection cancel];
+ [self missingTile:error];
}
else // Other Error
{
//RMLog(@"didReceiveResponse %@ %d", _connection, statusCode);
-
+
BOOL retry = FALSE;
switch(statusCode)
{
- /// \bug magic number
+ /// \bug magic number
case 500: retry = TRUE; break;
case 503: retry = TRUE; break;
}
@@ -213,14 +213,12 @@ - (void)connection:(NSURLConnection *)_connection didReceiveResponse:(NSURLRespo
if(retry)
{
- if ( lastError ) [lastError release];
- lastError = [error retain];
- [self requestTile];
+ [self retryTile:error];
}
else
{
- [[NSNotificationCenter defaultCenter] postNotificationName:RMTileError object:self userInfo:[NSDictionary dictionaryWithObject:error forKey:RMWebTileImageNotificationErrorKey]];
- [self cancelLoading];
+ [_connection cancel];
+ [self errorTile:error];
}
}
}
@@ -243,30 +241,26 @@ - (void)connection:(NSURLConnection *)_connection didFailWithError:(NSError *)er
switch([error code])
{
- case NSURLErrorBadURL: // -1000
- case NSURLErrorTimedOut: // -1001
- case NSURLErrorUnsupportedURL: // -1002
- case NSURLErrorCannotFindHost: // -1003
- case NSURLErrorCannotConnectToHost: // -1004
- case NSURLErrorNetworkConnectionLost: // -1005
- case NSURLErrorDNSLookupFailed: // -1006
- case NSURLErrorResourceUnavailable: // -1008
- case NSURLErrorNotConnectedToInternet: // -1009
+ case NSURLErrorBadURL: // -1000
+ case NSURLErrorTimedOut: // -1001
+ case NSURLErrorUnsupportedURL: // -1002
+ case NSURLErrorCannotFindHost: // -1003
+ case NSURLErrorCannotConnectToHost: // -1004
+ case NSURLErrorNetworkConnectionLost: // -1005
+ case NSURLErrorDNSLookupFailed: // -1006
+ case NSURLErrorResourceUnavailable: // -1008
+ case NSURLErrorNotConnectedToInternet: // -1009
retry = TRUE;
break;
}
if(retry)
{
- if ( lastError ) [lastError release];
- lastError = [error retain];
-
- [self requestTile];
+ [self retryTile:error];
}
else
{
- [[NSNotificationCenter defaultCenter] postNotificationName:RMTileError object:self userInfo:[NSDictionary dictionaryWithObject:error forKey:RMWebTileImageNotificationErrorKey]];
- [self cancelLoading];
+ [self errorTile:error];
}
}
@@ -282,36 +276,25 @@ - (void)connectionDidFinishLoading:(NSURLConnection *)_connection
{
//RMLog(@"connectionDidFinishLoading %@ data size %d", _connection, [data length]);
- if ( lastError ) [lastError release];
- lastError = [[NSError errorWithDomain:RMWebTileImageErrorDomain
- code:RMWebTileImageErrorZeroLengthResponse
- userInfo:[NSDictionary dictionaryWithObjectsAndKeys:
- NSLocalizedString(@"The server returned a zero-length response", @""), NSLocalizedDescriptionKey, nil]] retain];
- [self requestTile];
+ NSError *error = [[NSError errorWithDomain:RMWebTileImageErrorDomain
+ code:RMWebTileImageErrorZeroLengthResponse
+ userInfo:[NSDictionary dictionaryWithObjectsAndKeys:
+ NSLocalizedString(@"The server returned a zero-length response", @""), NSLocalizedDescriptionKey, nil]] retain];
+ [self retryTile:error];
}
else
{
- if ( ![self updateImageUsingData:data] ) {
- if ( lastError ) [lastError release];
- lastError = [[NSError errorWithDomain:RMWebTileImageErrorDomain
- code:RMWebTileImageErrorUnexpectedHTTPResponse
- userInfo:[NSDictionary dictionaryWithObjectsAndKeys:
- NSLocalizedString(@"The server returned an invalid response", @""), NSLocalizedDescriptionKey, nil]] retain];
- [self requestTile];
- return;
+ if ( ![self updateImageUsingData:data] )
+ {
+ NSError *error = [[NSError errorWithDomain:RMWebTileImageErrorDomain
+ code:RMWebTileImageErrorUnexpectedHTTPResponse
+ userInfo:[NSDictionary dictionaryWithObjectsAndKeys:
+ NSLocalizedString(@"The server returned an invalid response", @""), NSLocalizedDescriptionKey, nil]] retain];
+ [self retryTile:error];
+ }
+ else {
+ //[[NSNotificationCenter defaultCenter] postNotificationName:RMTileRetrieved object:self];
}
-
- [data release];
- data = nil;
- [url release];
- url = nil;
- [connectionOp stop];
- [connectionOp release];
- connectionOp = nil;
-
- if ( lastError ) [lastError release]; lastError = nil;
-
- [[NSNotificationCenter defaultCenter] postNotificationName:RMTileRetrieved object:self];
}
}
Something went wrong with that request. Please try again.