Authored by Joseph G

Added some layers code. Added an overlay and background to RMMapContents.

These have not been tested; but should work.
... ... @@ -72,7 +72,7 @@
{
for (id layer in set)
{
// if ([layer respondsToSelector:@selector(moveBy:)])
if ([layer respondsToSelector:@selector(moveBy:)])
[layer moveBy:delta];
// if layer moves on and offscreen...
... ... @@ -83,7 +83,7 @@
{
for (id layer in set)
{
// if ([layer respondsToSelector:@selector(zoomByFactor:Near:)])
if ([layer respondsToSelector:@selector(zoomByFactor:Near:)])
[layer zoomByFactor:zoomFactor Near:center];
}
}
... ...
... ... @@ -17,6 +17,7 @@
@class RMTileImageSet;
@class RMTileLoader;
@class RMMapRenderer;
@class RMMapLayer;
@protocol RMMercatorToTileProjection;
@protocol RMTileSource;
... ... @@ -59,10 +60,14 @@
@property (readonly) id<RMMercatorToTileProjection> mercatorToTileProjection;
@property (readonly) RMMercatorToScreenProjection *mercatorToScreenProjection;
@property (readonly) id<RMTileSource> tileSource;
@property (retain, readwrite) id<RMTileSource> tileSource;
@property (retain, readwrite) RMMapRenderer *renderer;
@property (readonly) CALayer *layer;
@property (retain, readwrite) RMMapLayer *background;
@property (retain, readwrite) RMMapLayer *overlay;
- (id) initForView: (UIView*) view;
// Designated initialiser
... ...
... ... @@ -22,6 +22,8 @@
#import "RMCoreAnimationRenderer.h"
#import "RMCachedTileSource.h"
#import "RMLayerSet.h"
@implementation RMMapContents
#pragma mark Initialisation
... ... @@ -44,37 +46,6 @@
return mapContents;
}
- (void) setTileSource: (id<RMTileSource>)newTileSource
{
[tileSource release];
tileSource = [newTileSource retain];
[latLongToMercatorProjection release];
latLongToMercatorProjection = [[tileSource latLongToMercatorProjection] retain];
[mercatorToTileProjection release];
mercatorToTileProjection = [[tileSource mercatorToTileProjection] retain];
[imagesOnScreen setTileSource:tileSource];
}
- (void) setRenderer: (RMMapRenderer*) newRenderer
{
if (renderer == newRenderer)
return;
[[renderer layer] removeFromSuperlayer];
[renderer release];
renderer = [newRenderer retain];
// CGRect rect = [self screenBounds];
// NSLog(@"%f %f %f %f", rect.origin.x, rect.origin.y, rect.size.width, rect.size.height);
[[renderer layer] setFrame:[self screenBounds]];
[layer addSublayer:[renderer layer]];
}
- (id) initForView: (UIView*) view WithTileSource: (id<RMTileSource>)_tileSource WithRenderer: (RMMapRenderer*)_renderer LookingAt:(CLLocationCoordinate2D)latlong
{
if (![super init])
... ... @@ -106,6 +77,15 @@
[tileLoader setSuppressLoading:NO];
// TODO: Make a nice background class
RMMapLayer *theBackground = [[RMMapLayer alloc] init];
[self setBackground:theBackground];
[theBackground release];
RMMapLayer *theOverlay = [[RMLayerSet alloc] init];
[self setOverlay:theOverlay];
[theOverlay release];
[view setNeedsDisplay];
NSLog(@"Map contents initialised. view: %@ tileSource %@ renderer %@", view, tileSource, renderer);
... ... @@ -167,6 +147,100 @@
#pragma mark Properties
- (void) setTileSource: (id<RMTileSource>)newTileSource
{
[tileSource release];
tileSource = [newTileSource retain];
[latLongToMercatorProjection release];
latLongToMercatorProjection = [[tileSource latLongToMercatorProjection] retain];
[mercatorToTileProjection release];
mercatorToTileProjection = [[tileSource mercatorToTileProjection] retain];
[imagesOnScreen setTileSource:tileSource];
}
- (id<RMTileSource>) tileSource
{
return [[tileSource retain] autorelease];
}
- (void) setRenderer: (RMMapRenderer*) newRenderer
{
if (renderer == newRenderer)
return;
[[renderer layer] removeFromSuperlayer];
[renderer release];
renderer = [newRenderer retain];
// CGRect rect = [self screenBounds];
// NSLog(@"%f %f %f %f", rect.origin.x, rect.origin.y, rect.size.width, rect.size.height);
[[renderer layer] setFrame:[self screenBounds]];
if (background != nil)
[layer insertSublayer:[renderer layer] above:background];
else if (overlay != nil)
[layer insertSublayer:[renderer layer] below:overlay];
else
[layer addSublayer:[renderer layer]];
}
- (RMMapRenderer *)renderer
{
return [[renderer retain] autorelease];
}
- (void) setBackground: (RMMapLayer*) aLayer
{
if (background != nil)
{
[background release];
[background removeFromSuperlayer];
}
background = [aLayer retain];
background.frame = [self screenBounds];
if ([renderer layer] != nil)
[layer insertSublayer:background below:[renderer layer]];
else if (overlay != nil)
[layer insertSublayer:background below:overlay];
else
[layer addSublayer:background];
}
- (RMMapLayer *)background
{
return [[background retain] autorelease];
}
- (void) setOverlay: (RMMapLayer*) aLayer
{
if (overlay != nil)
{
[overlay release];
[overlay removeFromSuperlayer];
}
overlay = [aLayer retain];
overlay.frame = [self screenBounds];
if ([renderer layer] != nil)
[layer insertSublayer:overlay above:[renderer layer]];
else if (background != nil)
[layer insertSublayer:overlay above:background];
else
[layer addSublayer:overlay];
}
- (RMMapLayer *)overlay
{
return [[overlay retain] autorelease];
}
- (CLLocationCoordinate2D) mapCenter
{
RMMercatorPoint mercCenter = [mercatorToScreenProjection mercatorCenter];
... ... @@ -240,11 +314,6 @@
return [[mercatorToScreenProjection retain] autorelease];
}
-(id<RMTileSource>) tileSource
{
return [[tileSource retain] autorelease];
}
- (CALayer *)layer
{
return [[layer retain] autorelease];
... ...
... ... @@ -17,6 +17,8 @@
self.contents = (id)image;
self.anchorPoint = CGPointMake(0.5, 1.0);
return self;
}
... ...