Authored by Justin R. Miller

static map view logo bug

@@ -31,9 +31,11 @@ @@ -31,9 +31,11 @@
31 31
32 - (id)initWithFrame:(CGRect)frame mapID:(NSString *)mapID centerCoordinate:(CLLocationCoordinate2D)centerCoordinate zoomLevel:(CGFloat)initialZoomLevel; 32 - (id)initWithFrame:(CGRect)frame mapID:(NSString *)mapID centerCoordinate:(CLLocationCoordinate2D)centerCoordinate zoomLevel:(CGFloat)initialZoomLevel;
33 33
34 -// TODO: delegate 34 +/** A Boolean value indicating whether to show a small logo in the corner of the map view. Defaults to `YES`. */
  35 +@property (nonatomic, assign) BOOL showLogoBug;
  36 +
  37 +// TODO: success/failure blocks
35 // TODO: markers 38 // TODO: markers
36 // TODO: attribution 39 // TODO: attribution
37 -// TODO: logo bug  
38 40
39 @end 41 @end
@@ -33,6 +33,12 @@ @@ -33,6 +33,12 @@
33 #define RMStaticMapViewMaxZoom 17.0f 33 #define RMStaticMapViewMaxZoom 17.0f
34 34
35 @implementation RMStaticMapView 35 @implementation RMStaticMapView
  36 +{
  37 + UIImageView *_logoBug;
  38 + UIActivityIndicatorView *_spinner;
  39 +}
  40 +
  41 +@synthesize showLogoBug=_showLogoBug;
36 42
37 - (id)initWithFrame:(CGRect)frame mapID:(NSString *)mapID centerCoordinate:(CLLocationCoordinate2D)centerCoordinate zoomLevel:(CGFloat)initialZoomLevel 43 - (id)initWithFrame:(CGRect)frame mapID:(NSString *)mapID centerCoordinate:(CLLocationCoordinate2D)centerCoordinate zoomLevel:(CGFloat)initialZoomLevel
38 { 44 {
@@ -51,15 +57,17 @@ @@ -51,15 +57,17 @@
51 57
52 self.contentMode = UIViewContentModeCenter; 58 self.contentMode = UIViewContentModeCenter;
53 59
54 - UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; 60 + self.showLogoBug = YES;
55 61
56 - [spinner startAnimating]; 62 + _spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
57 63
58 - spinner.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin; 64 + [_spinner startAnimating];
59 65
60 - spinner.center = self.center; 66 + _spinner.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;
61 67
62 - [self addSubview:spinner]; 68 + _spinner.center = self.center;
  69 +
  70 + [self addSubview:_spinner];
63 71
64 NSURL *imageURL = [NSURL URLWithString:[NSString stringWithFormat:@"http://api.tiles.mapbox.com/v3/%@/%f,%f,%i/%ix%i.png", mapID, centerCoordinate.longitude, centerCoordinate.latitude, (int)roundf(initialZoomLevel), (int)roundf(requestFrame.size.width), (int)roundf(requestFrame.size.height)]]; 72 NSURL *imageURL = [NSURL URLWithString:[NSString stringWithFormat:@"http://api.tiles.mapbox.com/v3/%@/%f,%f,%i/%ix%i.png", mapID, centerCoordinate.longitude, centerCoordinate.latitude, (int)roundf(initialZoomLevel), (int)roundf(requestFrame.size.width), (int)roundf(requestFrame.size.height)]];
65 73
@@ -67,7 +75,8 @@ @@ -67,7 +75,8 @@
67 queue:[NSOperationQueue new] 75 queue:[NSOperationQueue new]
68 completionHandler:^(NSURLResponse *response, NSData *responseData, NSError *error) 76 completionHandler:^(NSURLResponse *response, NSData *responseData, NSError *error)
69 { 77 {
70 - [self.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)]; 78 + [_spinner removeFromSuperview];
  79 + [_spinner release]; _spinner = nil;
71 80
72 if (responseData) 81 if (responseData)
73 { 82 {
@@ -84,4 +93,31 @@ @@ -84,4 +93,31 @@
84 return self; 93 return self;
85 } 94 }
86 95
  96 +- (void)dealloc
  97 +{
  98 + [_logoBug release]; _logoBug = nil;
  99 + [_spinner release]; _spinner = nil;
  100 + [super dealloc];
  101 +}
  102 +
  103 +- (void)setShowLogoBug:(BOOL)showLogoBug
  104 +{
  105 + if (showLogoBug && ! _logoBug)
  106 + {
  107 + _logoBug = [[UIImageView alloc] initWithImage:[RMMapView resourceImageNamed:@"mapbox.png"]];
  108 +
  109 + _logoBug.frame = CGRectMake(8, self.bounds.size.height - _logoBug.bounds.size.height - 4, _logoBug.bounds.size.width, _logoBug.bounds.size.height);
  110 + _logoBug.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleRightMargin;
  111 +
  112 + [self addSubview:_logoBug];
  113 + }
  114 + else if ( ! showLogoBug && _logoBug)
  115 + {
  116 + [_logoBug removeFromSuperview];
  117 + [_logoBug release]; _logoBug = nil;
  118 + }
  119 +
  120 + _showLogoBug = showLogoBug;
  121 +}
  122 +
87 @end 123 @end