/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. #import "RMAbstractMercatorWebSource.h"
  28. #import "RMTransform.h"
  29. #import "RMTileImage.h"
  30. #import "RMTileLoader.h"
  31. #import "RMFractalTileProjection.h"
  32. #import "RMTiledLayerController.h"
  33. #import "RMProjection.h"
  34. @implementation RMAbstractMercatorWebSource
  35. -(id) init
  36. {
  37. if (![super init])
  38. return nil;
  39. tileProjection = [[RMFractalTileProjection alloc] initFromProjection:[self projection] tileSideLength:kDefaultTileSize maxZoom:kDefaultMaxTileZoom minZoom:kDefaultMinTileZoom];
  40. networkOperations = TRUE;
  41. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(networkOperationsNotification:) name:RMSuspendNetworkOperations object:nil];
  42. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(networkOperationsNotification:) name:RMResumeNetworkOperations object:nil];
  43. return self;
  44. }
  45. - (void) networkOperationsNotification: (NSNotification*) notification
  46. {
  47. if(notification.name == RMSuspendNetworkOperations)
  48. networkOperations = FALSE;
  49. else if(notification.name == RMResumeNetworkOperations)
  50. networkOperations = TRUE;
  51. }
  52. -(void) dealloc
  53. {
  54. [[NSNotificationCenter defaultCenter] removeObserver:self name:RMSuspendNetworkOperations object:nil];
  55. [[NSNotificationCenter defaultCenter] removeObserver:self name:RMResumeNetworkOperations object:nil];
  56. [tileProjection release];
  57. [super dealloc];
  58. }
  59. -(int)tileSideLength
  60. {
  61. return tileProjection.tileSideLength;
  62. }
  63. - (void) setTileSideLength: (NSUInteger) aTileSideLength
  64. {
  65. [tileProjection setTileSideLength:aTileSideLength];
  66. }
  67. -(float) minZoom
  68. {
  69. return (float)tileProjection.minZoom;
  70. }
  71. -(float) maxZoom
  72. {
  73. return (float)tileProjection.maxZoom;
  74. }
  75. -(void) setMinZoom:(NSUInteger)aMinZoom
  76. {
  77. [tileProjection setMinZoom:aMinZoom];
  78. }
  79. -(void) setMaxZoom:(NSUInteger)aMaxZoom
  80. {
  81. [tileProjection setMaxZoom:aMaxZoom];
  82. }
  83. -(RMSphericalTrapezium) latitudeLongitudeBoundingBox;
  84. {
  85. return kDefaultLatLonBoundingBox;
  86. }
  87. /// \bug magic string literals
  88. -(NSString*) tileURL: (RMTile) tile
  89. {
  90. @throw [NSException exceptionWithName:@"RMAbstractMethodInvocation" reason:@"tileURL invoked on AbstractMercatorWebSource. Override this method when instantiating abstract class." userInfo:nil];
  91. }
  92. -(NSString*) tileFile: (RMTile) tile
  93. {
  94. return nil;
  95. }
  96. -(NSString*) tilePath
  97. {
  98. return nil;
  99. }
  100. -(RMTileImage *)tileImage:(RMTile)tile
  101. {
  102. RMTileImage *image;
  103. tile = [tileProjection normaliseTile:tile];
  104. NSString *file = [self tileFile:tile];
  105. if(file && [[NSFileManager defaultManager] fileExistsAtPath:file])
  106. {
  107. image = [RMTileImage imageForTile:tile fromFile:file];
  108. }
  109. else if(networkOperations)
  110. {
  111. image = [RMTileImage imageForTile:tile withURL:[self tileURL:tile]];
  112. }
  113. else
  114. {
  115. image = [RMTileImage dummyTile:tile];
  116. }
  117. return image;
  118. }
  119. -(id<RMMercatorToTileProjection>) mercatorToTileProjection
  120. {
  121. return [[tileProjection retain] autorelease];
  122. }
  123. -(RMProjection*) projection
  124. {
  125. return [RMProjection googleProjection];
  126. }
  127. -(void) didReceiveMemoryWarning
  128. {
  129. LogMethod();
  130. }
  131. -(NSString *)uniqueTilecacheKey
  132. {
  133. @throw [NSException exceptionWithName:@"RMAbstractMethodInvocation" reason:@"uniqueTilecacheKey invoked on AbstractMercatorWebSource. Override this method when instantiating abstract class." userInfo:nil];
  134. }
  135. -(NSString *)shortName
  136. {
  137. @throw [NSException exceptionWithName:@"RMAbstractMethodInvocation" reason:@"shortName invoked on AbstractMercatorWebSource. Override this method when instantiating abstract class." userInfo:nil];
  138. }
  139. -(NSString *)longDescription
  140. {
  141. return [self shortName];
  142. }
  143. -(NSString *)shortAttribution
  144. {
  145. @throw [NSException exceptionWithName:@"RMAbstractMethodInvocation" reason:@"shortAttribution invoked on AbstractMercatorWebSource. Override this method when instantiating abstract class." userInfo:nil];
  146. }
  147. -(NSString *)longAttribution
  148. {
  149. return [self shortAttribution];
  150. }
  151. -(void) removeAllCachedImages
  152. {
  153. }
  154. @end