Authored by Justin R. Miller

fixes #85: add zoom/pan background grid view when no background image

//
// RMTileLoadingView.h
// MapView
//
// Created by Justin R. Miller on 8/15/12.
// Copyright 2012 MapBox.
//
#import <UIKit/UIKit.h>
@interface RMLoadingTileView : UIScrollView
@property (nonatomic, assign) BOOL mapZooming;
@end
... ...
//
// RMTileLoadingView.m
// MapView
//
// Created by Justin R. Miller on 8/15/12.
// Copyright 2012 MapBox.
//
#import "RMLoadingTileView.h"
@implementation RMLoadingTileView
{
UIView *_contentView;
}
@synthesize mapZooming=_mapZooming;
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self)
{
NSAssert([[NSBundle mainBundle] pathForResource:@"LoadingTile" ofType:@"png"], @"Unable to find necessary graphical assets (copy from framework 'Resources' folder)");
_contentView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width * 3, frame.size.height * 3)];
[self addSubview:_contentView];
[self setMapZooming:YES];
self.userInteractionEnabled = NO;
self.showsHorizontalScrollIndicator = NO;
self.showsVerticalScrollIndicator = NO;
}
return self;
}
- (void)dealloc
{
[_contentView release]; _contentView = nil;
[super dealloc];
}
- (void)setMapZooming:(BOOL)zooming
{
if (zooming)
{
_contentView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"LoadingTileZoom.png"]];
}
else
{
_contentView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"LoadingTile.png"]];
_contentView.frame = CGRectMake(0, 0, self.frame.size.width * 3, self.frame.size.height * 3);
self.contentSize = _contentView.bounds.size;
self.contentOffset = CGPointMake(self.frame.size.width, self.frame.size.height);
}
_mapZooming = zooming;
}
- (void)setContentOffset:(CGPoint)contentOffset
{
CGPoint newContentOffset = contentOffset;
if (newContentOffset.x > 2 * self.contentSize.width / 3)
{
newContentOffset.x = self.bounds.size.width;
}
else if (newContentOffset.x < self.contentSize.width / 3)
{
newContentOffset.x = self.bounds.size.width * 2;
}
if (newContentOffset.y > 2 * self.contentSize.height / 3)
{
newContentOffset.y = self.bounds.size.height;
}
else if (newContentOffset.y < self.contentSize.height / 3)
{
newContentOffset.y = self.bounds.size.height * 2;
}
[super setContentOffset:newContentOffset];
}
@end
... ...
... ... @@ -46,6 +46,7 @@
#import "RMMapTiledLayerView.h"
#import "RMMapOverlayView.h"
#import "RMLoadingTileView.h"
#import "RMUserLocation.h"
... ... @@ -135,6 +136,7 @@
RMMapScrollView *_mapScrollView;
RMMapOverlayView *_overlayView;
UIView *_tiledLayersSuperview;
RMLoadingTileView *_loadingTileView;
RMProjection *_projection;
RMFractalTileProjection *_mercatorToTileProjection;
... ... @@ -241,9 +243,16 @@
[self setTileCache:[[[RMTileCache alloc] init] autorelease]];
[self setBackgroundView:[[[UIView alloc] initWithFrame:[self bounds]] autorelease]];
if (backgroundImage)
{
[self setBackgroundView:[[[UIView alloc] initWithFrame:[self bounds]] autorelease]];
self.backgroundView.layer.contents = (id)backgroundImage.CGImage;
}
else
{
_loadingTileView = [[[RMLoadingTileView alloc] initWithFrame:self.bounds] autorelease];
[self setBackgroundView:_loadingTileView];
}
if (minZoomLevel < newTilesource.minZoom) minZoomLevel = newTilesource.minZoom;
if (maxZoomLevel > newTilesource.maxZoom) maxZoomLevel = newTilesource.maxZoom;
... ... @@ -1214,6 +1223,9 @@
[self registerZoomEventByUser:(scrollView.pinchGestureRecognizer.state == UIGestureRecognizerStateBegan)];
_mapScrollViewIsZooming = YES;
if (_loadingTileView)
_loadingTileView.mapZooming = YES;
}
- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale
... ... @@ -1224,6 +1236,19 @@
_mapScrollViewIsZooming = NO;
[self correctPositionOfAllAnnotations];
if (_loadingTileView)
_loadingTileView.mapZooming = NO;
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
if (_loadingTileView)
{
CGSize delta = CGSizeMake(scrollView.contentOffset.x - _lastContentOffset.x, scrollView.contentOffset.y - _lastContentOffset.y);
CGPoint newOffset = CGPointMake(_loadingTileView.contentOffset.x + delta.width, _loadingTileView.contentOffset.y + delta.height);
_loadingTileView.contentOffset = newOffset;
}
}
- (void)scrollViewDidZoom:(UIScrollView *)scrollView
... ...
... ... @@ -21,7 +21,7 @@
if ( ! (self = [super initWithMapView:aMapView coordinate:aCoordinate andTitle:aTitle]))
return nil;
NSAssert([[NSBundle mainBundle] pathForResource:@"TrackingDot" ofType:@"png"], @"Unable to find necessary user location graphical assets (copy from MapView/Map/Resources)");
NSAssert([[NSBundle mainBundle] pathForResource:@"TrackingDot" ofType:@"png"], @"Unable to find necessary graphical assets (copy from framework 'Resources' folder)");
layer = [[RMMarker alloc] initWithUIImage:[UIImage imageNamed:@"TrackingDot.png"]];
... ...
... ... @@ -103,6 +103,8 @@
DD5A200B15CAD09400FE4157 /* GRMustache.h in Headers */ = {isa = PBXBuildFile; fileRef = DD5A200A15CAD09400FE4157 /* GRMustache.h */; };
DD6380DD152E72880074E66E /* RMMapBoxSource.h in Headers */ = {isa = PBXBuildFile; fileRef = DD6380DB152E72880074E66E /* RMMapBoxSource.h */; };
DD6380DE152E72880074E66E /* RMMapBoxSource.m in Sources */ = {isa = PBXBuildFile; fileRef = DD6380DC152E72880074E66E /* RMMapBoxSource.m */; };
DD5FA1EB15E2B020004EB6C5 /* RMLoadingTileView.h in Headers */ = {isa = PBXBuildFile; fileRef = DD5FA1E915E2B020004EB6C5 /* RMLoadingTileView.h */; };
DD5FA1EC15E2B020004EB6C5 /* RMLoadingTileView.m in Sources */ = {isa = PBXBuildFile; fileRef = DD5FA1EA15E2B020004EB6C5 /* RMLoadingTileView.m */; };
DD8CDB4A14E0507100B73EB9 /* RMMapQuestOSMSource.h in Headers */ = {isa = PBXBuildFile; fileRef = DD8CDB4814E0507100B73EB9 /* RMMapQuestOSMSource.h */; };
DD8CDB4B14E0507100B73EB9 /* RMMapQuestOSMSource.m in Sources */ = {isa = PBXBuildFile; fileRef = DD8CDB4914E0507100B73EB9 /* RMMapQuestOSMSource.m */; };
DD8FD7541559E4A40044D96F /* RMUserLocation.h in Headers */ = {isa = PBXBuildFile; fileRef = DD8FD7521559E4A40044D96F /* RMUserLocation.h */; };
... ... @@ -228,9 +230,12 @@
DD2B375414CF8197008DE8CB /* RMMBTilesSource.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RMMBTilesSource.m; sourceTree = "<group>"; };
DD3BEF7715913C55007892D8 /* RMAttributionViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RMAttributionViewController.h; sourceTree = "<group>"; };
DD3BEF7815913C55007892D8 /* RMAttributionViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RMAttributionViewController.m; sourceTree = "<group>"; };
DD49B8A815E2CE4E0055CCEE /* LoadingTileZoom.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = LoadingTileZoom.png; path = Resources/LoadingTileZoom.png; sourceTree = "<group>"; };
DD49B8A915E2CE4E0055CCEE /* LoadingTile.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = LoadingTile.png; path = Resources/LoadingTile.png; sourceTree = "<group>"; };
DD5A200815CAD03700FE4157 /* libGRMustache4-iOS.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = "libGRMustache4-iOS.a"; path = "GRMustache/lib/libGRMustache4-iOS.a"; sourceTree = "<group>"; };
DD5A200A15CAD09400FE4157 /* GRMustache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = GRMustache.h; path = GRMustache/include/GRMustache.h; sourceTree = "<group>"; };
DD624B4315B4EB53004524C4 /* loading.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = loading.png; path = Resources/loading.png; sourceTree = "<group>"; };
DD5FA1E915E2B020004EB6C5 /* RMLoadingTileView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RMLoadingTileView.h; sourceTree = "<group>"; };
DD5FA1EA15E2B020004EB6C5 /* RMLoadingTileView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RMLoadingTileView.m; sourceTree = "<group>"; };
DD8CDB4814E0507100B73EB9 /* RMMapQuestOSMSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RMMapQuestOSMSource.h; sourceTree = "<group>"; };
DD8CDB4914E0507100B73EB9 /* RMMapQuestOSMSource.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RMMapQuestOSMSource.m; sourceTree = "<group>"; };
DD8FD7521559E4A40044D96F /* RMUserLocation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RMUserLocation.h; sourceTree = "<group>"; };
... ... @@ -363,6 +368,8 @@
1609AF8D14068B09008344B7 /* RMMapOverlayView.m */,
16F3581915864135003A3AD9 /* RMMapScrollView.h */,
16F3581A15864135003A3AD9 /* RMMapScrollView.m */,
DD5FA1E915E2B020004EB6C5 /* RMLoadingTileView.h */,
DD5FA1EA15E2B020004EB6C5 /* RMLoadingTileView.m */,
);
name = "Tile Layer & Overlay";
sourceTree = "<group>";
... ... @@ -509,9 +516,10 @@
DD8FD7581559EDA80044D96F /* Resources */ = {
isa = PBXGroup;
children = (
DD624B4315B4EB53004524C4 /* loading.png */,
DD8FD7631559EE120044D96F /* HeadingAngleSmall.png */,
DD8FD7641559EE120044D96F /* HeadingAngleSmall@2x.png */,
DD49B8A915E2CE4E0055CCEE /* LoadingTile.png */,
DD49B8A815E2CE4E0055CCEE /* LoadingTileZoom.png */,
DD8FD7651559EE120044D96F /* TrackingDot.png */,
DD8FD7661559EE120044D96F /* TrackingDot@2x.png */,
DD8FD76C1559EE120044D96F /* TrackingDotHalo.png */,
... ... @@ -602,6 +610,7 @@
161E563A1594664E00B00BB6 /* RMOpenSeaMapLayer.h in Headers */,
1656665515A1DF7900EF3DC7 /* RMCoordinateGridSource.h in Headers */,
DD5A200B15CAD09400FE4157 /* GRMustache.h in Headers */,
DD5FA1EB15E2B020004EB6C5 /* RMLoadingTileView.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
... ... @@ -719,6 +728,7 @@
16FBF07715936BF1004ECAD1 /* RMTileSourcesContainer.m in Sources */,
161E563B1594664E00B00BB6 /* RMOpenSeaMapLayer.m in Sources */,
1656665615A1DF7900EF3DC7 /* RMCoordinateGridSource.m in Sources */,
DD5FA1EC15E2B020004EB6C5 /* RMLoadingTileView.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
... ...