Authored by Thomas Rasch

o Refactoring: Code cleanup

... ... @@ -110,7 +110,10 @@
- (void)addTile:(RMTile)tile withImage:(RMTileImage *)image
{
// The tile probably hasn't loaded any data yet... we must be patient.
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(addImageData:) name:RMMapImageLoadedNotification object:image];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(addImageData:)
name:RMMapImageLoadedNotification
object:image];
}
- (void)addImageData:(NSNotification *)notification
... ...
... ... @@ -24,6 +24,7 @@
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
#import <UIKit/UIKit.h>
#import "RMFoundation.h"
... ... @@ -31,7 +32,6 @@
#import "RMTilesUpdateDelegate.h"
// constants for boundingMask
enum {
// Map can be zoomed out past view limits
... ... @@ -64,7 +64,9 @@ enum {
@protocol RMMapContentsAnimationCallback <NSObject>
@optional
- (void)animationFinishedWithZoomFactor:(float)zoomFactor near:(CGPoint)p;
@end
... ... @@ -94,20 +96,19 @@ enum {
/// Latlong is calculated dynamically from mercatorBounds.
RMProjection *projection;
id<RMMercatorToTileProjection> mercatorToTileProjection;
// RMTileRect tileBounds;
id <RMMercatorToTileProjection> mercatorToTileProjection;
/// (guess) converts from projected meters to screen pixel coordinates
RMMercatorToScreenProjection *mercatorToScreenProjection;
/// 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
id<RMTileSource> tileSource;
id <RMTileSource> tileSource;
RMTileImageSet *imagesOnScreen;
RMTileLoader *tileLoader;
RMMapRenderer *renderer;
NSUInteger boundingMask;
NSUInteger boundingMask;
/// 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.
float minZoom;
... ... @@ -171,13 +172,6 @@ enum {
minZoomLevel:(float)minZoomLevel
backgroundImage:(UIImage *)backgroundImage;
/// \deprecated subject to removal at any moment after 0.5 is released
- (id) initForView: (UIView*) view;
/// \deprecated subject to removal at any moment after 0.5 is released
- (id) initForView: (UIView*) view WithLocation:(CLLocationCoordinate2D)latlong;
/// \deprecated subject to removal at any moment after 0.5 is released
- (id)initForView:(UIView*)view WithTileSource:(id<RMTileSource>)tileSource WithRenderer:(RMMapRenderer*)renderer LookingAt:(CLLocationCoordinate2D)latlong;
- (void)setFrame:(CGRect)frame;
- (void)handleMemoryWarningNotification:(NSNotification *)notification;
... ... @@ -198,16 +192,11 @@ enum {
- (void)zoomInToNextNativeZoomAt:(CGPoint) pivot;
- (void)zoomOutToNextNativeZoomAt:(CGPoint) pivot;
- (float)adjustZoomForBoundingMask:(float)zoomFactor;
- (void)adjustMapPlacementWithScale:(float)aScale;
- (float)nextNativeZoomFactor;
- (float)prevNativeZoomFactor;
- (void) drawRect: (CGRect) rect;
//-(void)addLayer: (id<RMMapLayer>) layer above: (id<RMMapLayer>) other;
//-(void)addLayer: (id<RMMapLayer>) layer below: (id<RMMapLayer>) other;
//-(void)removeLayer: (id<RMMapLayer>) layer;
- (CGPoint)latLongToPixel:(CLLocationCoordinate2D)latlong;
- (CGPoint)latLongToPixel:(CLLocationCoordinate2D)latlong withMetersPerPixel:(float)aScale;
- (RMTilePoint)latLongToTilePoint:(CLLocationCoordinate2D)latlong withMetersPerPixel:(float)aScale;
... ... @@ -255,7 +244,6 @@ enum {
- (void)zoomInToNextNativeZoomAt:(CGPoint) pivot;
- (void)zoomOutToNextNativeZoomAt:(CGPoint) pivot;
- (float)adjustZoomForBoundingMask:(float)zoomFactor;
- (void)adjustMapPlacementWithScale:(float)aScale;
- (CGPoint)latLongToPixel:(CLLocationCoordinate2D)latlong;
- (CGPoint)latLongToPixel:(CLLocationCoordinate2D)latlong withMetersPerPixel:(float)aScale;
... ... @@ -265,11 +253,6 @@ enum {
- (void)zoomWithLatLngBoundsNorthEast:(CLLocationCoordinate2D)ne SouthWest:(CLLocationCoordinate2D)se;
- (void)zoomWithRMMercatorRectBounds:(RMProjectedRect)bounds;
/// \deprecated name change pending after 0.5
- (RMSphericalTrapezium) latitudeLongitudeBoundingBoxForScreen;
/// \deprecated name change pending after 0.5
- (RMSphericalTrapezium) latitudeLongitudeBoundingBoxFor:(CGRect) rect;
- (void) tilesUpdatedRegion:(CGRect)region;
... ...
... ... @@ -24,6 +24,7 @@
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
#import "RMGlobalConstants.h"
#import "RMMapContents.h"
... ... @@ -47,8 +48,6 @@
#import "RMMarker.h"
@interface RMMapContents (PrivateMethods)
- (void)animatedZoomStep:(NSTimer *)timer;
@end
... ... @@ -181,93 +180,6 @@
return self;
}
/// deprecated at any moment after release 0.5
- (id) initForView: (UIView*) view
{
WarnDeprecated();
return [self initWithView:view];
}
/// deprecated at any moment after release 0.5
- (id) initForView: (UIView*) view WithLocation:(CLLocationCoordinate2D)latlong
{
WarnDeprecated();
LogMethod();
id<RMTileSource> _tileSource = nil;
RMMapRenderer *_renderer = [[RMCoreAnimationRenderer alloc] initWithContent:self];
id mapContents = [self initForView:view WithTileSource:_tileSource WithRenderer:_renderer LookingAt:latlong];
[_tileSource release];
[_renderer release];
return mapContents;
}
/// deprecated at any moment after release 0.5
- (id) initForView: (UIView*) view WithTileSource: (id<RMTileSource>)_tileSource WithRenderer: (RMMapRenderer*)_renderer LookingAt:(CLLocationCoordinate2D)latlong
{
WarnDeprecated();
LogMethod();
if (![super init])
return nil;
NSAssert1([view isKindOfClass:[RMMapView class]], @"view %@ must be a subclass of RMMapView", view);
self.boundingMask = RMMapMinWidthBound;
// targetView = view;
mercatorToScreenProjection = [[RMMercatorToScreenProjection alloc] initFromProjection:[_tileSource projection] toScreenBounds:[view bounds]];
tileSource = nil;
projection = nil;
mercatorToTileProjection = nil;
renderer = nil;
imagesOnScreen = nil;
tileLoader = nil;
layer = [[view layer] retain];
[self setTileSource:_tileSource];
[self setRenderer:_renderer];
imagesOnScreen = [[RMTileImageSet alloc] initWithDelegate:renderer];
[imagesOnScreen setTileSource:tileSource];
tileLoader = [[RMTileLoader alloc] initWithContent:self];
[tileLoader setSuppressLoading:YES];
[self setMinZoom:kDefaultMinimumZoomLevel];
[self setMaxZoom:kDefaultMaximumZoomLevel];
[self setZoom:kDefaultInitialZoomLevel];
[self moveToLatLong:latlong];
[tileLoader setSuppressLoading:NO];
/// \bug TODO: Make a nice background class
RMMapLayer *theBackground = [[RMMapLayer alloc] init];
[self setBackground:theBackground];
[theBackground release];
RMLayerCollection *theOverlay = [[RMLayerCollection alloc] initForContents:self];
[self setOverlay:theOverlay];
[theOverlay release];
markerManager = [[RMMarkerManager alloc] initWithContents:self];
[view setNeedsDisplay];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleMemoryWarningNotification:)
name:UIApplicationDidReceiveMemoryWarningNotification
object:nil];
RMLog(@"Map contents initialised. view: %@ tileSource %@ renderer %@", view, tileSource, renderer);
return self;
}
- (void)setFrame:(CGRect)frame
{
CGRect bounds = CGRectMake(0, 0, frame.size.width, frame.size.height);
... ... @@ -479,40 +391,8 @@
}
}
//[self adjustMapPlacementWithScale:newMPP];
return zoomFactor;
}
/// This currently is not called because it does not handle the case when the map is continous or not continous. At a certain scale
/// you can continuously move to the west or east until you get to a certain scale level that simply shows the entire world.
- (void)adjustMapPlacementWithScale:(float)aScale
{
CGSize adjustmentDelta = {0.0, 0.0};
CLLocationCoordinate2D rightEdgeLatLong = {0, kMaxLong};
CLLocationCoordinate2D leftEdgeLatLong = {0,- kMaxLong};
CGPoint rightEdge = [self latLongToPixel:rightEdgeLatLong withMetersPerPixel:aScale];
CGPoint leftEdge = [self latLongToPixel:leftEdgeLatLong withMetersPerPixel:aScale];
//CGPoint topEdge = [self latLongToPixel:myLatLong withMetersPerPixel:aScale];
//CGPoint bottomEdge = [self latLongToPixel:myLatLong withMetersPerPixel:aScale];
CGRect containerBounds = [self screenBounds];
if ( rightEdge.x < containerBounds.size.width )
{
adjustmentDelta.width = containerBounds.size.width - rightEdge.x;
[self moveBy:adjustmentDelta];
}
if ( leftEdge.x > containerBounds.origin.x )
{
adjustmentDelta.width = containerBounds.origin.x - leftEdge.x;
[self moveBy:adjustmentDelta];
}
return zoomFactor;
}
/// \bug this is a no-op, not a clamp, if new zoom would be outside of minzoom/maxzoom range
... ... @@ -875,6 +755,7 @@ static NSMutableDictionary *cachedTilesources = nil;
{
return [mercatorToScreenProjection projectedBounds];
}
-(void) setProjectedBounds: (RMProjectedRect) boundsRect
{
[mercatorToScreenProjection setProjectedBounds:boundsRect];
... ...
... ... @@ -121,7 +121,7 @@ typedef struct {
@interface RMMapView : UIView <RMMapContentsFacade, RMMapContentsAnimationCallback>
{
RMMapContents *contents;
id<RMMapViewDelegate> delegate;
id <RMMapViewDelegate> delegate;
BOOL enableDragging;
BOOL enableZoom;
BOOL enableRotate;
... ...
... ... @@ -28,9 +28,5 @@
static NSString* const RMSuspendNetworkOperations = @"RMSuspendNetworkOperations";
static NSString* const RMResumeNetworkOperations = @"RMResumeNetworkOperations";
static NSString* const RMMapImageRemovedFromScreenNotification = @"RMMapImageRemovedFromScreen";
static NSString* const RMMapImageAddedToScreenNotification = @"RMMapImageAddedToScreen";
static NSString* const RMTileRetrieved = @"RMTileRetrieved";
static NSString* const RMTileRequested = @"RMTileRequested";
static NSString* const RMTileError = @"RMTileError";
static NSString* const RMMapImageLoadedNotification = @"RMMapImageLoaded";
static NSString* const RMMapImageLoadingCancelledNotification = @"RMMapImageLoadingCancelled";
... ...
... ... @@ -36,7 +36,6 @@
#import "RMFoundation.h"
#import "RMNotifications.h"
#import "RMTile.h"
#import "RMTileProxy.h"
#import "FMDatabase.h"
@interface RMTileImage : NSObject {
... ... @@ -47,8 +46,6 @@
/// Used by cache
NSDate *lastUsedTime;
// \bug placing the "layer" on the RMTileImage implicitly assumes that a particular RMTileImage will be used in only
// one UIView. Might see some interesting crashes if you have two RMMapViews using the same tile source.
// Only used when appropriate
CALayer *layer;
}
... ...
... ... @@ -55,15 +55,11 @@
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(tileRemovedFromScreen:)
name:RMMapImageRemovedFromScreenNotification object:self];
name:RMMapImageRemovedFromScreenNotification
object:self];
return self;
}
- (void)tileRemovedFromScreen:(NSNotification *)notification
{
[self cancelLoading];
}
- (id)init
{
... ... @@ -121,7 +117,7 @@
return [[[RMDBTileImage alloc] initWithTile: _tile fromDB:db] autorelease];
}
- (void) cancelLoading
- (void)cancelLoading
{
[[NSNotificationCenter defaultCenter] postNotificationName:RMMapImageLoadingCancelledNotification
object:self];
... ... @@ -161,7 +157,7 @@
if (![anObject isKindOfClass:[RMTileImage class]])
return NO;
return RMTilesEqual(tile, [(RMTileImage*)anObject tile]);
return RMTilesEqual(tile, [(RMTileImage *)anObject tile]);
}
- (void)makeLayer
... ...
... ... @@ -64,11 +64,6 @@
return self;
}
- (void)dealloc
{
[super dealloc];
}
- (void)clearLoadedBounds
{
loadedBounds = CGRectZero;
... ... @@ -108,23 +103,19 @@
if ([self screenIsLoaded])
return;
//RMLog(@"updateLoadedImages initial count = %d", [[content imagesOnScreen] count]);
RMTileRect newTileRect = [content tileBounds];
RMTileImageSet *images = [content imagesOnScreen];
images.zoom = newTileRect.origin.tile.zoom;
CGRect newLoadedBounds = [images addTiles:newTileRect toDisplayIn:[content screenBounds]];
//RMLog(@"updateLoadedImages added count = %d", [images count]);
CGRect newLoadedBounds = [images loadTiles:newTileRect toDisplayIn:[content screenBounds]];
if (!RMTileIsDummy(loadedTiles.origin.tile))
{
[images removeTilesOutsideOf:newTileRect];
}
//RMLog(@"updateLoadedImages final count = %d", [images count]);
loadedBounds = newLoadedBounds;
loadedZoom = newTileRect.origin.tile.zoom;
loadedTiles = newTileRect;
... ... @@ -134,9 +125,7 @@
- (void)moveBy:(CGSize)delta
{
// RMLog(@"loadedBounds %f %f %f %f -> ", loadedBounds.origin.x, loadedBounds.origin.y, loadedBounds.size.width, loadedBounds.size.height);
loadedBounds = RMTranslateCGRectBy(loadedBounds, delta);
// RMLog(@" -> %f %f %f %f", loadedBounds.origin.x, loadedBounds.origin.y, loadedBounds.size.width, loadedBounds.size.height);
[self updateLoadedImages];
}
... ...
... ... @@ -68,7 +68,7 @@
/*! \brief clear all images from the in-memory and on-disk image caches
\bug This method belongs on RMCachedTileSource, not on RMTileSource, because an RMTileSource doesn't have a cache.
*/
-(void)removeAllCachedImages;
- (void)removeAllCachedImages;
- (void)didReceiveMemoryWarning;
... ...
... ... @@ -49,8 +49,6 @@ NSString *RMWebTileImageNotificationErrorKey = @"RMWebTileImageNotificationError
retries = kWebTileRetries;
[[NSNotificationCenter defaultCenter] postNotificationName:RMTileRequested object:self];
[self requestTile];
return self;
... ... @@ -80,9 +78,7 @@ NSString *RMWebTileImageNotificationErrorKey = @"RMWebTileImageNotificationError
if (retries == 0) // No more retries
{
[super displayProxy:[RMTileProxy errorTile]];
[[NSNotificationCenter defaultCenter] postNotificationName:RMTileRetrieved object:self];
[[NSNotificationCenter defaultCenter] postNotificationName:RMTileError object:self userInfo:[NSDictionary dictionaryWithObject:lastError forKey:RMWebTileImageNotificationErrorKey]];
[super displayProxy:[RMTileImage errorTile]];
[lastError autorelease]; lastError = nil;
return;
... ... @@ -113,7 +109,6 @@ NSString *RMWebTileImageNotificationErrorKey = @"RMWebTileImageNotificationError
if (!connection)
return;
[[NSNotificationCenter defaultCenter] postNotificationName:RMTileRetrieved object:self];
[connection cancel];
[connection release];
... ... @@ -159,7 +154,6 @@ NSString *RMWebTileImageNotificationErrorKey = @"RMWebTileImageNotificationError
userInfo:[NSDictionary dictionaryWithObjectsAndKeys:
NSLocalizedString(@"The requested tile was not found on the server", @""), NSLocalizedDescriptionKey, nil]];
[[NSNotificationCenter defaultCenter] postNotificationName:RMTileError object:self userInfo:[NSDictionary dictionaryWithObject:error forKey:RMWebTileImageNotificationErrorKey]];
[self cancelLoading];
}
else { // Other Error
... ... @@ -184,7 +178,6 @@ NSString *RMWebTileImageNotificationErrorKey = @"RMWebTileImageNotificationError
[self requestTile];
}
else {
[[NSNotificationCenter defaultCenter] postNotificationName:RMTileError object:self userInfo:[NSDictionary dictionaryWithObject:error forKey:RMWebTileImageNotificationErrorKey]];
[self cancelLoading];
}
}
... ... @@ -221,7 +214,6 @@ NSString *RMWebTileImageNotificationErrorKey = @"RMWebTileImageNotificationError
[self requestTile];
}
else {
[[NSNotificationCenter defaultCenter] postNotificationName:RMTileError object:self userInfo:[NSDictionary dictionaryWithObject:error forKey:RMWebTileImageNotificationErrorKey]];
[self cancelLoading];
}
}
... ... @@ -246,8 +238,6 @@ NSString *RMWebTileImageNotificationErrorKey = @"RMWebTileImageNotificationError
if ( lastError ) {
[lastError release]; lastError = nil;
}
[[NSNotificationCenter defaultCenter] postNotificationName:RMTileRetrieved object:self];
}
}
... ...