/samples/MapTestbed/Classes/MapTestbedAppDelegate.m

http://github.com/route-me/route-me · Objective C · 150 lines · 114 code · 27 blank · 9 comment · 0 complexity · 4f1a4907bcb8bb418a7f54a5faf6813a MD5 · raw file

  1. //
  2. // MapTestbedAppDelegate.m
  3. // MapTestbed : Diagnostic map
  4. //
  5. #import "MapTestbedAppDelegate.h"
  6. #import "RootViewController.h"
  7. #import "MainViewController.h"
  8. #import "RMPath.h"
  9. #import "RMMarker.h"
  10. #import "RMMarkerManager.h"
  11. @implementation MapTestbedAppDelegate
  12. @synthesize window;
  13. @synthesize rootViewController;
  14. -(RMMapContents *)mapContents
  15. {
  16. return self.rootViewController.mainViewController.mapView.contents;
  17. }
  18. -(void)performTestPart2
  19. {
  20. // a bug exists that offsets the path when we execute this moveToLatLong
  21. CLLocationCoordinate2D pt;
  22. pt.latitude = 48.86600492029781f;
  23. pt.longitude = 2.3194026947021484f;
  24. [self.mapContents moveToLatLong: pt];
  25. }
  26. -(void)performTestPart3
  27. {
  28. // path returns to correct position after this zoom
  29. CLLocationCoordinate2D northeast, southwest;
  30. northeast.latitude = 48.885875363989435f;
  31. northeast.longitude = 2.338285446166992f;
  32. southwest.latitude = 48.860406466081656f;
  33. southwest.longitude = 2.2885894775390625;
  34. [self.mapContents zoomWithLatLngBoundsNorthEast:northeast SouthWest:southwest];
  35. }
  36. - (void)performTest
  37. {
  38. NSLog(@"testing paths");
  39. RMMapContents *mapContents = [self mapContents];
  40. UIImage *xMarkerImage = [UIImage imageNamed:@"marker-X.png"];
  41. // if we zoom with bounds after the paths are created, nothing is displayed on the map
  42. CLLocationCoordinate2D northeast, southwest;
  43. northeast.latitude = 48.885875363989435f;
  44. northeast.longitude = 2.338285446166992f;
  45. southwest.latitude = 48.860406466081656f;
  46. southwest.longitude = 2.2885894775390625;
  47. [mapContents zoomWithLatLngBoundsNorthEast:northeast SouthWest:southwest];
  48. CLLocationCoordinate2D one, two, three, four;
  49. one.latitude = 48.884238608729035f;
  50. one.longitude = 2.297086715698242f;
  51. two.latitude = 48.878481319827735f;
  52. two.longitude = 2.294340133666992f;
  53. three.latitude = 48.87351371451778f;
  54. three.longitude = 2.2948551177978516f;
  55. four.latitude = 48.86600492029781f;
  56. four.longitude = 2.3194026947021484f;
  57. // draw a green path south down an avenue and southeast on Champs-Elysees
  58. RMPath *testPath, *testRegion;
  59. testPath = [[RMPath alloc] initWithContents:mapContents];
  60. [testPath setLineColor:[UIColor greenColor]];
  61. [testPath setFillColor:[UIColor clearColor]];
  62. [testPath setLineWidth:4.0f];
  63. [testPath setShadowColor:[UIColor colorWithWhite:0.0 alpha:0.8]];
  64. [testPath setShadowBlur:4.0];
  65. [testPath setShadowOffset:CGSizeMake(0, 4)];
  66. [testPath addLineToLatLong:one];
  67. [testPath addLineToLatLong:two];
  68. [testPath addLineToLatLong:three];
  69. [testPath addLineToLatLong:four];
  70. [[mapContents overlay] addSublayer:testPath];
  71. [testPath release];
  72. RMMarker *newMarker;
  73. newMarker = [[RMMarker alloc] initWithUIImage:xMarkerImage anchorPoint:CGPointMake(0.5, 1.0)];
  74. [mapContents.markerManager addMarker:[newMarker autorelease] AtLatLong:one];
  75. newMarker = [[RMMarker alloc] initWithUIImage:xMarkerImage anchorPoint:CGPointMake(0.5, 1.0)];
  76. [mapContents.markerManager addMarker:[newMarker autorelease] AtLatLong:two];
  77. newMarker = [[RMMarker alloc] initWithUIImage:xMarkerImage anchorPoint:CGPointMake(0.5, 1.0)];
  78. [mapContents.markerManager addMarker:[newMarker autorelease] AtLatLong:three];
  79. newMarker = [[RMMarker alloc] initWithUIImage:xMarkerImage anchorPoint:CGPointMake(0.5, 1.0)];
  80. [mapContents.markerManager addMarker:[newMarker autorelease] AtLatLong:four];
  81. CLLocationCoordinate2D r1, r2, r3, r4;
  82. r1.latitude = 48.86637615203047f;
  83. r1.longitude = 2.3236513137817383f;
  84. r2.latitude = 48.86372241857954f;
  85. r2.longitude = 2.321462631225586f;
  86. r3.latitude = 48.86087090984738f;
  87. r3.longitude = 2.330174446105957f;
  88. r4.latitude = 48.86369418661614f;
  89. r4.longitude = 2.332019805908203f;
  90. // draw a blue-filled rectangle on top of the Tuileries
  91. testRegion = [[RMPath alloc] initWithContents:mapContents];
  92. [testRegion setFillColor:[UIColor colorWithRed: 0.1 green:0.1 blue: 0.8 alpha: 0.5 ]];
  93. [testRegion setLineColor:[UIColor blueColor]];
  94. [testRegion setLineWidth:2.0f];
  95. [testRegion addLineToLatLong:r1];
  96. [testRegion addLineToLatLong:r2];
  97. [testRegion addLineToLatLong:r3];
  98. [testRegion addLineToLatLong:r4];
  99. [testRegion closePath];
  100. [[mapContents overlay] addSublayer:testRegion];
  101. [testRegion release];
  102. newMarker = [[RMMarker alloc] initWithUIImage:xMarkerImage anchorPoint:CGPointMake(0.5, 1.0)];
  103. [mapContents.markerManager addMarker:[newMarker autorelease] AtLatLong:r1];
  104. newMarker = [[RMMarker alloc] initWithUIImage:xMarkerImage anchorPoint:CGPointMake(0.5, 1.0)];
  105. [mapContents.markerManager addMarker:[newMarker autorelease] AtLatLong:r2];
  106. newMarker = [[RMMarker alloc] initWithUIImage:xMarkerImage anchorPoint:CGPointMake(0.5, 1.0)];
  107. [mapContents.markerManager addMarker:[newMarker autorelease] AtLatLong:r3];
  108. newMarker = [[RMMarker alloc] initWithUIImage:xMarkerImage anchorPoint:CGPointMake(0.5, 1.0)];
  109. [mapContents.markerManager addMarker:[newMarker autorelease] AtLatLong:r4];
  110. [self performSelector:@selector(performTestPart2) withObject:nil afterDelay:3.0f];
  111. [self performSelector:@selector(performTestPart3) withObject:nil afterDelay:7.0f];
  112. }
  113. - (void)applicationDidFinishLaunching:(UIApplication *)application {
  114. [window addSubview:[rootViewController view]];
  115. [window makeKeyAndVisible];
  116. [self performSelector:@selector(performTest) withObject:nil afterDelay:0.25f];
  117. }
  118. - (void)dealloc {
  119. [rootViewController release];
  120. [window release];
  121. [super dealloc];
  122. }
  123. @end