PageRenderTime 27ms CodeModel.GetById 10ms app.highlight 14ms RepoModel.GetById 1ms app.codeStats 0ms

/MapView/Map/RMCachedTileSource.m

http://github.com/route-me/route-me
Objective C | 170 lines | 116 code | 25 blank | 29 comment | 4 complexity | 8d7be577edf18af579d31e4ee1154da6 MD5 | raw file
  1//
  2//  RMCachedTileSource.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 "RMCachedTileSource.h"
 29#import "RMTileCache.h"
 30
 31@implementation RMCachedTileSource
 32
 33- (id) initWithSource: (id<RMTileSource>) _source
 34{
 35	if ([_source isKindOfClass:[RMCachedTileSource class]])
 36	{
 37		[self release];
 38		return [_source retain];
 39	}
 40	
 41	if (![super init])
 42		return nil;
 43	
 44	tileSource = [_source retain];
 45	
 46	cache = [[RMTileCache alloc] initWithTileSource:tileSource];
 47	
 48	return self;
 49}
 50
 51- (void) dealloc
 52{
 53	[tileSource release];
 54	[cache release];
 55	[super dealloc];
 56}
 57
 58+ (RMCachedTileSource*) cachedTileSourceWithSource: (id<RMTileSource>) source
 59{
 60	// Doing this fixes a strange build warning...
 61	id theSource = source;
 62	return [[[RMCachedTileSource alloc] initWithSource:theSource] autorelease];
 63}
 64
 65-(RMTileImage *) tileImage: (RMTile) tile
 66{
 67	RMTileImage *cachedImage = [cache cachedImage:tile];
 68	if (cachedImage != nil)
 69	{
 70		return cachedImage;
 71	}
 72	else
 73	{
 74		RMTileImage *image = [tileSource tileImage:tile];
 75		[cache addTile:tile WithImage:image];
 76		return image;
 77	}
 78}
 79
 80-(id<RMMercatorToTileProjection>) mercatorToTileProjection
 81{
 82	return [tileSource mercatorToTileProjection];
 83}
 84
 85-(RMProjection*) projection
 86{
 87	return [tileSource projection];
 88}
 89
 90- (id<RMTileSource>) underlyingTileSource
 91{
 92	// I'm assuming that our tilesource isn't itself a cachedtilesource.
 93	// This class's initialiser should make sure of that.
 94	return tileSource;
 95}
 96
 97-(float) minZoom
 98{
 99	return [tileSource minZoom];
100}
101-(float) maxZoom
102{
103	return [tileSource maxZoom];
104}
105
106-(RMSphericalTrapezium) latitudeLongitudeBoundingBox
107{
108	return [tileSource latitudeLongitudeBoundingBox];
109}
110
111- (void) didReceiveMemoryWarning
112{
113	LogMethod();		
114	[cache didReceiveMemoryWarning];
115	[tileSource didReceiveMemoryWarning];
116}
117
118-(NSString*) uniqueTilecacheKey
119{
120	return [tileSource uniqueTilecacheKey];
121}
122
123-(NSString *)shortName
124{
125	return [tileSource shortName];
126}
127-(NSString *)longDescription
128{
129	return [tileSource longDescription];
130}
131-(NSString *)shortAttribution
132{
133	return [tileSource shortAttribution];
134}
135-(NSString *)longAttribution
136{
137	return [tileSource longAttribution];
138}
139
140-(NSString *) tileURL: (RMTile) tile
141{
142  return [tileSource tileURL:tile];
143}
144
145-(NSString *) tileFile: (RMTile) tile
146{
147  return [tileSource tileFile:tile];
148}
149
150-(NSString *) tilePath
151{
152  return [tileSource tilePath];
153}
154
155-(void) setMinZoom:(NSUInteger)aMinZoom
156{
157        [tileSource setMinZoom:aMinZoom];
158}
159
160-(void) setMaxZoom:(NSUInteger)aMaxZoom
161{
162        [tileSource setMaxZoom:aMaxZoom];
163}
164
165-(void) removeAllCachedImages
166{
167	[cache removeAllCachedImages];
168}
169
170@end