PageRenderTime 43ms CodeModel.GetById 28ms app.highlight 13ms RepoModel.GetById 1ms app.codeStats 0ms

/samples/MapTestbed/Classes/MainViewController.m

http://github.com/route-me/route-me
Objective C | 84 lines | 52 code | 23 blank | 9 comment | 1 complexity | ad47b2e336fcc9de979cbf7362fa5fa9 MD5 | raw file
 1//
 2//  MainViewController.m
 3//  MapTestbed : Diagnostic map
 4//
 5
 6#import "MainViewController.h"
 7#import "MapTestbedAppDelegate.h"
 8
 9#import "MainView.h"
10
11@implementation MainViewController
12
13@synthesize mapView;
14@synthesize infoTextView;
15
16- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
17    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
18        // Custom initialization
19    }
20    return self;
21}
22
23
24// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
25- (void)viewDidLoad {
26    [super viewDidLoad];
27    [mapView setDelegate:self];
28	[mapView setDeceleration:YES];
29    [self updateInfo];
30}
31
32
33
34 // Override to allow orientations other than the default portrait orientation.
35 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
36 // Return YES for supported orientations
37	 return YES;
38 }
39
40
41
42- (void)didReceiveMemoryWarning {
43    [super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
44    // Release anything that's not essential, such as cached data
45}
46
47- (void)viewDidAppear:(BOOL)animated {
48    [self updateInfo];
49}
50
51- (void)dealloc {
52    self.infoTextView = nil; 
53    self.mapView = nil; 
54    [super dealloc];
55}
56
57- (void)updateInfo {
58	RMMapContents *contents = self.mapView.contents;
59    CLLocationCoordinate2D mapCenter = [contents mapCenter];
60    
61    float routemeMetersPerPixel = [contents metersPerPixel];
62	double truescaleDenominator =  [contents scaleDenominator];
63    
64    [infoTextView setText:[NSString stringWithFormat:@"Latitude : %f\nLongitude : %f\nZoom level : %.2f\nMeter per pixel : %.1f\nTrue scale : 1:%.0f", 
65                           mapCenter.latitude, 
66                           mapCenter.longitude, 
67                           contents.zoom, 
68                           routemeMetersPerPixel,
69                           truescaleDenominator]];
70}
71
72#pragma mark -
73#pragma mark Delegate methods
74
75- (void) afterMapMove: (RMMapView*) map {
76    [self updateInfo];
77}
78
79- (void) afterMapZoom: (RMMapView*) map byFactor: (float) zoomFactor near:(CGPoint) center {
80    [self updateInfo];
81}
82
83
84@end