/samples/MapTestbedFlipMaps/Classes/FlipsideViewController.m

http://github.com/route-me/route-me · Objective C · 106 lines · 65 code · 27 blank · 14 comment · 1 complexity · d666f83eaf9ffe2f743116479113a49d MD5 · raw file

  1. //
  2. // FlipsideViewController.m
  3. // MapTestbed : Diagnostic map
  4. //
  5. #import "FlipsideViewController.h"
  6. #import "MapTestbedAppDelegate.h"
  7. #import "RMMarker.h"
  8. #import "RMMarkerManager.h"
  9. @implementation FlipsideViewController
  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. [self updateInfo];
  23. RMMarkerManager *markerManager = [mapView markerManager];
  24. NSAssert(markerManager, @"null markerManager returned");
  25. RMMarker *marker = [[RMMarker alloc] initWithUIImage:[UIImage imageNamed:@"marker-blue.png"]
  26. anchorPoint:CGPointMake(0.5, 1.0)];
  27. [marker setTextForegroundColor:[UIColor blueColor]];
  28. [marker changeLabelUsingText:@"Hello"];
  29. [markerManager addMarker:marker AtLatLong:[[mapView contents] mapCenter]];
  30. [marker release];
  31. }
  32. /*
  33. // Override to allow orientations other than the default portrait orientation.
  34. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
  35. // Return YES for supported orientations
  36. return (interfaceOrientation == UIInterfaceOrientationPortrait);
  37. }
  38. */
  39. - (void)didReceiveMemoryWarning {
  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. self.infoTextView = nil;
  48. self.mapView = nil;
  49. [super dealloc];
  50. }
  51. - (void)updateInfo {
  52. RMMapContents *contents = self.mapView.contents;
  53. CLLocationCoordinate2D mapCenter = [contents mapCenter];
  54. float routemeMetersPerPixel = [contents metersPerPixel];
  55. double truescaleDenominator = [contents scaleDenominator];
  56. [infoTextView setText:[NSString stringWithFormat:@"Latitude : %f\nLongitude : %f\nZoom level : %.2f\nMeter per pixel : %.1f\nTrue scale : 1:%.0f",
  57. mapCenter.latitude,
  58. mapCenter.longitude,
  59. contents.zoom,
  60. routemeMetersPerPixel,
  61. truescaleDenominator]];
  62. }
  63. #pragma mark -
  64. #pragma mark Delegate methods
  65. - (void)mapView:(RMMapView *)map didDragMarker:(RMMarker *)marker withEvent:(UIEvent *)event
  66. {
  67. CGPoint position = [[[event allTouches] anyObject] locationInView:mapView];
  68. RMMarkerManager *markerManager = [mapView markerManager];
  69. NSLog(@"New location: X:%lf Y:%lf", [marker projectedLocation].easting, [marker projectedLocation].northing);
  70. CGRect rect = [marker bounds];
  71. [markerManager moveMarker:marker AtXY:CGPointMake(position.x,position.y +rect.size.height/3)];
  72. }
  73. - (void) afterMapMove: (RMMapView*) map {
  74. [self updateInfo];
  75. }
  76. - (void) afterMapZoom: (RMMapView*) map byFactor: (float) zoomFactor near:(CGPoint) center {
  77. [self updateInfo];
  78. }
  79. @end