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