Authored by Thomas Rasch

Merge branch 'release' into develop

... ... @@ -46,7 +46,7 @@
if (!(self = [super init]))
return nil;
[self setQueuePriority:10]; // Highest priority
// [self setQueuePriority:10]; // Highest priority
connection = nil;
retries = kWebTileRetries;
... ... @@ -100,6 +100,11 @@
return;
}
if (tileImage.loadingCancelled) {
[self finish];
return;
}
[self willChangeValueForKey:@"isExecuting"];
isExecuting = YES;
[self didChangeValueForKey:@"isExecuting"];
... ... @@ -119,25 +124,27 @@
int statusCode = NSURLErrorUnknown; // unknown
if ([aResponse isKindOfClass:[NSHTTPURLResponse class]])
statusCode = [(NSHTTPURLResponse *)aResponse statusCode];
[data setLength:0];
if (statusCode < 400) { // Success
}
else if (statusCode == 404) { // Not Found
[tileImage updateWithImage:[RMTileImage missingTile] andNotify:NO];
if (!tileImage.loadingCancelled)
[tileImage updateWithImage:[RMTileImage missingTile] andNotify:NO];
[self finish];
}
else { // Other Error
//RMLog(@"didReceiveResponse %@ %d", _connection, statusCode);
BOOL retry = FALSE;
switch(statusCode)
{
case 500: retry = TRUE; break;
case 503: retry = TRUE; break;
}
if (retry) {
[self start];
}
... ... @@ -158,6 +165,11 @@
[self start];
}
else {
if (tileImage.loadingCancelled) {
[self finish];
return;
}
UIImage *image = [UIImage imageWithData:data];
[tileImage updateWithImage:image andNotify:YES];
if (tileCache) [tileCache addImage:image forTile:tileImage.tile withCacheKey:cacheKey];
... ... @@ -228,10 +240,12 @@
{
RMTile tile = [[self mercatorToTileProjection] normaliseTile:tileImage.tile];
for (NSOperation *currentRequest in [requestQueue operations])
{
[currentRequest setQueuePriority:[currentRequest queuePriority] - 1];
}
// [requestQueue setSuspended:YES];
// for (NSOperation *currentRequest in [requestQueue operations])
// {
// [currentRequest setQueuePriority:[currentRequest queuePriority] - 1];
// }
// [requestQueue setSuspended:NO];
[requestQueue addOperation:[RMWebDownloadOperation operationWithUrl:[self URLForTile:tile] withTileImage:tileImage andTileCache:tileCache withCacheKey:aCacheKey]];
... ...
... ... @@ -73,19 +73,6 @@
{
}
- (id <CAAction>)actionForLayer:(CALayer *)theLayer forKey:(NSString *)key
{
if (theLayer == layer) {
return nil;
}
if ([key isEqualToString:@"position"] || [key isEqualToString:@"bounds"])
return nil;
else {
return nil;
}
}
- (void)tileImageAdded:(RMTileImage *)image
{
// RMLog(@"tileAdded: %d %d %d at %f %f %f %f", tile.x, tile.y, tile.zoom, image.screenLocation.origin.x, image.screenLocation.origin.y,
... ... @@ -127,8 +114,7 @@
RMTileImage *image = nil;
RMTile tile = tileImage.tile;
NSUInteger i = [tiles count];
while (i--)
for (NSInteger i = [tiles count]-1; i>=0; --i)
{
RMTileImage *potential = [tiles objectAtIndex:i];
... ...
... ... @@ -30,7 +30,7 @@
#import "RMTileImage.h"
#import "RMTile.h"
#define kWriteQueueLimit 25
#define kWriteQueueLimit 15
@interface RMDatabaseCache ()
... ... @@ -199,7 +199,12 @@
// Don't add new images to the database while there are still more than kWriteQueueLimit
// insert operations pending. This prevents some memory issues.
if ([writeQueue operationCount] > kWriteQueueLimit) return;
BOOL skipThisTile = NO;
[writeQueueLock lock];
if ([writeQueue operationCount] > kWriteQueueLimit) skipThisTile = YES;
[writeQueueLock unlock];
if (skipThisTile) return;
[writeQueue addOperationWithBlock:^{
// RMLog(@"addData\t%d", tileHash);
... ...
... ... @@ -45,11 +45,14 @@
// Only used when appropriate
CALayer *layer;
BOOL loadingCancelled;
}
@property (readwrite, assign) CGRect screenLocation;
@property (readonly, assign) RMTile tile;
@property (readonly) CALayer *layer;
@property (readonly) BOOL loadingCancelled;
+ (UIImage *)errorTile;
+ (UIImage *)missingTile;
... ...
... ... @@ -40,7 +40,7 @@ static UIImage *_missingTile = nil;
@implementation RMTileImage
@synthesize screenLocation, tile, layer;
@synthesize screenLocation, tile, layer, loadingCancelled;
#pragma mark -
... ... @@ -87,6 +87,7 @@ static UIImage *_missingTile = nil;
tile = _tile;
layer = nil;
screenLocation = CGRectZero;
loadingCancelled = NO;
[self makeLayer];
... ... @@ -124,6 +125,7 @@ static UIImage *_missingTile = nil;
- (void)cancelLoading
{
loadingCancelled = YES;
[[NSNotificationCenter defaultCenter] postNotificationName:RMMapImageLoadingCancelledNotification
object:self];
}
... ... @@ -175,7 +177,7 @@ static UIImage *_missingTile = nil;
[customActions setObject:[NSNull null] forKey:kCAOnOrderIn];
CATransition *reveal = [[CATransition alloc] init];
reveal.duration = 0.3;
reveal.duration = 0.2;
reveal.type = kCATransitionFade;
[customActions setObject:reveal forKey:@"contents"];
[reveal release];
... ...
... ... @@ -36,6 +36,38 @@
#import "RMMercatorToTileProjection.h"
@interface RMShuffleContainer : NSObject
{}
@property (nonatomic, assign) RMTile tile;
@property (nonatomic, assign) CGRect screenLocation;
+ (id)containerWithTile:(RMTile)aTile at:(CGRect)aScreenLocation;
- (id)initWithTile:(RMTile)aTile at:(CGRect)aScreenLocation;
@end
@implementation RMShuffleContainer
@synthesize tile, screenLocation;
+ (id)containerWithTile:(RMTile)aTile at:(CGRect)aScreenLocation
{
return [[[self alloc] initWithTile:aTile at:aScreenLocation] autorelease];
}
- (id)initWithTile:(RMTile)aTile at:(CGRect)aScreenLocation
{
if (!(self = [super init])) return nil;
self.tile = aTile;
self.screenLocation = aScreenLocation;
return self;
}
@end
#pragma mark -
@implementation RMTileImageSet
@synthesize delegate, tileDepth, zoom;
... ... @@ -246,6 +278,8 @@
screenLocation.size.height = pixelsPerTile;
t.zoom = rect.origin.tile.zoom;
NSMutableArray *tilesToLoad = [NSMutableArray array];
for (t.x = roundedRect.origin.tile.x; t.x < roundedRect.origin.tile.x + tileRegionWidth; t.x++)
{
for (t.y = roundedRect.origin.tile.y; t.y < roundedRect.origin.tile.y + tileRegionHeight; t.y++)
... ... @@ -259,13 +293,25 @@
screenLocation.origin.x = bounds.origin.x + (t.x - rect.origin.tile.x - rect.origin.offset.x) * pixelsPerTile;
screenLocation.origin.y = bounds.origin.y + (t.y - rect.origin.tile.y - rect.origin.offset.y) * pixelsPerTile;
[self addTile:normalisedTile at:screenLocation];
[tilesToLoad addObject:[RMShuffleContainer containerWithTile:normalisedTile at:screenLocation]];
// [self addTile:normalisedTile at:screenLocation];
}
}
// RMLog(@"%d tiles to load", [tilesToLoad count]);
// Load the tiles from the middle to the outside
for (NSInteger i=[tilesToLoad count]; i>0; --i)
{
NSInteger index = i/2;
RMShuffleContainer *tileToLoad = [tilesToLoad objectAtIndex:index];
[self addTile:tileToLoad.tile at:tileToLoad.screenLocation];
[tilesToLoad removeObjectAtIndex:index];
}
// Performance issue!
break;
// break;
// adjust rect for next zoom level down until we're at minimum
if (--rect.origin.tile.zoom <= minimumZoom)
break;
... ...