Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decoupled map view with and without annotations, added tests. #16

Merged
merged 11 commits into from
Mar 9, 2014
36 changes: 32 additions & 4 deletions Demo/Demo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
/* Begin PBXBuildFile section */
07DDEB3EBEEC4C6FAF715BF1 /* libPods-DemoTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 98DB4ADA533041DD9D9E7647 /* libPods-DemoTests.a */; };
273E9EE865984F44A8AF2A9D /* libPods.a in Frameworks */ = {isa = PBXBuildFile; fileRef = D2957D8BD1FB4630AD6F922F /* libPods.a */; };
3C9F354518CA838600EA1F22 /* NAMasterViewControllerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 3C9F354418CA838600EA1F22 /* NAMasterViewControllerTests.m */; };
3C9F354718CA862100EA1F22 /* NABasicDemoViewControllerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 3C9F354618CA862100EA1F22 /* NABasicDemoViewControllerTests.m */; };
3C9F354918CA86D600EA1F22 /* NAInteractiveDemoViewControllerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 3C9F354818CA86D600EA1F22 /* NAInteractiveDemoViewControllerTests.m */; };
3C9F354B18CA876700EA1F22 /* NALoadViaNIBDemoViewControllerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 3C9F354A18CA876700EA1F22 /* NALoadViaNIBDemoViewControllerTests.m */; };
3C9F354E18CA922C00EA1F22 /* NAPlainDemoViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 3C9F354D18CA922C00EA1F22 /* NAPlainDemoViewController.m */; };
3C9F355018CB8B6000EA1F22 /* NAPlainDemoViewControllerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 3C9F354F18CB8B6000EA1F22 /* NAPlainDemoViewControllerTests.m */; };
3CB0E6D718C8B9E2009CE8DB /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3CB0E6D618C8B9E2009CE8DB /* Foundation.framework */; };
3CB0E6D918C8B9E2009CE8DB /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3CB0E6D818C8B9E2009CE8DB /* CoreGraphics.framework */; };
3CB0E6DB18C8B9E2009CE8DB /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3CB0E6DA18C8B9E2009CE8DB /* UIKit.framework */; };
Expand All @@ -19,7 +25,6 @@
3CB0E6F718C8B9E2009CE8DB /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3CB0E6D618C8B9E2009CE8DB /* Foundation.framework */; };
3CB0E6F818C8B9E3009CE8DB /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3CB0E6DA18C8B9E2009CE8DB /* UIKit.framework */; };
3CB0E70018C8B9E3009CE8DB /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 3CB0E6FE18C8B9E3009CE8DB /* InfoPlist.strings */; };
3CB0E70218C8B9E3009CE8DB /* NAMapViewTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 3CB0E70118C8B9E3009CE8DB /* NAMapViewTests.m */; };
3CB0E71B18C8BB08009CE8DB /* NAAnimatedDemoViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 3CB0E70C18C8BB08009CE8DB /* NAAnimatedDemoViewController.m */; };
3CB0E71C18C8BB08009CE8DB /* NAAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 3CB0E70E18C8BB08009CE8DB /* NAAppDelegate.m */; };
3CB0E71D18C8BB08009CE8DB /* NABasicDemoViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 3CB0E71018C8BB08009CE8DB /* NABasicDemoViewController.m */; };
Expand All @@ -30,6 +35,7 @@
3CB0E72218C8BB08009CE8DB /* NAMasterViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 3CB0E71818C8BB08009CE8DB /* NAMasterViewController.m */; };
3CB0E72718C8BC0C009CE8DB /* australia.png in Resources */ = {isa = PBXBuildFile; fileRef = 3CB0E72618C8BC0C009CE8DB /* australia.png */; };
3CB0E72A18C8BC62009CE8DB /* NAMasterViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 3CB0E72818C8BC62009CE8DB /* NAMasterViewController.xib */; };
3CB0E72F18C8C9A4009CE8DB /* NAMapViewTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 3CB0E72E18C8C9A4009CE8DB /* NAMapViewTests.m */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand All @@ -43,6 +49,13 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
3C9F354418CA838600EA1F22 /* NAMasterViewControllerTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NAMasterViewControllerTests.m; sourceTree = "<group>"; };
3C9F354618CA862100EA1F22 /* NABasicDemoViewControllerTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NABasicDemoViewControllerTests.m; sourceTree = "<group>"; };
3C9F354818CA86D600EA1F22 /* NAInteractiveDemoViewControllerTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NAInteractiveDemoViewControllerTests.m; sourceTree = "<group>"; };
3C9F354A18CA876700EA1F22 /* NALoadViaNIBDemoViewControllerTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NALoadViaNIBDemoViewControllerTests.m; sourceTree = "<group>"; };
3C9F354C18CA922C00EA1F22 /* NAPlainDemoViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NAPlainDemoViewController.h; sourceTree = "<group>"; };
3C9F354D18CA922C00EA1F22 /* NAPlainDemoViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NAPlainDemoViewController.m; sourceTree = "<group>"; };
3C9F354F18CB8B6000EA1F22 /* NAPlainDemoViewControllerTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NAPlainDemoViewControllerTests.m; sourceTree = "<group>"; };
3CB0E6D318C8B9E2009CE8DB /* Demo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Demo.app; sourceTree = BUILT_PRODUCTS_DIR; };
3CB0E6D618C8B9E2009CE8DB /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
3CB0E6D818C8B9E2009CE8DB /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; };
Expand All @@ -56,7 +69,6 @@
3CB0E6F518C8B9E2009CE8DB /* XCTest.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = XCTest.framework; path = Library/Frameworks/XCTest.framework; sourceTree = DEVELOPER_DIR; };
3CB0E6FD18C8B9E3009CE8DB /* DemoTests-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "DemoTests-Info.plist"; sourceTree = "<group>"; };
3CB0E6FF18C8B9E3009CE8DB /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = "<group>"; };
3CB0E70118C8B9E3009CE8DB /* NAMapViewTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = NAMapViewTests.m; sourceTree = "<group>"; };
3CB0E70B18C8BB08009CE8DB /* NAAnimatedDemoViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NAAnimatedDemoViewController.h; sourceTree = "<group>"; };
3CB0E70C18C8BB08009CE8DB /* NAAnimatedDemoViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NAAnimatedDemoViewController.m; sourceTree = "<group>"; };
3CB0E70D18C8BB08009CE8DB /* NAAppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NAAppDelegate.h; sourceTree = "<group>"; };
Expand All @@ -74,6 +86,7 @@
3CB0E72618C8BC0C009CE8DB /* australia.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = australia.png; sourceTree = "<group>"; };
3CB0E72918C8BC62009CE8DB /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = en.lproj/NAMasterViewController.xib; sourceTree = "<group>"; };
3CB0E72B18C8BD61009CE8DB /* DemoTests-Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "DemoTests-Prefix.pch"; sourceTree = "<group>"; };
3CB0E72E18C8C9A4009CE8DB /* NAMapViewTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NAMapViewTests.m; sourceTree = "<group>"; };
93B37F17EB6B492D83AB25A2 /* Pods-DemoTests.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-DemoTests.xcconfig"; path = "Pods/Pods-DemoTests.xcconfig"; sourceTree = "<group>"; };
98DB4ADA533041DD9D9E7647 /* libPods-DemoTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-DemoTests.a"; sourceTree = BUILT_PRODUCTS_DIR; };
BD0E280B71AE47E499695C40 /* Pods.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.xcconfig; path = Pods/Pods.xcconfig; sourceTree = "<group>"; };
Expand Down Expand Up @@ -161,6 +174,8 @@
3CB0E71818C8BB08009CE8DB /* NAMasterViewController.m */,
3CB0E6EE18C8B9E2009CE8DB /* Images.xcassets */,
3CB0E6DD18C8B9E2009CE8DB /* Supporting Files */,
3C9F354C18CA922C00EA1F22 /* NAPlainDemoViewController.h */,
3C9F354D18CA922C00EA1F22 /* NAPlainDemoViewController.m */,
);
path = Demo;
sourceTree = "<group>";
Expand All @@ -179,8 +194,13 @@
3CB0E6FB18C8B9E3009CE8DB /* DemoTests */ = {
isa = PBXGroup;
children = (
3CB0E70118C8B9E3009CE8DB /* NAMapViewTests.m */,
3CB0E72E18C8C9A4009CE8DB /* NAMapViewTests.m */,
3CB0E6FC18C8B9E3009CE8DB /* Supporting Files */,
3C9F354418CA838600EA1F22 /* NAMasterViewControllerTests.m */,
3C9F354618CA862100EA1F22 /* NABasicDemoViewControllerTests.m */,
3C9F354818CA86D600EA1F22 /* NAInteractiveDemoViewControllerTests.m */,
3C9F354A18CA876700EA1F22 /* NALoadViaNIBDemoViewControllerTests.m */,
3C9F354F18CB8B6000EA1F22 /* NAPlainDemoViewControllerTests.m */,
);
path = DemoTests;
sourceTree = "<group>";
Expand Down Expand Up @@ -368,6 +388,7 @@
3CB0E71E18C8BB08009CE8DB /* NAInteractiveDemoViewController.m in Sources */,
3CB0E71C18C8BB08009CE8DB /* NAAppDelegate.m in Sources */,
3CB0E71B18C8BB08009CE8DB /* NAAnimatedDemoViewController.m in Sources */,
3C9F354E18CA922C00EA1F22 /* NAPlainDemoViewController.m in Sources */,
3CB0E72018C8BB08009CE8DB /* NALoadViaNIBDemoViewController.m in Sources */,
3CB0E71D18C8BB08009CE8DB /* NABasicDemoViewController.m in Sources */,
);
Expand All @@ -377,7 +398,12 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
3CB0E70218C8B9E3009CE8DB /* NAMapViewTests.m in Sources */,
3C9F355018CB8B6000EA1F22 /* NAPlainDemoViewControllerTests.m in Sources */,
3CB0E72F18C8C9A4009CE8DB /* NAMapViewTests.m in Sources */,
3C9F354918CA86D600EA1F22 /* NAInteractiveDemoViewControllerTests.m in Sources */,
3C9F354718CA862100EA1F22 /* NABasicDemoViewControllerTests.m in Sources */,
3C9F354518CA838600EA1F22 /* NAMasterViewControllerTests.m in Sources */,
3C9F354B18CA876700EA1F22 /* NALoadViaNIBDemoViewControllerTests.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -533,6 +559,7 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "DemoTests/DemoTests-Prefix.pch";
GCC_PREPROCESSOR_DEFINITIONS = (
"FB_REFERENCE_IMAGE_DIR=\"\\\"$(SOURCE_ROOT)/$(PROJECT_NAME)Tests/ReferenceImages\\\"\"",
"DEBUG=1",
"$(inherited)",
);
Expand All @@ -556,6 +583,7 @@
);
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "DemoTests/DemoTests-Prefix.pch";
GCC_PREPROCESSOR_DEFINITIONS = "";
INFOPLIST_FILE = "DemoTests/DemoTests-Info.plist";
PRODUCT_NAME = "$(TARGET_NAME)";
TEST_HOST = "$(BUNDLE_LOADER)";
Expand Down
42 changes: 18 additions & 24 deletions Demo/Demo/NAAnimatedDemoViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,45 +8,39 @@

#import "NAAnimatedDemoViewController.h"
#import "NAMapView.h"
#import "NAAnnotation.h"


#import "NAPinAnnotationMapView.h"
#import "NAPinAnnotation.h"

@implementation NAAnimatedDemoViewController


- (void)viewDidLoad
{
[super viewDidLoad];
NAMapView *mapView = [[NAMapView alloc] initWithFrame:self.view.bounds];

NAMapView *mapView = [[NAPinAnnotationMapView alloc] initWithFrame:self.view.bounds];

mapView.backgroundColor = [UIColor colorWithRed:0.000f green:0.475f blue:0.761f alpha:1.000f];
mapView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;


[mapView displayMap:[UIImage imageNamed:@"australia"]];

mapView.minimumZoomScale = 0.5f;
mapView.maximumZoomScale = 1.5f;

[self.view addSubview:mapView];

NAAnnotation *a0 = [NAAnnotation annotationWithPoint:CGPointMake(63.0f, 379.0f)];
NAAnnotation *a1 = [NAAnnotation annotationWithPoint:CGPointMake(130.0f, 340.0f)];
NAAnnotation *a2 = [NAAnnotation annotationWithPoint:CGPointMake(200.0f, 311.0f)];
NAAnnotation *a3 = [NAAnnotation annotationWithPoint:CGPointMake(308.0f, 304.0f)];
NAAnnotation *a4 = [NAAnnotation annotationWithPoint:CGPointMake(404.0f, 302.0f)];
NAAnnotation *a5 = [NAAnnotation annotationWithPoint:CGPointMake(472.0f, 367.0f)];
NAAnnotation *a6 = [NAAnnotation annotationWithPoint:CGPointMake(530.0f, 422.0f)];
NAAnnotation *a7 = [NAAnnotation annotationWithPoint:CGPointMake(541.0f, 488.0f)];

NSArray *annotations = [NSArray arrayWithObjects:a0, a1, a2, a3, a4, a5, a6, a7, nil];

[mapView addAnnotations:annotations animated:YES];

}
NAPinAnnotation *a0 = [NAPinAnnotation annotationWithPoint:CGPointMake(63.0f, 379.0f)];
NAPinAnnotation *a1 = [NAPinAnnotation annotationWithPoint:CGPointMake(130.0f, 340.0f)];
NAPinAnnotation *a2 = [NAPinAnnotation annotationWithPoint:CGPointMake(200.0f, 311.0f)];
NAPinAnnotation *a3 = [NAPinAnnotation annotationWithPoint:CGPointMake(308.0f, 304.0f)];
NAPinAnnotation *a4 = [NAPinAnnotation annotationWithPoint:CGPointMake(404.0f, 302.0f)];
NAPinAnnotation *a5 = [NAPinAnnotation annotationWithPoint:CGPointMake(472.0f, 367.0f)];
NAPinAnnotation *a6 = [NAPinAnnotation annotationWithPoint:CGPointMake(530.0f, 422.0f)];
NAPinAnnotation *a7 = [NAPinAnnotation annotationWithPoint:CGPointMake(541.0f, 488.0f)];

NSArray *annotations = [NSArray arrayWithObjects:a0, a1, a2, a3, a4, a5, a6, a7, nil];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor, but this can now be NSArray *annotations = @[a0, a1, a2, a3, a4, a5, a6, a7];

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might as well inline the annotations


[mapView addAnnotations:annotations animated:YES];
}

@end
2 changes: 1 addition & 1 deletion Demo/Demo/NABasicDemoViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
#import <UIKit/UIKit.h>

@interface NABasicDemoViewController : UIViewController

@property(nonatomic, readonly) NSArray *pins;
@end
36 changes: 21 additions & 15 deletions Demo/Demo/NABasicDemoViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

#import "NABasicDemoViewController.h"
#import "NAMapView.h"
#import "NAAnnotation.h"
#import "NAPinAnnotationMapView.h"
#import "NAPinAnnotation.h"

@interface NABasicDemoViewController ()

Expand All @@ -28,8 +29,9 @@ - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
- (void)viewDidLoad
{
[super viewDidLoad];

NAMapView *mapView = [[NAMapView alloc] initWithFrame:self.view.bounds];

NSMutableArray *pins = [NSMutableArray array];
NAMapView *mapView = [[NAPinAnnotationMapView alloc] initWithFrame:self.view.bounds];

mapView.backgroundColor = [UIColor colorWithRed:0.000f green:0.475f blue:0.761f alpha:1.000f];
mapView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
Expand All @@ -41,27 +43,31 @@ - (void)viewDidLoad

[self.view addSubview:mapView];

NAAnnotation *melbourne = [NAAnnotation annotationWithPoint:CGPointMake(543.0f, 489.0f)];
melbourne.title = @"Melbourne";
melbourne.subtitle = @"I have a subtitle";
melbourne.color = NAPinColorGreen;
NAPinAnnotation *melbourne = [NAPinAnnotation annotationWithPoint:CGPointMake(543.0f, 489.0f)];
melbourne.title = @"Melbourne";
melbourne.subtitle = @"I have a subtitle";
melbourne.color = NAPinColorGreen;

[mapView addAnnotation:melbourne animated:NO];
[pins addObject:melbourne];

NAAnnotation * perth = [NAAnnotation annotationWithPoint:CGPointMake(63.0f, 379.0f)];
perth.title = @"Perth";
perth.subtitle = @"I have a button";
NAPinAnnotation * perth = [NAPinAnnotation annotationWithPoint:CGPointMake(63.0f, 379.0f)];
perth.title = @"Perth";
perth.subtitle = @"I have a button";
perth.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
perth.color = NAPinColorRed;
perth.color = NAPinColorRed;

[mapView addAnnotation:perth animated:YES];
[pins addObject:perth];

NAAnnotation * brisbane = [NAAnnotation annotationWithPoint:CGPointMake(679.0f, 302.0f)];
brisbane.title = @"Brisbane";
brisbane.color = NAPinColorPurple;
NAPinAnnotation * brisbane = [NAPinAnnotation annotationWithPoint:CGPointMake(679.0f, 302.0f)];
brisbane.title = @"Brisbane";
brisbane.color = NAPinColorPurple;

[mapView addAnnotation:brisbane animated:NO];

[pins addObject:brisbane];

_pins = pins;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
Expand Down
5 changes: 5 additions & 0 deletions Demo/Demo/NAInteractiveDemoViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,18 @@

#import <UIKit/UIKit.h>
#import "NAMapView.h"
#import "NAPinAnnotation.h"

@interface NAInteractiveDemoViewController : UIViewController

@property (nonatomic, weak) IBOutlet NAMapView *mapView;

-(IBAction)addPin:(id)sender;
-(void)addPinAt:(CGPoint)point withColor:(NAPinColor)color;

-(IBAction)removePin:(id)sender;

-(IBAction)selectRandom:(id)sender;
-(void)selectPinAt:(NSInteger)index;

@end
57 changes: 33 additions & 24 deletions Demo/Demo/NAInteractiveDemoViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
//

#import "NAInteractiveDemoViewController.h"
#import "NAPinAnnotation.h"

@interface NAInteractiveDemoViewController (){
int _count;
NAAnnotation *_lastFocused;
NAPinAnnotation *_lastFocused;
}
@property (nonatomic, strong) NSMutableArray *annotations;
@property (nonatomic, assign) CGSize size;
Expand All @@ -26,64 +27,72 @@ @implementation NAInteractiveDemoViewController
- (void)viewDidLoad
{
[super viewDidLoad];

self.annotations = [[NSMutableArray alloc] init];

UIImage *image = [UIImage imageNamed:@"australia"];

self.mapView.backgroundColor = [UIColor colorWithRed:0.000f green:0.475f blue:0.761f alpha:1.000f];

[self.mapView displayMap:image];

self.size = image.size;

_count = 0;
_lastFocused = nil;
}


-(IBAction)addPin:(id)sender{

int x = (arc4random() % (int)self.size.width);
int y = (arc4random() % (int)self.size.width);

CGPoint point = CGPointMake(x, y);

[self addPinAt:point withColor:arc4random() % 3];
}

-(void)addPinAt:(CGPoint)point withColor:(NAPinColor)color{

[self.mapView centreOnPoint:point animated:YES];
NAAnnotation *annotation = [NAAnnotation annotationWithPoint:point];

NAPinAnnotation *annotation = [NAPinAnnotation annotationWithPoint:point];

annotation.title = [NSString stringWithFormat:@"Pin %d", ++_count];
annotation.color = arc4random() % 3;

annotation.color = color;

[self.mapView addAnnotation:annotation animated:YES];

[self.annotations addObject:annotation];

_lastFocused = annotation;

}

-(IBAction)removePin:(id)sender{

if([self.annotations count] <= 0 || _lastFocused == nil) return;

[self.mapView centreOnPoint:_lastFocused.point animated:YES];

[self.mapView removeAnnotation:_lastFocused];

[self.annotations removeObject:_lastFocused];

_lastFocused = ([self.annotations count] > 0) ? [self.annotations objectAtIndex:[self.annotations count]-1] : nil;
}

-(IBAction)selectRandom:(id)sender{
if([self.annotations count] <= 0) return;

int rand = (arc4random() % (int)[self.annotations count]);
NAAnnotation *annotation = [self.annotations objectAtIndex:rand];
[self selectPinAt:rand];
}

-(void)selectPinAt:(NSInteger)index{
NAPinAnnotation *annotation = [self.annotations objectAtIndex:index];

[self.mapView selectAnnotation:annotation animated:YES];

_lastFocused = annotation;
Expand Down
Loading