PageRenderTime 23ms CodeModel.GetById 1ms app.highlight 19ms RepoModel.GetById 1ms app.codeStats 0ms

/samples/SampleMap/Classes/MainViewController.m

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