PageRenderTime 51ms CodeModel.GetById 30ms app.highlight 17ms RepoModel.GetById 1ms app.codeStats 0ms

/MapView/Map/RMAbstractMercatorWebSource.m

http://github.com/route-me/route-me
Objective C | 185 lines | 127 code | 31 blank | 27 comment | 10 complexity | d52e039b83cebf30f592fc48c5d6eacc MD5 | raw file
  1//
  2//  RMMercatorWebSource.m
  3//
  4// Copyright (c) 2008-2009, Route-Me Contributors
  5// All rights reserved.
  6//
  7// Redistribution and use in source and binary forms, with or without
  8// modification, are permitted provided that the following conditions are met:
  9//
 10// * Redistributions of source code must retain the above copyright notice, this
 11//   list of conditions and the following disclaimer.
 12// * Redistributions in binary form must reproduce the above copyright notice,
 13//   this list of conditions and the following disclaimer in the documentation
 14//   and/or other materials provided with the distribution.
 15//
 16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 17// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 18// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 19// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 20// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 21// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 22// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 23// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 24// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 25// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 26// POSSIBILITY OF SUCH DAMAGE.
 27
 28#import "RMAbstractMercatorWebSource.h"
 29#import "RMTransform.h"
 30#import "RMTileImage.h"
 31#import "RMTileLoader.h"
 32#import "RMFractalTileProjection.h"
 33#import "RMTiledLayerController.h"
 34#import "RMProjection.h"
 35
 36@implementation RMAbstractMercatorWebSource
 37
 38-(id) init
 39{
 40	if (![super init])
 41		return nil;
 42	
 43	tileProjection = [[RMFractalTileProjection alloc] initFromProjection:[self projection] tileSideLength:kDefaultTileSize maxZoom:kDefaultMaxTileZoom minZoom:kDefaultMinTileZoom];
 44	
 45	networkOperations = TRUE;
 46	
 47	[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(networkOperationsNotification:) name:RMSuspendNetworkOperations object:nil];
 48	[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(networkOperationsNotification:) name:RMResumeNetworkOperations object:nil];
 49	
 50	return self;
 51}
 52
 53- (void) networkOperationsNotification: (NSNotification*) notification
 54{	
 55	if(notification.name == RMSuspendNetworkOperations)
 56		networkOperations = FALSE;
 57	else if(notification.name == RMResumeNetworkOperations)
 58		networkOperations = TRUE;
 59}
 60
 61-(void) dealloc
 62{
 63	[[NSNotificationCenter defaultCenter] removeObserver:self name:RMSuspendNetworkOperations object:nil];
 64	[[NSNotificationCenter defaultCenter] removeObserver:self name:RMResumeNetworkOperations object:nil];
 65	[tileProjection release];
 66	[super dealloc];
 67}
 68
 69-(int)tileSideLength
 70{
 71	return tileProjection.tileSideLength;
 72}
 73
 74- (void) setTileSideLength: (NSUInteger) aTileSideLength
 75{
 76	[tileProjection setTileSideLength:aTileSideLength];
 77}
 78
 79-(float) minZoom
 80{
 81	return (float)tileProjection.minZoom;
 82}
 83
 84-(float) maxZoom
 85{
 86	return (float)tileProjection.maxZoom;
 87}
 88
 89-(void) setMinZoom:(NSUInteger)aMinZoom
 90{
 91	[tileProjection setMinZoom:aMinZoom];
 92}
 93
 94-(void) setMaxZoom:(NSUInteger)aMaxZoom
 95{
 96	[tileProjection setMaxZoom:aMaxZoom];
 97}
 98
 99-(RMSphericalTrapezium) latitudeLongitudeBoundingBox;
100{
101	return kDefaultLatLonBoundingBox;
102}
103
104/// \bug magic string literals
105-(NSString*) tileURL: (RMTile) tile
106{
107	@throw [NSException exceptionWithName:@"RMAbstractMethodInvocation" reason:@"tileURL invoked on AbstractMercatorWebSource. Override this method when instantiating abstract class." userInfo:nil];
108}
109
110-(NSString*) tileFile: (RMTile) tile
111{
112	return nil;
113}
114
115-(NSString*) tilePath
116{
117	return nil;
118}
119
120-(RMTileImage *)tileImage:(RMTile)tile
121{
122	RMTileImage *image;
123	
124	tile = [tileProjection normaliseTile:tile];
125	
126	NSString *file = [self tileFile:tile];
127	
128	if(file && [[NSFileManager defaultManager] fileExistsAtPath:file])
129	{
130		image = [RMTileImage imageForTile:tile fromFile:file];
131	}
132	else if(networkOperations) 
133	{
134		image = [RMTileImage imageForTile:tile withURL:[self tileURL:tile]];     
135	}
136	else
137	{
138		image = [RMTileImage dummyTile:tile];
139	}
140	
141	return image;
142}
143
144-(id<RMMercatorToTileProjection>) mercatorToTileProjection
145{
146	return [[tileProjection retain] autorelease];
147}
148
149-(RMProjection*) projection
150{
151	return [RMProjection googleProjection];
152}
153
154-(void) didReceiveMemoryWarning
155{
156	LogMethod();		
157}
158
159-(NSString *)uniqueTilecacheKey
160{
161	@throw [NSException exceptionWithName:@"RMAbstractMethodInvocation" reason:@"uniqueTilecacheKey invoked on AbstractMercatorWebSource. Override this method when instantiating abstract class." userInfo:nil];
162}
163
164-(NSString *)shortName
165{
166	@throw [NSException exceptionWithName:@"RMAbstractMethodInvocation" reason:@"shortName invoked on AbstractMercatorWebSource. Override this method when instantiating abstract class." userInfo:nil];
167}
168-(NSString *)longDescription
169{
170	return [self shortName];
171}
172-(NSString *)shortAttribution
173{
174	@throw [NSException exceptionWithName:@"RMAbstractMethodInvocation" reason:@"shortAttribution invoked on AbstractMercatorWebSource. Override this method when instantiating abstract class." userInfo:nil];
175}
176-(NSString *)longAttribution
177{
178	return [self shortAttribution];
179}
180
181-(void) removeAllCachedImages
182{
183}
184@end
185