/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. #import "MainViewController.h"
  6. #import "MapTestbedAppDelegate.h"
  7. #import "MainView.h"
  8. @implementation MainViewController
  9. @synthesize mapView;
  10. @synthesize infoTextView;
  11. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
  12. if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
  13. // Custom initialization
  14. }
  15. return self;
  16. }
  17. // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
  18. - (void)viewDidLoad {
  19. [super viewDidLoad];
  20. [mapView setDelegate:self];
  21. [mapView setDeceleration:YES];
  22. [self updateInfo];
  23. }
  24. // Override to allow orientations other than the default portrait orientation.
  25. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
  26. // Return YES for supported orientations
  27. return YES;
  28. }
  29. - (void)didReceiveMemoryWarning {
  30. [super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
  31. // Release anything that's not essential, such as cached data
  32. }
  33. - (void)viewDidAppear:(BOOL)animated {
  34. [self updateInfo];
  35. }
  36. - (void)dealloc {
  37. self.infoTextView = nil;
  38. self.mapView = nil;
  39. [super dealloc];
  40. }
  41. - (void)updateInfo {
  42. RMMapContents *contents = self.mapView.contents;
  43. CLLocationCoordinate2D mapCenter = [contents mapCenter];
  44. float routemeMetersPerPixel = [contents metersPerPixel];
  45. double truescaleDenominator = [contents scaleDenominator];
  46. [infoTextView setText:[NSString stringWithFormat:@"Latitude : %f\nLongitude : %f\nZoom level : %.2f\nMeter per pixel : %.1f\nTrue scale : 1:%.0f",
  47. mapCenter.latitude,
  48. mapCenter.longitude,
  49. contents.zoom,
  50. routemeMetersPerPixel,
  51. truescaleDenominator]];
  52. }
  53. #pragma mark -
  54. #pragma mark Delegate methods
  55. - (void) afterMapMove: (RMMapView*) map {
  56. [self updateInfo];
  57. }
  58. - (void) afterMapZoom: (RMMapView*) map byFactor: (float) zoomFactor near:(CGPoint) center {
  59. [self updateInfo];
  60. }
  61. @end