PageRenderTime 16ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/MapView/Map/RMMapContents.h

http://github.com/route-me/route-me
C Header | 283 lines | 147 code | 58 blank | 78 comment | 0 complexity | c9307c2ad3b4f1f3e068b2f20ad71cf8 MD5 | raw file
  1. //
  2. // RMMapContents.h
  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 <UIKit/UIKit.h>
  28. #import "RMFoundation.h"
  29. #import "RMLatLong.h"
  30. #import "RMTile.h"
  31. #import "RMTilesUpdateDelegate.h"
  32. // constants for boundingMask
  33. enum {
  34. // Map can be zoomed out past view limits
  35. RMMapNoMinBound = 0,
  36. // Minimum map height when zooming out restricted to view height
  37. RMMapMinHeightBound = 1,
  38. // Minimum map width when zooming out restricted to view width ( default )
  39. RMMapMinWidthBound = 2
  40. };
  41. #define kDefaultInitialLatitude -33.858771
  42. #define kDefaultInitialLongitude 151.201596
  43. #define kDefaultMinimumZoomLevel 0.0
  44. #define kDefaultMaximumZoomLevel 25.0
  45. #define kDefaultInitialZoomLevel 13.0
  46. @class RMMarkerManager;
  47. @class RMProjection;
  48. @class RMMercatorToScreenProjection;
  49. @class RMTileImageSet;
  50. @class RMTileLoader;
  51. @class RMMapRenderer;
  52. @class RMMapLayer;
  53. @class RMLayerCollection;
  54. @class RMMarker;
  55. @protocol RMMercatorToTileProjection;
  56. @protocol RMTileSource;
  57. @protocol RMMapContentsAnimationCallback <NSObject>
  58. @optional
  59. - (void)animationFinishedWithZoomFactor:(float)zoomFactor near:(CGPoint)p;
  60. - (void)animationStepped;
  61. @end
  62. /*! \brief The cartographic and data components of a map. Do not retain.
  63. There is exactly one RMMapContents instance for each RMMapView instance.
  64. \warning Do not retain an RMMapContents instance. Instead, ask the RMMapView for its contents
  65. when you need it. It is an error for an RMMapContents instance to exist without a view, and
  66. if you retain the RMMapContents, it can't go away when the RMMapView is released.
  67. At some point, it's likely that RMMapContents and RMMapView will be merged into one class.
  68. */
  69. @interface RMMapContents : NSObject
  70. {
  71. /// This is the underlying UIView's layer.
  72. CALayer *layer;
  73. RMMarkerManager *markerManager;
  74. /// subview for the image displayed while tiles are loading. Set its contents by providing your own "loading.png".
  75. RMMapLayer *background;
  76. /// subview for markers and paths
  77. RMLayerCollection *overlay;
  78. /// (guess) the projection object to convert from latitude/longitude to meters.
  79. /// Latlong is calculated dynamically from mercatorBounds.
  80. RMProjection *projection;
  81. id<RMMercatorToTileProjection> mercatorToTileProjection;
  82. // RMTileRect tileBounds;
  83. /// (guess) converts from projected meters to screen pixel coordinates
  84. RMMercatorToScreenProjection *mercatorToScreenProjection;
  85. /// controls what images are used. Can be changed while the view is visible, but see http://code.google.com/p/route-me/issues/detail?id=12
  86. id<RMTileSource> tileSource;
  87. RMTileImageSet *imagesOnScreen;
  88. RMTileLoader *tileLoader;
  89. RMMapRenderer *renderer;
  90. NSUInteger boundingMask;
  91. /// minimum zoom number allowed for the view. #minZoom and #maxZoom must be within the limits of #tileSource but can be stricter; they are clamped to tilesource limits if needed.
  92. float minZoom;
  93. /// maximum zoom number allowed for the view. #minZoom and #maxZoom must be within the limits of #tileSource but can be stricter; they are clamped to tilesource limits if needed.
  94. float maxZoom;
  95. float screenScale;
  96. id<RMTilesUpdateDelegate> tilesUpdateDelegate;
  97. }
  98. @property (readwrite) CLLocationCoordinate2D mapCenter;
  99. @property (readwrite) RMProjectedPoint centerProjectedPoint;
  100. @property (readwrite) RMProjectedRect projectedBounds;
  101. @property (readonly) RMTileRect tileBounds;
  102. @property (readonly) CGRect screenBounds;
  103. @property (readwrite) float metersPerPixel;
  104. @property (readonly) float scaledMetersPerPixel;
  105. /// zoom level is clamped to range (minZoom, maxZoom)
  106. @property (readwrite) float zoom;
  107. @property (nonatomic, readwrite) float minZoom, maxZoom;
  108. @property (nonatomic, readonly) float screenScale;
  109. @property (readonly) RMTileImageSet *imagesOnScreen;
  110. @property (readonly) RMTileLoader *tileLoader;
  111. @property (readonly) RMProjection *projection;
  112. @property (readonly) id<RMMercatorToTileProjection> mercatorToTileProjection;
  113. @property (readonly) RMMercatorToScreenProjection *mercatorToScreenProjection;
  114. @property (retain, readwrite) id<RMTileSource> tileSource;
  115. @property (retain, readwrite) RMMapRenderer *renderer;
  116. @property (readonly) CALayer *layer;
  117. @property (retain, readwrite) RMMapLayer *background;
  118. @property (retain, readwrite) RMLayerCollection *overlay;
  119. @property (retain, readonly) RMMarkerManager *markerManager;
  120. /// \bug probably shouldn't be retaining this delegate
  121. @property (nonatomic, retain) id<RMTilesUpdateDelegate> tilesUpdateDelegate;
  122. @property (readwrite) NSUInteger boundingMask;
  123. /// The denominator in a cartographic scale like 1/24000, 1/50000, 1/2000000.
  124. @property (readonly)double scaleDenominator;
  125. // tileDepth defaults to zero. if tiles have no alpha, set this higher, 3 or so, to make zooming smoother
  126. @property (readwrite, assign) short tileDepth;
  127. @property (readonly, assign) BOOL fullyLoaded;
  128. - (id)initWithView: (UIView*) view;
  129. - (id)initWithView: (UIView*) view screenScale:(float)theScreenScale;
  130. - (id)initWithView: (UIView*) view tilesource:(id<RMTileSource>)newTilesource;
  131. - (id)initWithView: (UIView*) view tilesource:(id<RMTileSource>)newTilesource screenScale:(float)theScreenScale;
  132. /// designated initializer
  133. - (id)initWithView:(UIView*)view
  134. tilesource:(id<RMTileSource>)tilesource
  135. centerLatLon:(CLLocationCoordinate2D)initialCenter
  136. zoomLevel:(float)initialZoomLevel
  137. maxZoomLevel:(float)maxZoomLevel
  138. minZoomLevel:(float)minZoomLevel
  139. backgroundImage:(UIImage *)backgroundImage
  140. screenScale:(float)theScreenScale;
  141. /// \deprecated subject to removal at any moment after 0.5 is released
  142. - (id) initForView: (UIView*) view;
  143. /// \deprecated subject to removal at any moment after 0.5 is released
  144. - (id) initForView: (UIView*) view WithLocation:(CLLocationCoordinate2D)latlong;
  145. /// \deprecated subject to removal at any moment after 0.5 is released
  146. - (id)initForView:(UIView*)view WithTileSource:(id<RMTileSource>)tileSource WithRenderer:(RMMapRenderer*)renderer LookingAt:(CLLocationCoordinate2D)latlong;
  147. - (void)setFrame:(CGRect)frame;
  148. - (void)handleMemoryWarningNotification:(NSNotification *)notification;
  149. - (void)didReceiveMemoryWarning;
  150. - (void)moveToLatLong: (CLLocationCoordinate2D)latlong;
  151. /// \deprecate Use setCenterProjectedPoint: instead.
  152. - (void)moveToProjectedPoint: (RMProjectedPoint)aPoint;
  153. - (void)moveBy: (CGSize) delta;
  154. - (void)zoomByFactor: (float) zoomFactor near:(CGPoint) center;
  155. - (void)zoomInToNextNativeZoomAt:(CGPoint) pivot animated:(BOOL) animated;
  156. - (void)zoomOutToNextNativeZoomAt:(CGPoint) pivot animated:(BOOL) animated;
  157. - (void)zoomByFactor: (float) zoomFactor near:(CGPoint) center animated:(BOOL) animated;
  158. - (void)zoomByFactor: (float) zoomFactor near:(CGPoint) center animated:(BOOL) animated withCallback:(id<RMMapContentsAnimationCallback>)callback;
  159. - (void)zoomInToNextNativeZoomAt:(CGPoint) pivot;
  160. - (void)zoomOutToNextNativeZoomAt:(CGPoint) pivot;
  161. - (float)adjustZoomForBoundingMask:(float)zoomFactor;
  162. - (void)adjustMapPlacementWithScale:(float)aScale;
  163. - (float)nextNativeZoomFactor;
  164. - (float)prevNativeZoomFactor;
  165. - (void) drawRect: (CGRect) rect;
  166. //-(void)addLayer: (id<RMMapLayer>) layer above: (id<RMMapLayer>) other;
  167. //-(void)addLayer: (id<RMMapLayer>) layer below: (id<RMMapLayer>) other;
  168. //-(void)removeLayer: (id<RMMapLayer>) layer;
  169. // During touch and move operations on the iphone its good practice to
  170. // hold off on any particularly expensive operations so the user's
  171. + (BOOL) performExpensiveOperations;
  172. + (void) setPerformExpensiveOperations: (BOOL)p;
  173. - (CGPoint)latLongToPixel:(CLLocationCoordinate2D)latlong;
  174. - (CGPoint)latLongToPixel:(CLLocationCoordinate2D)latlong withMetersPerPixel:(float)aScale;
  175. - (RMTilePoint)latLongToTilePoint:(CLLocationCoordinate2D)latlong withMetersPerPixel:(float)aScale;
  176. - (CLLocationCoordinate2D)pixelToLatLong:(CGPoint)aPixel;
  177. - (CLLocationCoordinate2D)pixelToLatLong:(CGPoint)aPixel withMetersPerPixel:(float)aScale;
  178. - (void)zoomWithLatLngBoundsNorthEast:(CLLocationCoordinate2D)ne SouthWest:(CLLocationCoordinate2D)se;
  179. - (void)zoomWithRMMercatorRectBounds:(RMProjectedRect)bounds;
  180. /// returns the smallest bounding box containing the entire screen
  181. - (RMSphericalTrapezium) latitudeLongitudeBoundingBoxForScreen;
  182. /// returns the smallest bounding box containing a rectangular region of the screen
  183. - (RMSphericalTrapezium) latitudeLongitudeBoundingBoxFor:(CGRect) rect;
  184. - (void)setRotation:(float)angle;
  185. - (void) tilesUpdatedRegion:(CGRect)region;
  186. /*! \brief Clear all images from the #tileSource's caching system.
  187. All of the existing RMTileSource implementations load tile images via NSURLRequest. It's possible that some images will remain in your
  188. application's shared URL cache. If you need to clear this out too, use this call:
  189. \code
  190. [[NSURLCache sharedURLCache] removeAllCachedResponses];
  191. \endcode
  192. */
  193. -(void)removeAllCachedImages;
  194. @end
  195. /// Appears to be the methods actually implemented by RMMapContents, but generally invoked on RMMapView, and forwarded to the contents object.
  196. @protocol RMMapContentsFacade
  197. @optional
  198. - (void)moveToLatLong: (CLLocationCoordinate2D)latlong;
  199. - (void)moveToProjectedPoint: (RMProjectedPoint)aPoint;
  200. - (void)moveBy: (CGSize) delta;
  201. - (void)zoomByFactor: (float) zoomFactor near:(CGPoint) center;
  202. - (void)zoomInToNextNativeZoomAt:(CGPoint) pivot animated:(BOOL) animated;
  203. - (void)zoomOutToNextNativeZoomAt:(CGPoint) pivot animated:(BOOL) animated;
  204. - (void)zoomByFactor: (float) zoomFactor near:(CGPoint) center animated:(BOOL) animated;
  205. - (void)zoomInToNextNativeZoomAt:(CGPoint) pivot;
  206. - (void)zoomOutToNextNativeZoomAt:(CGPoint) pivot;
  207. - (float)adjustZoomForBoundingMask:(float)zoomFactor;
  208. - (void)adjustMapPlacementWithScale:(float)aScale;
  209. - (CGPoint)latLongToPixel:(CLLocationCoordinate2D)latlong;
  210. - (CGPoint)latLongToPixel:(CLLocationCoordinate2D)latlong withMetersPerPixel:(float)aScale;
  211. - (CLLocationCoordinate2D)pixelToLatLong:(CGPoint)aPixel;
  212. - (CLLocationCoordinate2D)pixelToLatLong:(CGPoint)aPixel withMetersPerPixel:(float)aScale;
  213. - (void)zoomWithLatLngBoundsNorthEast:(CLLocationCoordinate2D)ne SouthWest:(CLLocationCoordinate2D)se;
  214. - (void)zoomWithRMMercatorRectBounds:(RMProjectedRect)bounds;
  215. /// \deprecated name change pending after 0.5
  216. - (RMSphericalTrapezium) latitudeLongitudeBoundingBoxForScreen;
  217. /// \deprecated name change pending after 0.5
  218. - (RMSphericalTrapezium) latitudeLongitudeBoundingBoxFor:(CGRect) rect;
  219. - (void) tilesUpdatedRegion:(CGRect)region;
  220. @end