Authored by Joseph G

Nuked loading image. Fixed a bug whereby moveToLatLong wouldn't remove old tiles…

…. Played with some animation stuff.
This group contains the mapview -specific files and logic.
It replaces the older 'Classes' directory + files.
\ No newline at end of file
It replaces the older 'Classes' directory + files.
For a guide on how to incorporate this map into your own project, please read this:
http://code.google.com/p/route-me/wiki/EmbedingGuide
... ...
... ... @@ -26,6 +26,10 @@
layer.masksToBounds = YES;
layer.frame = [view bounds];
NSMutableDictionary *customActions=[NSMutableDictionary dictionaryWithDictionary:[layer actions]];
[customActions setObject:[NSNull null] forKey:@"sublayers"];
layer.actions = customActions;
layer.delegate = self;
[[view layer] addSublayer:layer];
... ... @@ -40,16 +44,30 @@
- (id<CAAction>)actionForLayer:(CALayer *)theLayer
forKey:(NSString *)key
{
// NSLog(@"key: %@", key);
if (theLayer == layer)
{
// NSLog(@"base layer key: %@", key);
return nil;
}
// if ([key isEqualToString:@"position"] || [key isEqualToString:@"bounds"])
return (id<CAAction>)[NSNull null];
// else
// return nil;
// || [key isEqualToString:@"onLayout"]
if ([key isEqualToString:@"position"]
|| [key isEqualToString:@"bounds"])
return nil;
// return (id<CAAction>)[NSNull null];
else
{
// NSLog(@"key: %@", key);
return nil;
}
}
- (void)tileAdded: (RMTile) tile WithImage: (RMTileImage*) image
{
NSLog(@"tileAdded: %d %d %d at %f %f %f %f", tile.x, tile.y, tile.zoom, image.screenLocation.origin.x, image.screenLocation.origin.y,
image.screenLocation.size.width, image.screenLocation.size.height);
// NSLog(@"tileAdded");
[image makeLayer];
... ... @@ -64,6 +82,9 @@
{
RMTileImage *image = [[content imagesOnScreen] imageWithTile:tile];
NSLog(@"tileRemoved: %d %d %d at %f %f %f %f", tile.x, tile.y, tile.zoom, image.screenLocation.origin.x, image.screenLocation.origin.y,
image.screenLocation.size.width, image.screenLocation.size.height);
[[image layer] removeFromSuperlayer];
}
... ...
... ... @@ -7,12 +7,23 @@
//
#import <Foundation/Foundation.h>
#import <QuartzCore/QuartzCore.h>
@protocol RMMapLayer;
@interface RMLayerSet : NSObject
{
NSMutableArray *layers;
}
- (void)addAbove: (id)layer;
- (void)addBelow: (id)layer;
- (void)moveBy: (CGSize) delta;
- (void)zoomByFactor: (float) zoomFactor Near:(CGPoint) center;
-(void) drawRect: (CGRect)rect;
-(CALayer*) layer;
@end
... ...
... ... @@ -109,7 +109,7 @@
{
[mercatorToScreenProjection setMercatorCenter:mercator];
[imagesOnScreen removeAllTiles];
// [imagesOnScreen removeAllTiles];
[tileLoader clearLoadedBounds];
[tileLoader updateLoadedImages];
... ...
... ... @@ -24,6 +24,9 @@ typedef struct {
@class RMMapContents;
// This class is a wrapper around RMMapContents for the iphone.
// It implements event handling; but thats about it. All the interesting map
// logic is done by RMMapContents.
@interface RMMapView : UIView
{
RMMapContents *contents;
... ... @@ -33,6 +36,10 @@ typedef struct {
RMGestureDetails lastGesture;
}
// Any other functions you need to manipulate the mapyou can access through this
// property. The contents structure holds the actual map bits.
@property (readonly) RMMapContents *contents;
- (void)moveToLatLong: (CLLocationCoordinate2D)latlong;
- (void)moveToMercator: (RMMercatorPoint)mercator;
... ...
... ... @@ -25,6 +25,8 @@
if (enableZoom)
[self setMultipleTouchEnabled:TRUE];
self.backgroundColor = [UIColor grayColor];
// [[NSURLCache sharedURLCache] removeAllCachedResponses];
}
... ... @@ -59,6 +61,11 @@
return [NSString stringWithFormat:@"iPhone MapView at %.0f,%.0f-%.0f,%.0f", bounds.origin.x, bounds.origin.y, bounds.size.width, bounds.size.height];
}
-(RMMapContents*) contents
{
return [[contents retain] autorelease];
}
#pragma mark Movement
-(void) moveToMercator: (RMMercatorPoint) point
... ...
... ... @@ -224,6 +224,23 @@ NSString * const RMMapImageLoadingCancelledNotification = @"MapImageLoadingCance
layer.anchorPoint = CGPointMake(0.0f, 0.0f);
layer.bounds = CGRectMake(0, 0, screenLocation.size.width, screenLocation.size.height);
layer.position = screenLocation.origin;
NSMutableDictionary *customActions=[NSMutableDictionary dictionaryWithDictionary:[layer actions]];
[customActions setObject:[NSNull null] forKey:@"position"];
[customActions setObject:[NSNull null] forKey:@"bounds"];
[customActions setObject:[NSNull null] forKey:kCAOnOrderOut];
/* CATransition *fadein = [[CATransition alloc] init];
fadein.duration = 2.0;
fadein.type = kCATransitionFade;
[customActions setObject:fadein forKey:kCAOnOrderIn];
[fadein release];
*/
[customActions setObject:[NSNull null] forKey:kCAOnOrderIn];
layer.actions=customActions;
// NSLog(@"location %f %f", screenLocation.origin.x, screenLocation.origin.y);
// NSLog(@"layer made");
... ...
... ... @@ -55,13 +55,14 @@ NSString* const RMResumeExpensiveOperations = @"RMResumeExpensiveOperations";
-(void) clearLoadedBounds
{
loadedBounds = CGRectMake(0, 0, 0, 0);
loadedTiles.origin.tile = RMTileDummy();
// loadedTiles.origin.tile = RMTileDummy();
}
-(BOOL) screenIsLoaded
{
// RMTileRect targetRect = [content tileBounds];
BOOL contained = CGRectContainsRect(loadedBounds, [content screenBounds]);
float targetZoom = [[content mercatorToTileProjection] calculateNormalisedZoomFromScale:[content scale]];
int targetZoom = (int)([[content mercatorToTileProjection] calculateNormalisedZoomFromScale:[content scale]]);
if (contained == NO)
{
... ... @@ -84,7 +85,7 @@ NSString* const RMResumeExpensiveOperations = @"RMResumeExpensiveOperations";
if ([self screenIsLoaded])
return;
// NSLog(@"assemble count = %d", [[content imagesOnScreen] count]);
NSLog(@"assemble count = %d", [[content imagesOnScreen] count]);
RMTileRect newTileRect = [content tileBounds];
... ...
... ... @@ -12,7 +12,7 @@
@interface RMWebTileImage : RMTileImage {
// Before image is completely loaded a proxy image can be used.
// This will typically be a boilerplate image or a zoomed in or zoomed out version of another image.
RMTileImage *proxy;
// RMTileImage *proxy;
NSURLConnection *connection;
// Data accumulator during loading.
... ...
... ... @@ -25,8 +25,8 @@
NSURLRequest *request = [NSURLRequest requestWithURL:url];
NSCachedURLResponse *cachedData = [[NSURLCache sharedURLCache] cachedResponseForRequest:request];
proxy = [RMTileProxy loadingTile];
[proxy retain];
// proxy = [RMTileProxy loadingTile];
// [proxy retain];
// NSURLCache *cache = [NSURLCache sharedURLCache];
// NSLog(@"Cache mem size: %d / %d disk size: %d / %d", [cache currentMemoryUsage], [cache memoryCapacity], [cache currentDiskUsage], [cache diskCapacity]);
... ... @@ -44,8 +44,8 @@
if (connection == nil)
{
NSLog(@"Error: Connection is nil ?!?");
proxy = [RMTileProxy errorTile];
[proxy retain];
// proxy = [RMTileProxy errorTile];
// [proxy retain];
}
if (startImmediately == NO)
... ... @@ -76,7 +76,7 @@
[[NSNotificationCenter defaultCenter] removeObserver:self];
// NSLog(@"Image dealloced");
[proxy release];
// [proxy release];
// NSLog(@"loading cancelled because image dealloced");
[self cancelLoading];
... ... @@ -105,21 +105,20 @@
{
[super makeLayer];
if (image == nil
&& layer != nil
&& layer.contents == nil)
{
layer.contents = (id)[[proxy image] CGImage];
}
// if (image == nil
// && layer != nil
// && layer.contents == nil)
// {
// layer.contents = (id)[[proxy image] CGImage];
// }
}
- (void)drawInRect:(CGRect)rect
{
if (image)
[super drawInRect:rect];
else
[proxy drawInRect:rect];
}
#pragma mark URL loading functions
// Delegate methods for loading the image
//– connection:didCancelAuthenticationChallenge: delegate method
... ... @@ -153,7 +152,7 @@
- (void)connection:(NSURLConnection *)_connection didFailWithError:(NSError *)error
{
proxy = [RMTileProxy errorTile];
// proxy = [RMTileProxy errorTile];
[data release];
data = nil;
NSLog(@"Tile could not be loaded: %@", [error localizedDescription]);
... ...